test/unittest_schema.py
branchtls-sprint
changeset 1802 d628defebc17
parent 1398 5fe84a5f7035
child 1977 606923dff11b
equal deleted inserted replaced
1801:672acc730ce5 1802:d628defebc17
    94         self.assertEqual(eperson.get_groups('add'), set(('managers',)))
    94         self.assertEqual(eperson.get_groups('add'), set(('managers',)))
    95         self.assertEqual([str(e) for e in eperson.get_rqlexprs('add')],
    95         self.assertEqual([str(e) for e in eperson.get_rqlexprs('add')],
    96                          ['Any X WHERE X travaille S, S owned_by U, X eid %(x)s, U eid %(u)s'])
    96                          ['Any X WHERE X travaille S, S owned_by U, X eid %(x)s, U eid %(u)s'])
    97         eperson.set_groups('read', ('managers',))
    97         eperson.set_groups('read', ('managers',))
    98         self.assertEqual(eperson.get_groups('read'), set(('managers',)))
    98         self.assertEqual(eperson.get_groups('read'), set(('managers',)))
    99         
    99 
   100     def test_relation_perms(self):
   100     def test_relation_perms(self):
   101         rconcerne = schema.rschema('concerne')
   101         rconcerne = schema.rschema('concerne')
   102         rconcerne.set_default_groups()
   102         rconcerne.set_default_groups()
   103         self.assertEqual(rconcerne.get_groups('read'), set(('managers', 'users', 'guests')))
   103         self.assertEqual(rconcerne.get_groups('read'), set(('managers', 'users', 'guests')))
   104         self.assertEqual(rconcerne.get_groups('delete'), set(('managers',)))
   104         self.assertEqual(rconcerne.get_groups('delete'), set(('managers',)))
   110 
   110 
   111     def test_erqlexpression(self):
   111     def test_erqlexpression(self):
   112         self.assertRaises(RQLSyntaxError, ERQLExpression, '1')
   112         self.assertRaises(RQLSyntaxError, ERQLExpression, '1')
   113         expr = ERQLExpression('X travaille S, S owned_by U')
   113         expr = ERQLExpression('X travaille S, S owned_by U')
   114         self.assertEquals(str(expr), 'Any X WHERE X travaille S, S owned_by U, X eid %(x)s, U eid %(u)s')
   114         self.assertEquals(str(expr), 'Any X WHERE X travaille S, S owned_by U, X eid %(x)s, U eid %(u)s')
   115         
   115 
   116     def test_rrqlexpression(self):
   116     def test_rrqlexpression(self):
   117         self.assertRaises(Exception, RRQLExpression, '1')
   117         self.assertRaises(Exception, RRQLExpression, '1')
   118         self.assertRaises(RQLSyntaxError, RRQLExpression, 'O X Y')
   118         self.assertRaises(RQLSyntaxError, RRQLExpression, 'O X Y')
   119         expr = RRQLExpression('U has_update_permission O')
   119         expr = RRQLExpression('U has_update_permission O')
   120         self.assertEquals(str(expr), 'Any O WHERE U has_update_permission O, O eid %(o)s, U eid %(u)s')
   120         self.assertEquals(str(expr), 'Any O WHERE U has_update_permission O, O eid %(o)s, U eid %(u)s')
   121         
   121 
   122 
   122 
   123 loader = CubicWebSchemaLoader()
   123 loader = CubicWebSchemaLoader()
   124 config = TestConfiguration('data')
   124 config = TestConfiguration('data')
   125 config.bootstrap_cubes()
   125 config.bootstrap_cubes()
   126 loader.lib_directory = config.schemas_lib_dir()
   126 loader.lib_directory = config.schemas_lib_dir()
   127     
   127 
   128 class SQLSchemaReaderClassTest(TestCase):
   128 class SQLSchemaReaderClassTest(TestCase):
   129 
   129 
   130     def test_knownValues_include_schema_files(self):
   130     def test_knownValues_include_schema_files(self):
   131         schema_files = loader.include_schema_files('Bookmark')
   131         schema_files = loader.include_schema_files('Bookmark')
   132         for file in schema_files:
   132         for file in schema_files:
   137         schema = loader.load(config)
   137         schema = loader.load(config)
   138         self.assert_(isinstance(schema, CubicWebSchema))
   138         self.assert_(isinstance(schema, CubicWebSchema))
   139         self.assertEquals(schema.name, 'data')
   139         self.assertEquals(schema.name, 'data')
   140         entities = [str(e) for e in schema.entities()]
   140         entities = [str(e) for e in schema.entities()]
   141         entities.sort()
   141         entities.sort()
   142         expected_entities = ['Bookmark', 'Boolean', 'Bytes', 'Card', 
   142         expected_entities = ['Bookmark', 'Boolean', 'Bytes', 'Card',
   143                              'Date', 'Datetime', 'Decimal',
   143                              'Date', 'Datetime', 'Decimal',
   144                              'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType',
   144                              'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType',
   145                              'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation',
   145                              'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation',
   146                              'CWPermission', 'CWProperty', 'CWRType', 'CWUser',
   146                              'CWPermission', 'CWProperty', 'CWRType', 'CWUser',
   147                              'File', 'Float', 'Image', 'Int', 'Interval', 'Note',
   147                              'File', 'Float', 'Image', 'Int', 'Interval', 'Note',
   148                              'Password', 'Personne',
   148                              'Password', 'Personne',
   149                              'RQLExpression', 
   149                              'RQLExpression',
   150                              'Societe', 'State', 'String', 'SubNote', 'Tag', 'Time', 
   150                              'Societe', 'State', 'String', 'SubNote', 'Tag', 'Time',
   151                              'Transition', 'TrInfo']
   151                              'Transition', 'TrInfo']
   152         self.assertListEquals(entities, sorted(expected_entities))
   152         self.assertListEquals(entities, sorted(expected_entities))
   153         relations = [str(r) for r in schema.relations()]
   153         relations = [str(r) for r in schema.relations()]
   154         relations.sort()
   154         relations.sort()
   155         expected_relations = ['add_permission', 'address', 'alias',
   155         expected_relations = ['add_permission', 'address', 'alias',
   156                               'allowed_transition', 'bookmarked_by', 'canonical',
   156                               'allowed_transition', 'bookmarked_by', 'canonical',
   157 
   157 
   158                               'cardinality', 'comment', 'comment_format', 
   158                               'cardinality', 'comment', 'comment_format',
   159                               'composite', 'condition', 'connait', 'constrained_by', 'content',
   159                               'composite', 'condition', 'connait', 'constrained_by', 'content',
   160                               'content_format', 'created_by', 'creation_date', 'cstrtype',
   160                               'content_format', 'created_by', 'creation_date', 'cstrtype',
   161 
   161 
   162                               'data', 'data_encoding', 'data_format', 'defaultval', 'delete_permission',
   162                               'data', 'data_encoding', 'data_format', 'defaultval', 'delete_permission',
   163                               'description', 'description_format', 'destination_state',
   163                               'description', 'description_format', 'destination_state',
   165                               'ecrit_par', 'eid', 'evaluee', 'expression', 'exprtype',
   165                               'ecrit_par', 'eid', 'evaluee', 'expression', 'exprtype',
   166 
   166 
   167                               'final', 'firstname', 'for_user',
   167                               'final', 'firstname', 'for_user',
   168                               'from_entity', 'from_state', 'fulltext_container', 'fulltextindexed',
   168                               'from_entity', 'from_state', 'fulltext_container', 'fulltextindexed',
   169 
   169 
   170                               'has_text', 
   170                               'has_text',
   171                               'identical_to', 'identity', 'in_group', 'in_state', 'indexed',
   171                               'identical_to', 'identity', 'in_group', 'in_state', 'indexed',
   172                               'initial_state', 'inlined', 'internationalizable', 'is', 'is_instance_of',
   172                               'initial_state', 'inlined', 'internationalizable', 'is', 'is_instance_of',
   173 
   173 
   174                               'label', 'last_login_time', 'login',
   174                               'label', 'last_login_time', 'login',
   175 
   175 
   177 
   177 
   178                               'name', 'nom',
   178                               'name', 'nom',
   179 
   179 
   180                               'ordernum', 'owned_by',
   180                               'ordernum', 'owned_by',
   181 
   181 
   182                               'path', 'pkey', 'prenom', 'primary_email', 
   182                               'path', 'pkey', 'prenom', 'primary_email',
   183 
   183 
   184                               'read_permission', 'relation_type', 'require_group',
   184                               'read_permission', 'relation_type', 'require_group',
   185                               
   185 
   186                               'specializes', 'state_of', 'surname', 'symetric', 'synopsis',
   186                               'specializes', 'state_of', 'surname', 'symetric', 'synopsis',
   187 
   187 
   188                               'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type',
   188                               'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type',
   189 
   189 
   190                               'upassword', 'update_permission', 'use_email',
   190                               'upassword', 'update_permission', 'use_email',
   191 
   191 
   192                               'value', 
   192                               'value',
   193 
   193 
   194                               'wf_info_for', 'wikiid']
   194                               'wf_info_for', 'wikiid']
   195     
   195 
   196         self.assertListEquals(relations, expected_relations)
   196         self.assertListEquals(relations, expected_relations)
   197 
   197 
   198         eschema = schema.eschema('CWUser')
   198         eschema = schema.eschema('CWUser')
   199         rels = sorted(str(r) for r in eschema.subject_relations())
   199         rels = sorted(str(r) for r in eschema.subject_relations())
   200         self.assertListEquals(rels, ['created_by', 'creation_date', 'eid',
   200         self.assertListEquals(rels, ['created_by', 'creation_date', 'eid',
   232     def _test(self, schemafile, msg):
   232     def _test(self, schemafile, msg):
   233         self.loader.handle_file(join(DATADIR, schemafile))
   233         self.loader.handle_file(join(DATADIR, schemafile))
   234         ex = self.assertRaises(BadSchemaDefinition,
   234         ex = self.assertRaises(BadSchemaDefinition,
   235                                self.loader._build_schema, 'toto', False)
   235                                self.loader._build_schema, 'toto', False)
   236         self.assertEquals(str(ex), msg)
   236         self.assertEquals(str(ex), msg)
   237         
   237 
   238     def test_rrqlexpr_on_etype(self):
   238     def test_rrqlexpr_on_etype(self):
   239         self._test('rrqlexpr_on_eetype.py', "can't use RRQLExpression on an entity type, use an ERQLExpression (ToTo)")
   239         self._test('rrqlexpr_on_eetype.py', "can't use RRQLExpression on an entity type, use an ERQLExpression (ToTo)")
   240         
   240 
   241     def test_erqlexpr_on_rtype(self):
   241     def test_erqlexpr_on_rtype(self):
   242         self._test('erqlexpr_on_ertype.py', "can't use ERQLExpression on a relation type, use a RRQLExpression (toto)")
   242         self._test('erqlexpr_on_ertype.py', "can't use ERQLExpression on a relation type, use a RRQLExpression (toto)")
   243         
   243 
   244     def test_rqlexpr_on_rtype_read(self):
   244     def test_rqlexpr_on_rtype_read(self):
   245         self._test('rqlexpr_on_ertype_read.py', "can't use rql expression for read permission of a relation type (toto)")
   245         self._test('rqlexpr_on_ertype_read.py', "can't use rql expression for read permission of a relation type (toto)")
   246         
   246 
   247     def test_rrqlexpr_on_attr(self):
   247     def test_rrqlexpr_on_attr(self):
   248         self._test('rrqlexpr_on_attr.py', "can't use RRQLExpression on a final relation type (eg attribute relation), use an ERQLExpression (attr)")
   248         self._test('rrqlexpr_on_attr.py', "can't use RRQLExpression on a final relation type (eg attribute relation), use an ERQLExpression (attr)")
   249 
   249 
   250 
   250 
   251 class NormalizeExpressionTC(TestCase):
   251 class NormalizeExpressionTC(TestCase):