test/unittest_schema.py
brancholdstable
changeset 5422 0865e1e90674
parent 5421 8167de96c523
child 5424 8ecbcbff9777
equal deleted inserted replaced
4985:02b52bf9f5f8 5422:0865e1e90674
       
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
     1 """unit tests for module cubicweb.schema
    18 """unit tests for module cubicweb.schema
     2 
    19 
     3 :organization: Logilab
       
     4 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
       
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
       
     7 """
    20 """
     8 
    21 
     9 import sys
    22 import sys
    10 from os.path import join, isabs, basename, dirname
    23 from os.path import join, isabs, basename, dirname
    11 
    24 
   239     def test_fulltext_container(self):
   252     def test_fulltext_container(self):
   240         schema = loader.load(config)
   253         schema = loader.load(config)
   241         self.failUnless('has_text' in schema['CWUser'].subject_relations())
   254         self.failUnless('has_text' in schema['CWUser'].subject_relations())
   242         self.failIf('has_text' in schema['EmailAddress'].subject_relations())
   255         self.failIf('has_text' in schema['EmailAddress'].subject_relations())
   243 
   256 
       
   257     def test_permission_settings(self):
       
   258         schema = loader.load(config)
       
   259         aschema = schema['TrInfo'].rdef('comment')
       
   260         self.assertEquals(aschema.get_groups('read'),
       
   261                           set(('managers', 'users', 'guests')))
       
   262         self.assertEquals(aschema.get_rqlexprs('read'),
       
   263                           ())
       
   264         self.assertEquals(aschema.get_groups('update'),
       
   265                           set(('managers',)))
       
   266         self.assertEquals([x.expression for x in aschema.get_rqlexprs('update')],
       
   267                           ['U has_update_permission X'])
   244 
   268 
   245 class BadSchemaRQLExprTC(TestCase):
   269 class BadSchemaRQLExprTC(TestCase):
   246     def setUp(self):
   270     def setUp(self):
   247         self.loader = CubicWebSchemaLoader()
   271         self.loader = CubicWebSchemaLoader()
   248         self.loader.defined = {}
   272         self.loader.defined = {}
   255         ex = self.assertRaises(BadSchemaDefinition,
   279         ex = self.assertRaises(BadSchemaDefinition,
   256                                self.loader._build_schema, 'toto', False)
   280                                self.loader._build_schema, 'toto', False)
   257         self.assertEquals(str(ex), msg)
   281         self.assertEquals(str(ex), msg)
   258 
   282 
   259     def test_rrqlexpr_on_etype(self):
   283     def test_rrqlexpr_on_etype(self):
   260         self._test('rrqlexpr_on_eetype.py', "can't use RRQLExpression on ToTo, use an ERQLExpression")
   284         self._test('rrqlexpr_on_eetype.py',
       
   285                    "can't use RRQLExpression on ToTo, use an ERQLExpression")
   261 
   286 
   262     def test_erqlexpr_on_rtype(self):
   287     def test_erqlexpr_on_rtype(self):
   263         self._test('erqlexpr_on_ertype.py', "can't use ERQLExpression on relation ToTo toto TuTu, use a RRQLExpression")
   288         self._test('erqlexpr_on_ertype.py',
       
   289                    "can't use ERQLExpression on relation ToTo toto TuTu, use a RRQLExpression")
   264 
   290 
   265     def test_rqlexpr_on_rtype_read(self):
   291     def test_rqlexpr_on_rtype_read(self):
   266         self._test('rqlexpr_on_ertype_read.py', "can't use rql expression for read permission of relation ToTo toto TuTu")
   292         self._test('rqlexpr_on_ertype_read.py',
       
   293                    "can't use rql expression for read permission of relation ToTo toto TuTu")
   267 
   294 
   268     def test_rrqlexpr_on_attr(self):
   295     def test_rrqlexpr_on_attr(self):
   269         self._test('rrqlexpr_on_attr.py', "can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression")
   296         self._test('rrqlexpr_on_attr.py',
       
   297                    "can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression")
   270 
   298 
   271 
   299 
   272 class NormalizeExpressionTC(TestCase):
   300 class NormalizeExpressionTC(TestCase):
   273 
   301 
   274     def test(self):
   302     def test(self):
   275         self.assertEquals(normalize_expression('X  bla Y,Y blur Z  ,  Z zigoulou   X '),
   303         self.assertEquals(normalize_expression('X  bla Y,Y blur Z  ,  Z zigoulou   X '),
   276                                                'X bla Y, Y blur Z, Z zigoulou X')
   304                                                'X bla Y, Y blur Z, Z zigoulou X')
   277 
   305 
   278 class RQLExpressionTC(TestCase):
   306 class RQLExpressionTC(TestCase):
   279     def test_comparison(self):
   307     def test_comparison(self):
   280         self.assertEquals(ERQLExpression('X is CWUser', 'X', 0), ERQLExpression('X is CWUser', 'X', 0))
   308         self.assertEquals(ERQLExpression('X is CWUser', 'X', 0),
   281         self.assertNotEquals(ERQLExpression('X is CWUser', 'X', 0), ERQLExpression('X is CWGroup', 'X', 0))
   309                           ERQLExpression('X is CWUser', 'X', 0))
       
   310         self.assertNotEquals(ERQLExpression('X is CWUser', 'X', 0),
       
   311                              ERQLExpression('X is CWGroup', 'X', 0))
   282 
   312 
   283 class GuessRrqlExprMainVarsTC(TestCase):
   313 class GuessRrqlExprMainVarsTC(TestCase):
   284     def test_exists(self):
   314     def test_exists(self):
   285         mainvars = guess_rrqlexpr_mainvars(normalize_expression('NOT EXISTS(O team_competition C, C level < 3)'))
   315         mainvars = guess_rrqlexpr_mainvars(normalize_expression('NOT EXISTS(O team_competition C, C level < 3)'))
   286         self.assertEquals(mainvars, 'O')
   316         self.assertEquals(mainvars, 'O')