author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 03 Feb 2010 21:11:41 +0100 | |
changeset 4449 | 0411dca43e05 |
parent 4252 | 6c4f109c2b03 |
child 4467 | 0e73d299730a |
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 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
206 |
'specializes', 'state_of', 'subworkflow', 'subworkflow_exit', 'subworkflow_state', 'surname', 'symetric', '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 |
||
244 |
||
245 |
class BadSchemaRQLExprTC(TestCase): |
|
246 |
def setUp(self): |
|
247 |
self.loader = CubicWebSchemaLoader() |
|
248 |
self.loader.defined = {} |
|
951 | 249 |
self.loader.loaded_files = [] |
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
250 |
self.loader._pyreader = PyFileReader(self.loader) |
0 | 251 |
|
252 |
def _test(self, schemafile, msg): |
|
253 |
self.loader.handle_file(join(DATADIR, schemafile)) |
|
254 |
ex = self.assertRaises(BadSchemaDefinition, |
|
255 |
self.loader._build_schema, 'toto', False) |
|
256 |
self.assertEquals(str(ex), msg) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
257 |
|
0 | 258 |
def test_rrqlexpr_on_etype(self): |
259 |
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
|
260 |
|
0 | 261 |
def test_erqlexpr_on_rtype(self): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
262 |
self._test('erqlexpr_on_ertype.py', "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
|
263 |
|
0 | 264 |
def test_rqlexpr_on_rtype_read(self): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
265 |
self._test('rqlexpr_on_ertype_read.py', "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
|
266 |
|
0 | 267 |
def test_rrqlexpr_on_attr(self): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
268 |
self._test('rrqlexpr_on_attr.py', "can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression") |
0 | 269 |
|
270 |
||
271 |
class NormalizeExpressionTC(TestCase): |
|
272 |
||
273 |
def test(self): |
|
274 |
self.assertEquals(normalize_expression('X bla Y,Y blur Z , Z zigoulou X '), |
|
275 |
'X bla Y, Y blur Z, Z zigoulou X') |
|
276 |
||
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
277 |
class RQLExpressionTC(TestCase): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
278 |
def test_comparison(self): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
279 |
self.assertEquals(ERQLExpression('X is CWUser', 'X', 0), ERQLExpression('X is CWUser', 'X', 0)) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
280 |
self.assertNotEquals(ERQLExpression('X is CWUser', 'X', 0), ERQLExpression('X is CWGroup', 'X', 0)) |
4181 | 281 |
|
4132
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
282 |
class GuessRrqlExprMainVarsTC(TestCase): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
283 |
def test_exists(self): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
284 |
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
|
285 |
self.assertEquals(mainvars, 'O') |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
286 |
|
4181 | 287 |
|
0 | 288 |
if __name__ == '__main__': |
289 |
unittest_main() |