16 from yams import BadSchemaDefinition |
16 from yams import BadSchemaDefinition |
17 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
17 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
18 from yams.buildobjs import RelationDefinition, EntityType, RelationType |
18 from yams.buildobjs import RelationDefinition, EntityType, RelationType |
19 from yams.reader import PyFileReader |
19 from yams.reader import PyFileReader |
20 |
20 |
21 from cubicweb.schema import CubicWebSchema, CubicWebEntitySchema, \ |
21 from cubicweb.schema import ( |
22 RQLConstraint, CubicWebSchemaLoader, ERQLExpression, RRQLExpression, \ |
22 CubicWebSchema, CubicWebEntitySchema, CubicWebSchemaLoader, |
23 normalize_expression, order_eschemas |
23 RQLConstraint, RQLUniqueConstraint, RQLVocabularyConstraint, |
|
24 ERQLExpression, RRQLExpression, |
|
25 normalize_expression, order_eschemas) |
24 from cubicweb.devtools import TestServerConfiguration as TestConfiguration |
26 from cubicweb.devtools import TestServerConfiguration as TestConfiguration |
25 |
27 |
26 DATADIR = join(dirname(__file__), 'data') |
28 DATADIR = join(dirname(__file__), 'data') |
27 |
29 |
28 # build a dummy schema ######################################################## |
30 # build a dummy schema ######################################################## |
80 done[_type.lower()] = True |
82 done[_type.lower()] = True |
81 schema.add_relation_def(RelationDefinition(_from, _type, _to)) |
83 schema.add_relation_def(RelationDefinition(_from, _type, _to)) |
82 |
84 |
83 class CubicWebSchemaTC(TestCase): |
85 class CubicWebSchemaTC(TestCase): |
84 |
86 |
|
87 def test_rql_constraints_inheritance(self): |
|
88 # isinstance(cstr, RQLVocabularyConstraint) |
|
89 # -> expected to return RQLVocabularyConstraint and RQLConstraint |
|
90 # instances but not RQLUniqueConstraint |
|
91 # |
|
92 # isinstance(cstr, RQLConstraint) |
|
93 # -> expected to return RQLConstraint instances but not |
|
94 # RRQLVocabularyConstraint and QLUniqueConstraint |
|
95 self.failIf(issubclass(RQLUniqueConstraint, RQLVocabularyConstraint)) |
|
96 self.failIf(issubclass(RQLUniqueConstraint, RQLConstraint)) |
|
97 self.failUnless(issubclass(RQLConstraint, RQLVocabularyConstraint)) |
|
98 |
85 def test_normalize(self): |
99 def test_normalize(self): |
86 """test that entities, relations and attributes name are normalized |
100 """test that entities, relations and attributes name are normalized |
87 """ |
101 """ |
88 self.assertEqual(esociete.type, 'Societe') |
102 self.assertEqual(esociete.type, 'Societe') |
89 self.assertEqual(schema.has_relation('TEST'), 0) |
103 self.assertEqual(schema.has_relation('TEST'), 0) |