author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Thu, 15 Apr 2010 14:27:43 +0200 | |
branch | stable |
changeset 5279 | 42a37a50f2ff |
parent 5179 | f08943f22334 |
child 5421 | 8167de96c523 |
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, |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
24 |
RQLExpression, 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')) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
49 |
eperson = schema.add_entity_type(EntityType('Personne', __permissions__=PERSONNE_PERMISSIONS)) |
0 | 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: |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
78 |
schema.add_relation_type(RelationType(_type)) |
0 | 79 |
done[_type.lower()] = True |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
80 |
if _type == 'concerne': |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
81 |
schema.add_relation_def(RelationDefinition(_from, _type, _to, |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
82 |
__permissions__=CONCERNE_PERMISSIONS)) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
83 |
else: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
84 |
schema.add_relation_def(RelationDefinition(_from, _type, _to)) |
0 | 85 |
|
86 |
class CubicWebSchemaTC(TestCase): |
|
87 |
||
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
88 |
def test_rql_constraints_inheritance(self): |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
89 |
# isinstance(cstr, RQLVocabularyConstraint) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
90 |
# -> expected to return RQLVocabularyConstraint and RQLConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
91 |
# instances but not RQLUniqueConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
92 |
# |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
93 |
# isinstance(cstr, RQLConstraint) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
94 |
# -> 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
|
95 |
# RRQLVocabularyConstraint and QLUniqueConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
96 |
self.failIf(issubclass(RQLUniqueConstraint, RQLVocabularyConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
97 |
self.failIf(issubclass(RQLUniqueConstraint, RQLConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
98 |
self.failUnless(issubclass(RQLConstraint, RQLVocabularyConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
99 |
|
0 | 100 |
def test_normalize(self): |
101 |
"""test that entities, relations and attributes name are normalized |
|
102 |
""" |
|
103 |
self.assertEqual(esociete.type, 'Societe') |
|
104 |
self.assertEqual(schema.has_relation('TEST'), 0) |
|
105 |
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
|
106 |
self.assertEqual(eperson.subjrels['test'].type, 'test') |
0 | 107 |
self.assertEqual(schema.has_relation('Concerne'), 0) |
108 |
self.assertEqual(schema.has_relation('concerne'), 1) |
|
109 |
self.assertEqual(schema.rschema('concerne').type, 'concerne') |
|
110 |
||
111 |
def test_entity_perms(self): |
|
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']) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
118 |
eperson.set_action_permissions('read', ('managers',)) |
0 | 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): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
122 |
rconcerne = schema.rschema('concerne').rdef('Personne', 'Societe') |
0 | 123 |
self.assertEqual(rconcerne.get_groups('read'), set(('managers', 'users', 'guests'))) |
124 |
self.assertEqual(rconcerne.get_groups('delete'), set(('managers',))) |
|
125 |
self.assertEqual(rconcerne.get_groups('add'), set(('managers', ))) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
126 |
rconcerne.set_action_permissions('read', ('managers',)) |
0 | 127 |
self.assertEqual(rconcerne.get_groups('read'), set(('managers',))) |
128 |
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
|
129 |
['Any S,U WHERE U has_update_permission S, S eid %(s)s, U eid %(u)s']) |
0 | 130 |
|
131 |
def test_erqlexpression(self): |
|
132 |
self.assertRaises(RQLSyntaxError, ERQLExpression, '1') |
|
133 |
expr = ERQLExpression('X travaille S, S owned_by U') |
|
134 |
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
|
135 |
|
0 | 136 |
def test_rrqlexpression(self): |
137 |
self.assertRaises(Exception, RRQLExpression, '1') |
|
138 |
self.assertRaises(RQLSyntaxError, RRQLExpression, 'O X Y') |
|
139 |
expr = RRQLExpression('U has_update_permission O') |
|
3899
78a2c8e7eef5
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
140 |
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
|
141 |
|
0 | 142 |
loader = CubicWebSchemaLoader() |
143 |
config = TestConfiguration('data') |
|
144 |
config.bootstrap_cubes() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
145 |
|
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
|
146 |
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
|
147 |
|
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 |
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
|
149 |
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
|
150 |
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
|
151 |
[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 |
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
|
153 |
[schema['Note'], schema['SubNote']]) |
0 | 154 |
|
155 |
def test_knownValues_load_schema(self): |
|
156 |
schema = loader.load(config) |
|
157 |
self.assert_(isinstance(schema, CubicWebSchema)) |
|
158 |
self.assertEquals(schema.name, 'data') |
|
159 |
entities = [str(e) for e in schema.entities()] |
|
160 |
entities.sort() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
161 |
expected_entities = ['BaseTransition', 'Bookmark', 'Boolean', 'Bytes', 'Card', |
0 | 162 |
'Date', 'Datetime', 'Decimal', |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
163 |
'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
164 |
'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
165 |
'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
|
166 |
'ExternalUri', 'File', 'Float', 'Image', 'Int', 'Interval', 'Note', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
167 |
'Password', 'Personne', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
168 |
'RQLExpression', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
169 |
'Societe', 'State', 'String', 'SubNote', 'SubWorkflowExitPoint', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
170 |
'Tag', 'Time', 'Transition', 'TrInfo', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
171 |
'Workflow', 'WorkflowTransition'] |
0 | 172 |
self.assertListEquals(entities, sorted(expected_entities)) |
173 |
relations = [str(r) for r in schema.relations()] |
|
174 |
relations.sort() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
175 |
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
|
176 |
'bookmarked_by', 'by_transition', |
0 | 177 |
|
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
178 |
'cardinality', 'comment', 'comment_format', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
179 |
'composite', 'condition', 'connait', 'constrained_by', 'content', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
180 |
'content_format', 'created_by', 'creation_date', 'cstrtype', 'custom_workflow', 'cwuri', |
0 | 181 |
|
3587 | 182 |
'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
|
183 |
'description', 'description_format', 'destination_state', |
0 | 184 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
185 |
'ecrit_par', 'eid', 'evaluee', 'expression', 'exprtype', |
0 | 186 |
|
187 |
'final', 'firstname', 'for_user', |
|
188 |
'from_entity', 'from_state', 'fulltext_container', 'fulltextindexed', |
|
189 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
190 |
'has_text', |
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
191 |
'identity', 'in_group', 'in_state', 'indexed', |
0 | 192 |
'initial_state', 'inlined', 'internationalizable', 'is', 'is_instance_of', |
193 |
||
194 |
'label', 'last_login_time', 'login', |
|
195 |
||
2456
aa25d6b244c8
new cwuri metadata + a few tests fixes on the way
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
196 |
'mainvars', 'modification_date', |
0 | 197 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
198 |
'name', 'nom', |
0 | 199 |
|
200 |
'ordernum', 'owned_by', |
|
201 |
||
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
202 |
'path', 'pkey', 'prefered_form', 'prenom', 'primary_email', |
0 | 203 |
|
204 |
'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
|
205 |
|
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
206 |
'specializes', 'state_of', 'subworkflow', 'subworkflow_exit', 'subworkflow_state', 'surname', 'symmetric', 'synopsis', |
0 | 207 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
208 |
'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type', |
0 | 209 |
|
2456
aa25d6b244c8
new cwuri metadata + a few tests fixes on the way
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
210 |
'upassword', 'update_permission', 'uri', 'use_email', |
0 | 211 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
212 |
'value', |
0 | 213 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
214 |
'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
|
215 |
|
0 | 216 |
self.assertListEquals(relations, expected_relations) |
217 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
218 |
eschema = schema.eschema('CWUser') |
0 | 219 |
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
|
220 |
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
|
221 |
'evaluee', 'firstname', 'has_text', 'identity', |
0 | 222 |
'in_group', 'in_state', 'is', |
223 |
'is_instance_of', 'last_login_time', |
|
224 |
'login', 'modification_date', 'owned_by', |
|
225 |
'primary_email', 'surname', 'upassword', |
|
226 |
'use_email']) |
|
227 |
rels = sorted(r.type for r in eschema.object_relations()) |
|
228 |
self.assertListEquals(rels, ['bookmarked_by', 'created_by', 'for_user', |
|
229 |
'identity', 'owned_by', 'wf_info_for']) |
|
230 |
rschema = schema.rschema('relation_type') |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
231 |
properties = rschema.rdef('CWAttribute', 'CWRType') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
232 |
self.assertEquals(properties.cardinality, '1*') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
233 |
constraints = properties.constraints |
0 | 234 |
self.failUnlessEqual(len(constraints), 1, constraints) |
235 |
constraint = constraints[0] |
|
236 |
self.failUnless(isinstance(constraint, RQLConstraint)) |
|
237 |
self.failUnlessEqual(constraint.restriction, 'O final TRUE') |
|
238 |
||
239 |
def test_fulltext_container(self): |
|
240 |
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
|
241 |
self.failUnless('has_text' in schema['CWUser'].subject_relations()) |
0 | 242 |
self.failIf('has_text' in schema['EmailAddress'].subject_relations()) |
243 |
||
5179
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
244 |
def test_permission_settings(self): |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
245 |
schema = loader.load(config) |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
246 |
aschema = schema['TrInfo'].rdef('comment') |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
247 |
self.assertEquals(aschema.get_groups('read'), |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
248 |
set(('managers', 'users', 'guests'))) |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
249 |
self.assertEquals(aschema.get_rqlexprs('read'), |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
250 |
()) |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
251 |
self.assertEquals(aschema.get_groups('update'), |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
252 |
set(('managers',))) |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
253 |
self.assertEquals([x.expression for x in aschema.get_rqlexprs('update')], |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
254 |
['U has_update_permission X']) |
0 | 255 |
|
256 |
class BadSchemaRQLExprTC(TestCase): |
|
257 |
def setUp(self): |
|
258 |
self.loader = CubicWebSchemaLoader() |
|
259 |
self.loader.defined = {} |
|
951 | 260 |
self.loader.loaded_files = [] |
4469
310b5f01c982
need post_build_callbacks attribute with earlier yams version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
261 |
self.loader.post_build_callbacks = [] |
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
262 |
self.loader._pyreader = PyFileReader(self.loader) |
0 | 263 |
|
264 |
def _test(self, schemafile, msg): |
|
265 |
self.loader.handle_file(join(DATADIR, schemafile)) |
|
266 |
ex = self.assertRaises(BadSchemaDefinition, |
|
267 |
self.loader._build_schema, 'toto', False) |
|
268 |
self.assertEquals(str(ex), msg) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
269 |
|
0 | 270 |
def test_rrqlexpr_on_etype(self): |
5179
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
271 |
self._test('rrqlexpr_on_eetype.py', |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
272 |
"can't use RRQLExpression on ToTo, use an ERQLExpression") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
273 |
|
0 | 274 |
def test_erqlexpr_on_rtype(self): |
5179
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
275 |
self._test('erqlexpr_on_ertype.py', |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
276 |
"can't use ERQLExpression on relation ToTo toto TuTu, use a RRQLExpression") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
277 |
|
0 | 278 |
def test_rqlexpr_on_rtype_read(self): |
5179
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
279 |
self._test('rqlexpr_on_ertype_read.py', |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
280 |
"can't use rql expression for read permission of relation ToTo toto TuTu") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
281 |
|
0 | 282 |
def test_rrqlexpr_on_attr(self): |
5179
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
283 |
self._test('rrqlexpr_on_attr.py', |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
284 |
"can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression") |
0 | 285 |
|
286 |
||
287 |
class NormalizeExpressionTC(TestCase): |
|
288 |
||
289 |
def test(self): |
|
290 |
self.assertEquals(normalize_expression('X bla Y,Y blur Z , Z zigoulou X '), |
|
291 |
'X bla Y, Y blur Z, Z zigoulou X') |
|
292 |
||
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
293 |
class RQLExpressionTC(TestCase): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
294 |
def test_comparison(self): |
5179
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
295 |
self.assertEquals(ERQLExpression('X is CWUser', 'X', 0), |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
296 |
ERQLExpression('X is CWUser', 'X', 0)) |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
297 |
self.assertNotEquals(ERQLExpression('X is CWUser', 'X', 0), |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
298 |
ERQLExpression('X is CWGroup', 'X', 0)) |
4181 | 299 |
|
4132
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
300 |
class GuessRrqlExprMainVarsTC(TestCase): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
301 |
def test_exists(self): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
302 |
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
|
303 |
self.assertEquals(mainvars, 'O') |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
304 |
|
4181 | 305 |
|
0 | 306 |
if __name__ == '__main__': |
307 |
unittest_main() |