author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Sat, 06 Feb 2010 10:34:35 +0100 | |
branch | stable |
changeset 4486 | 9a4ef69bdef7 |
parent 4212 | ab6573088b4a |
child 4252 | 6c4f109c2b03 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
1 |
"""unit tests for module cubicweb.schema |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4132
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
""" |
0 | 8 |
|
9 |
import sys |
|
10 |
from os.path import join, isabs, basename, dirname |
|
11 |
||
12 |
from logilab.common.testlib import TestCase, unittest_main |
|
13 |
||
14 |
from rql import RQLSyntaxError |
|
15 |
||
16 |
from yams import BadSchemaDefinition |
|
17 |
from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
|
18 |
from yams.buildobjs import RelationDefinition, EntityType, RelationType |
|
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
19 |
from yams.reader import PyFileReader |
0 | 20 |
|
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
21 |
from cubicweb.schema import ( |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
22 |
CubicWebSchema, CubicWebEntitySchema, CubicWebSchemaLoader, |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
23 |
RQLConstraint, RQLUniqueConstraint, RQLVocabularyConstraint, |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
24 |
ERQLExpression, RRQLExpression, |
4132
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
25 |
normalize_expression, order_eschemas, guess_rrqlexpr_mainvars) |
0 | 26 |
from cubicweb.devtools import TestServerConfiguration as TestConfiguration |
27 |
||
28 |
DATADIR = join(dirname(__file__), 'data') |
|
29 |
||
30 |
# build a dummy schema ######################################################## |
|
31 |
||
32 |
||
33 |
PERSONNE_PERMISSIONS = { |
|
34 |
'read': ('managers', 'users', 'guests'), |
|
35 |
'update': ('managers', 'owners'), |
|
36 |
'add': ('managers', ERQLExpression('X travaille S, S owned_by U')), |
|
37 |
'delete': ('managers', 'owners',), |
|
38 |
} |
|
39 |
||
40 |
CONCERNE_PERMISSIONS = { |
|
41 |
'read': ('managers', 'users', 'guests'), |
|
42 |
'add': ('managers', RRQLExpression('U has_update_permission S')), |
|
43 |
'delete': ('managers', RRQLExpression('O owned_by U')), |
|
44 |
} |
|
45 |
||
46 |
schema = CubicWebSchema('Test Schema') |
|
47 |
enote = schema.add_entity_type(EntityType('Note')) |
|
48 |
eaffaire = schema.add_entity_type(EntityType('Affaire')) |
|
49 |
eperson = schema.add_entity_type(EntityType('Personne', permissions=PERSONNE_PERMISSIONS)) |
|
50 |
esociete = schema.add_entity_type(EntityType('Societe')) |
|
51 |
||
52 |
RELS = ( |
|
53 |
# attribute relations |
|
54 |
('Note date String'), |
|
55 |
('Note type String'), |
|
56 |
('Affaire sujet String'), |
|
57 |
('Affaire ref String'), |
|
58 |
('Personne nom String'), |
|
59 |
('Personne prenom String'), |
|
60 |
('Personne sexe String'), |
|
61 |
('Personne tel Int'), |
|
62 |
('Personne fax Int'), |
|
63 |
('Personne datenaiss Date'), |
|
64 |
('Personne TEST Boolean'), |
|
65 |
('Personne promo String'), |
|
66 |
# real relations |
|
67 |
('Personne travaille Societe'), |
|
68 |
('Personne evaluee Note'), |
|
69 |
('Societe evaluee Note'), |
|
70 |
('Personne concerne Affaire'), |
|
71 |
('Personne concerne Societe'), |
|
72 |
('Affaire Concerne Societe'), |
|
73 |
) |
|
74 |
done = {} |
|
75 |
for rel in RELS: |
|
76 |
_from, _type, _to = rel.split() |
|
77 |
if not _type.lower() in done: |
|
78 |
if _type == 'concerne': |
|
79 |
schema.add_relation_type(RelationType(_type, permissions=CONCERNE_PERMISSIONS)) |
|
80 |
else: |
|
81 |
schema.add_relation_type(RelationType(_type)) |
|
82 |
done[_type.lower()] = True |
|
83 |
schema.add_relation_def(RelationDefinition(_from, _type, _to)) |
|
84 |
||
85 |
class CubicWebSchemaTC(TestCase): |
|
86 |
||
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
87 |
def test_rql_constraints_inheritance(self): |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
88 |
# isinstance(cstr, RQLVocabularyConstraint) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
89 |
# -> expected to return RQLVocabularyConstraint and RQLConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
90 |
# instances but not RQLUniqueConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
91 |
# |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
92 |
# isinstance(cstr, RQLConstraint) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
93 |
# -> expected to return RQLConstraint instances but not |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
94 |
# RRQLVocabularyConstraint and QLUniqueConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
95 |
self.failIf(issubclass(RQLUniqueConstraint, RQLVocabularyConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
96 |
self.failIf(issubclass(RQLUniqueConstraint, RQLConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
97 |
self.failUnless(issubclass(RQLConstraint, RQLVocabularyConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
98 |
|
0 | 99 |
def test_normalize(self): |
100 |
"""test that entities, relations and attributes name are normalized |
|
101 |
""" |
|
102 |
self.assertEqual(esociete.type, 'Societe') |
|
103 |
self.assertEqual(schema.has_relation('TEST'), 0) |
|
104 |
self.assertEqual(schema.has_relation('test'), 1) |
|
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
105 |
self.assertEqual(eperson.subjrels['test'].type, 'test') |
0 | 106 |
self.assertEqual(schema.has_relation('Concerne'), 0) |
107 |
self.assertEqual(schema.has_relation('concerne'), 1) |
|
108 |
self.assertEqual(schema.rschema('concerne').type, 'concerne') |
|
109 |
||
110 |
def test_entity_perms(self): |
|
111 |
eperson.set_default_groups() |
|
112 |
self.assertEqual(eperson.get_groups('read'), set(('managers', 'users', 'guests'))) |
|
113 |
self.assertEqual(eperson.get_groups('update'), set(('managers', 'owners',))) |
|
114 |
self.assertEqual(eperson.get_groups('delete'), set(('managers', 'owners'))) |
|
115 |
self.assertEqual(eperson.get_groups('add'), set(('managers',))) |
|
116 |
self.assertEqual([str(e) for e in eperson.get_rqlexprs('add')], |
|
117 |
['Any X WHERE X travaille S, S owned_by U, X eid %(x)s, U eid %(u)s']) |
|
118 |
eperson.set_groups('read', ('managers',)) |
|
119 |
self.assertEqual(eperson.get_groups('read'), set(('managers',))) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
120 |
|
0 | 121 |
def test_relation_perms(self): |
122 |
rconcerne = schema.rschema('concerne') |
|
123 |
rconcerne.set_default_groups() |
|
124 |
self.assertEqual(rconcerne.get_groups('read'), set(('managers', 'users', 'guests'))) |
|
125 |
self.assertEqual(rconcerne.get_groups('delete'), set(('managers',))) |
|
126 |
self.assertEqual(rconcerne.get_groups('add'), set(('managers', ))) |
|
127 |
rconcerne.set_groups('read', ('managers',)) |
|
128 |
self.assertEqual(rconcerne.get_groups('read'), set(('managers',))) |
|
129 |
self.assertEqual([str(e) for e in rconcerne.get_rqlexprs('add')], |
|
3899
78a2c8e7eef5
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
130 |
['Any S,U WHERE U has_update_permission S, S eid %(s)s, U eid %(u)s']) |
0 | 131 |
|
132 |
def test_erqlexpression(self): |
|
133 |
self.assertRaises(RQLSyntaxError, ERQLExpression, '1') |
|
134 |
expr = ERQLExpression('X travaille S, S owned_by U') |
|
135 |
self.assertEquals(str(expr), 'Any X WHERE X travaille S, S owned_by U, X eid %(x)s, U eid %(u)s') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
136 |
|
0 | 137 |
def test_rrqlexpression(self): |
138 |
self.assertRaises(Exception, RRQLExpression, '1') |
|
139 |
self.assertRaises(RQLSyntaxError, RRQLExpression, 'O X Y') |
|
140 |
expr = RRQLExpression('U has_update_permission O') |
|
3899
78a2c8e7eef5
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
141 |
self.assertEquals(str(expr), 'Any O,U WHERE U has_update_permission O, O eid %(o)s, U eid %(u)s') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
142 |
|
0 | 143 |
loader = CubicWebSchemaLoader() |
144 |
config = TestConfiguration('data') |
|
145 |
config.bootstrap_cubes() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
146 |
|
2926
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
147 |
class SchemaReaderClassTest(TestCase): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
148 |
|
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
149 |
def test_order_eschemas(self): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
150 |
schema = loader.load(config) |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
151 |
self.assertEquals(order_eschemas([schema['Note'], schema['SubNote']]), |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
152 |
[schema['Note'], schema['SubNote']]) |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
153 |
self.assertEquals(order_eschemas([schema['SubNote'], schema['Note']]), |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
154 |
[schema['Note'], schema['SubNote']]) |
0 | 155 |
|
156 |
def test_knownValues_load_schema(self): |
|
157 |
schema = loader.load(config) |
|
158 |
self.assert_(isinstance(schema, CubicWebSchema)) |
|
159 |
self.assertEquals(schema.name, 'data') |
|
160 |
entities = [str(e) for e in schema.entities()] |
|
161 |
entities.sort() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
162 |
expected_entities = ['BaseTransition', 'Bookmark', 'Boolean', 'Bytes', 'Card', |
0 | 163 |
'Date', 'Datetime', 'Decimal', |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
164 |
'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
165 |
'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
166 |
'CWPermission', 'CWProperty', 'CWRType', 'CWUser', |
2456
aa25d6b244c8
new cwuri metadata + a few tests fixes on the way
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
167 |
'ExternalUri', 'File', 'Float', 'Image', 'Int', 'Interval', 'Note', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
168 |
'Password', 'Personne', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
169 |
'RQLExpression', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
170 |
'Societe', 'State', 'String', 'SubNote', 'SubWorkflowExitPoint', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
171 |
'Tag', 'Time', 'Transition', 'TrInfo', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
172 |
'Workflow', 'WorkflowTransition'] |
0 | 173 |
self.assertListEquals(entities, sorted(expected_entities)) |
174 |
relations = [str(r) for r in schema.relations()] |
|
175 |
relations.sort() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
176 |
expected_relations = ['add_permission', 'address', 'alias', 'allowed_transition', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
177 |
'bookmarked_by', 'by_transition', |
0 | 178 |
|
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
179 |
'cardinality', 'comment', 'comment_format', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
180 |
'composite', 'condition', 'connait', 'constrained_by', 'content', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
181 |
'content_format', 'created_by', 'creation_date', 'cstrtype', 'custom_workflow', 'cwuri', |
0 | 182 |
|
3587 | 183 |
'data', 'data_encoding', 'data_format', 'data_name', 'default_workflow', 'defaultval', 'delete_permission', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
184 |
'description', 'description_format', 'destination_state', |
0 | 185 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
186 |
'ecrit_par', 'eid', 'evaluee', 'expression', 'exprtype', |
0 | 187 |
|
188 |
'final', 'firstname', 'for_user', |
|
189 |
'from_entity', 'from_state', 'fulltext_container', 'fulltextindexed', |
|
190 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
191 |
'has_text', |
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
192 |
'identity', 'in_group', 'in_state', 'indexed', |
0 | 193 |
'initial_state', 'inlined', 'internationalizable', 'is', 'is_instance_of', |
194 |
||
195 |
'label', 'last_login_time', 'login', |
|
196 |
||
2456
aa25d6b244c8
new cwuri metadata + a few tests fixes on the way
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
197 |
'mainvars', 'modification_date', |
0 | 198 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
199 |
'name', 'nom', |
0 | 200 |
|
201 |
'ordernum', 'owned_by', |
|
202 |
||
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
203 |
'path', 'pkey', 'prefered_form', 'prenom', 'primary_email', |
0 | 204 |
|
205 |
'read_permission', 'relation_type', 'require_group', |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
206 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
207 |
'specializes', 'state_of', 'subworkflow', 'subworkflow_exit', 'subworkflow_state', 'surname', 'symetric', 'synopsis', |
0 | 208 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
209 |
'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type', |
0 | 210 |
|
2456
aa25d6b244c8
new cwuri metadata + a few tests fixes on the way
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
211 |
'upassword', 'update_permission', 'uri', 'use_email', |
0 | 212 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
213 |
'value', |
0 | 214 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
215 |
'wf_info_for', 'wikiid', 'workflow_of'] |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
216 |
|
0 | 217 |
self.assertListEquals(relations, expected_relations) |
218 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
219 |
eschema = schema.eschema('CWUser') |
0 | 220 |
rels = sorted(str(r) for r in eschema.subject_relations()) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
221 |
self.assertListEquals(rels, ['created_by', 'creation_date', 'custom_workflow', 'cwuri', 'eid', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
222 |
'evaluee', 'firstname', 'has_text', 'identity', |
0 | 223 |
'in_group', 'in_state', 'is', |
224 |
'is_instance_of', 'last_login_time', |
|
225 |
'login', 'modification_date', 'owned_by', |
|
226 |
'primary_email', 'surname', 'upassword', |
|
227 |
'use_email']) |
|
228 |
rels = sorted(r.type for r in eschema.object_relations()) |
|
229 |
self.assertListEquals(rels, ['bookmarked_by', 'created_by', 'for_user', |
|
230 |
'identity', 'owned_by', 'wf_info_for']) |
|
231 |
rschema = schema.rschema('relation_type') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
232 |
properties = rschema.rproperties('CWAttribute', 'CWRType') |
0 | 233 |
self.assertEquals(properties['cardinality'], '1*') |
234 |
constraints = properties['constraints'] |
|
235 |
self.failUnlessEqual(len(constraints), 1, constraints) |
|
236 |
constraint = constraints[0] |
|
237 |
self.failUnless(isinstance(constraint, RQLConstraint)) |
|
238 |
self.failUnlessEqual(constraint.restriction, 'O final TRUE') |
|
239 |
||
240 |
def test_fulltext_container(self): |
|
241 |
schema = loader.load(config) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
242 |
self.failUnless('has_text' in schema['CWUser'].subject_relations()) |
0 | 243 |
self.failIf('has_text' in schema['EmailAddress'].subject_relations()) |
244 |
||
245 |
||
246 |
class BadSchemaRQLExprTC(TestCase): |
|
247 |
def setUp(self): |
|
248 |
self.loader = CubicWebSchemaLoader() |
|
249 |
self.loader.defined = {} |
|
951 | 250 |
self.loader.loaded_files = [] |
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
251 |
self.loader._pyreader = PyFileReader(self.loader) |
0 | 252 |
|
253 |
def _test(self, schemafile, msg): |
|
254 |
self.loader.handle_file(join(DATADIR, schemafile)) |
|
255 |
ex = self.assertRaises(BadSchemaDefinition, |
|
256 |
self.loader._build_schema, 'toto', False) |
|
257 |
self.assertEquals(str(ex), msg) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
258 |
|
0 | 259 |
def test_rrqlexpr_on_etype(self): |
260 |
self._test('rrqlexpr_on_eetype.py', "can't use RRQLExpression on an entity type, use an ERQLExpression (ToTo)") |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
261 |
|
0 | 262 |
def test_erqlexpr_on_rtype(self): |
263 |
self._test('erqlexpr_on_ertype.py', "can't use ERQLExpression on a relation type, use a RRQLExpression (toto)") |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
264 |
|
0 | 265 |
def test_rqlexpr_on_rtype_read(self): |
266 |
self._test('rqlexpr_on_ertype_read.py', "can't use rql expression for read permission of a relation type (toto)") |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
267 |
|
0 | 268 |
def test_rrqlexpr_on_attr(self): |
269 |
self._test('rrqlexpr_on_attr.py', "can't use RRQLExpression on a final relation type (eg attribute relation), use an ERQLExpression (attr)") |
|
270 |
||
271 |
||
272 |
class NormalizeExpressionTC(TestCase): |
|
273 |
||
274 |
def test(self): |
|
275 |
self.assertEquals(normalize_expression('X bla Y,Y blur Z , Z zigoulou X '), |
|
276 |
'X bla Y, Y blur Z, Z zigoulou X') |
|
277 |
||
4132
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
278 |
class GuessRrqlExprMainVarsTC(TestCase): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
279 |
def test_exists(self): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
280 |
mainvars = guess_rrqlexpr_mainvars(normalize_expression('NOT EXISTS(O team_competition C, C level < 3)')) |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
281 |
self.assertEquals(mainvars, 'O') |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
282 |
|
0 | 283 |
if __name__ == '__main__': |
284 |
unittest_main() |