author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 09 Jun 2010 14:44:45 +0200 | |
branch | stable |
changeset 5703 | 24ca7615379b |
parent 5424 | 8ecbcbff9777 |
child 5563 | 26e242ba3da5 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5179
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
18 |
"""unit tests for module cubicweb.schema |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
19 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
20 |
""" |
0 | 21 |
|
22 |
import sys |
|
23 |
from os.path import join, isabs, basename, dirname |
|
24 |
||
25 |
from logilab.common.testlib import TestCase, unittest_main |
|
26 |
||
27 |
from rql import RQLSyntaxError |
|
28 |
||
29 |
from yams import BadSchemaDefinition |
|
30 |
from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
|
31 |
from yams.buildobjs import RelationDefinition, EntityType, RelationType |
|
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
32 |
from yams.reader import PyFileReader |
0 | 33 |
|
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
34 |
from cubicweb.schema import ( |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
35 |
CubicWebSchema, CubicWebEntitySchema, CubicWebSchemaLoader, |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
36 |
RQLConstraint, RQLUniqueConstraint, RQLVocabularyConstraint, |
3998
94cc7cad3d2d
backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
37 |
RQLExpression, ERQLExpression, RRQLExpression, |
4132
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
38 |
normalize_expression, order_eschemas, guess_rrqlexpr_mainvars) |
0 | 39 |
from cubicweb.devtools import TestServerConfiguration as TestConfiguration |
40 |
||
41 |
DATADIR = join(dirname(__file__), 'data') |
|
42 |
||
43 |
# build a dummy schema ######################################################## |
|
44 |
||
45 |
||
46 |
PERSONNE_PERMISSIONS = { |
|
47 |
'read': ('managers', 'users', 'guests'), |
|
48 |
'update': ('managers', 'owners'), |
|
49 |
'add': ('managers', ERQLExpression('X travaille S, S owned_by U')), |
|
50 |
'delete': ('managers', 'owners',), |
|
51 |
} |
|
52 |
||
53 |
CONCERNE_PERMISSIONS = { |
|
54 |
'read': ('managers', 'users', 'guests'), |
|
55 |
'add': ('managers', RRQLExpression('U has_update_permission S')), |
|
56 |
'delete': ('managers', RRQLExpression('O owned_by U')), |
|
57 |
} |
|
58 |
||
59 |
schema = CubicWebSchema('Test Schema') |
|
60 |
enote = schema.add_entity_type(EntityType('Note')) |
|
61 |
eaffaire = schema.add_entity_type(EntityType('Affaire')) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
62 |
eperson = schema.add_entity_type(EntityType('Personne', __permissions__=PERSONNE_PERMISSIONS)) |
0 | 63 |
esociete = schema.add_entity_type(EntityType('Societe')) |
64 |
||
65 |
RELS = ( |
|
66 |
# attribute relations |
|
67 |
('Note date String'), |
|
68 |
('Note type String'), |
|
69 |
('Affaire sujet String'), |
|
70 |
('Affaire ref String'), |
|
71 |
('Personne nom String'), |
|
72 |
('Personne prenom String'), |
|
73 |
('Personne sexe String'), |
|
74 |
('Personne tel Int'), |
|
75 |
('Personne fax Int'), |
|
76 |
('Personne datenaiss Date'), |
|
77 |
('Personne TEST Boolean'), |
|
78 |
('Personne promo String'), |
|
79 |
# real relations |
|
80 |
('Personne travaille Societe'), |
|
81 |
('Personne evaluee Note'), |
|
82 |
('Societe evaluee Note'), |
|
83 |
('Personne concerne Affaire'), |
|
84 |
('Personne concerne Societe'), |
|
85 |
('Affaire Concerne Societe'), |
|
86 |
) |
|
87 |
done = {} |
|
88 |
for rel in RELS: |
|
89 |
_from, _type, _to = rel.split() |
|
90 |
if not _type.lower() in done: |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
91 |
schema.add_relation_type(RelationType(_type)) |
0 | 92 |
done[_type.lower()] = True |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
93 |
if _type == 'concerne': |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
94 |
schema.add_relation_def(RelationDefinition(_from, _type, _to, |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
95 |
__permissions__=CONCERNE_PERMISSIONS)) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
96 |
else: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
97 |
schema.add_relation_def(RelationDefinition(_from, _type, _to)) |
0 | 98 |
|
99 |
class CubicWebSchemaTC(TestCase): |
|
100 |
||
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
101 |
def test_rql_constraints_inheritance(self): |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
102 |
# isinstance(cstr, RQLVocabularyConstraint) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
103 |
# -> expected to return RQLVocabularyConstraint and RQLConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
104 |
# instances but not RQLUniqueConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
105 |
# |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
106 |
# isinstance(cstr, RQLConstraint) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
107 |
# -> 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
|
108 |
# RRQLVocabularyConstraint and QLUniqueConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
109 |
self.failIf(issubclass(RQLUniqueConstraint, RQLVocabularyConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
110 |
self.failIf(issubclass(RQLUniqueConstraint, RQLConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
111 |
self.failUnless(issubclass(RQLConstraint, RQLVocabularyConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
112 |
|
0 | 113 |
def test_normalize(self): |
114 |
"""test that entities, relations and attributes name are normalized |
|
115 |
""" |
|
116 |
self.assertEqual(esociete.type, 'Societe') |
|
117 |
self.assertEqual(schema.has_relation('TEST'), 0) |
|
118 |
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
|
119 |
self.assertEqual(eperson.subjrels['test'].type, 'test') |
0 | 120 |
self.assertEqual(schema.has_relation('Concerne'), 0) |
121 |
self.assertEqual(schema.has_relation('concerne'), 1) |
|
122 |
self.assertEqual(schema.rschema('concerne').type, 'concerne') |
|
123 |
||
124 |
def test_entity_perms(self): |
|
125 |
self.assertEqual(eperson.get_groups('read'), set(('managers', 'users', 'guests'))) |
|
126 |
self.assertEqual(eperson.get_groups('update'), set(('managers', 'owners',))) |
|
127 |
self.assertEqual(eperson.get_groups('delete'), set(('managers', 'owners'))) |
|
128 |
self.assertEqual(eperson.get_groups('add'), set(('managers',))) |
|
129 |
self.assertEqual([str(e) for e in eperson.get_rqlexprs('add')], |
|
130 |
['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
|
131 |
eperson.set_action_permissions('read', ('managers',)) |
0 | 132 |
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
|
133 |
|
0 | 134 |
def test_relation_perms(self): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
135 |
rconcerne = schema.rschema('concerne').rdef('Personne', 'Societe') |
0 | 136 |
self.assertEqual(rconcerne.get_groups('read'), set(('managers', 'users', 'guests'))) |
137 |
self.assertEqual(rconcerne.get_groups('delete'), set(('managers',))) |
|
138 |
self.assertEqual(rconcerne.get_groups('add'), set(('managers', ))) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
139 |
rconcerne.set_action_permissions('read', ('managers',)) |
0 | 140 |
self.assertEqual(rconcerne.get_groups('read'), set(('managers',))) |
141 |
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
|
142 |
['Any S,U WHERE U has_update_permission S, S eid %(s)s, U eid %(u)s']) |
0 | 143 |
|
144 |
def test_erqlexpression(self): |
|
145 |
self.assertRaises(RQLSyntaxError, ERQLExpression, '1') |
|
146 |
expr = ERQLExpression('X travaille S, S owned_by U') |
|
147 |
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
|
148 |
|
0 | 149 |
def test_rrqlexpression(self): |
150 |
self.assertRaises(Exception, RRQLExpression, '1') |
|
151 |
self.assertRaises(RQLSyntaxError, RRQLExpression, 'O X Y') |
|
152 |
expr = RRQLExpression('U has_update_permission O') |
|
3899
78a2c8e7eef5
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
153 |
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
|
154 |
|
0 | 155 |
loader = CubicWebSchemaLoader() |
156 |
config = TestConfiguration('data') |
|
157 |
config.bootstrap_cubes() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
158 |
|
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
|
159 |
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
|
160 |
|
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
[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
|
165 |
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
|
166 |
[schema['Note'], schema['SubNote']]) |
0 | 167 |
|
168 |
def test_knownValues_load_schema(self): |
|
169 |
schema = loader.load(config) |
|
170 |
self.assert_(isinstance(schema, CubicWebSchema)) |
|
171 |
self.assertEquals(schema.name, 'data') |
|
172 |
entities = [str(e) for e in schema.entities()] |
|
173 |
entities.sort() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
174 |
expected_entities = ['BaseTransition', 'Bookmark', 'Boolean', 'Bytes', 'Card', |
0 | 175 |
'Date', 'Datetime', 'Decimal', |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
176 |
'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
177 |
'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
178 |
'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
|
179 |
'ExternalUri', 'File', 'Float', 'Image', 'Int', 'Interval', 'Note', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
180 |
'Password', 'Personne', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
181 |
'RQLExpression', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
182 |
'Societe', 'State', 'String', 'SubNote', 'SubWorkflowExitPoint', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
183 |
'Tag', 'Time', 'Transition', 'TrInfo', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
184 |
'Workflow', 'WorkflowTransition'] |
0 | 185 |
self.assertListEquals(entities, sorted(expected_entities)) |
186 |
relations = [str(r) for r in schema.relations()] |
|
187 |
relations.sort() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
188 |
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
|
189 |
'bookmarked_by', 'by_transition', |
0 | 190 |
|
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
191 |
'cardinality', 'comment', 'comment_format', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
192 |
'composite', 'condition', 'connait', 'constrained_by', 'content', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
193 |
'content_format', 'created_by', 'creation_date', 'cstrtype', 'custom_workflow', 'cwuri', |
0 | 194 |
|
3587 | 195 |
'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
|
196 |
'description', 'description_format', 'destination_state', |
0 | 197 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
198 |
'ecrit_par', 'eid', 'evaluee', 'expression', 'exprtype', |
0 | 199 |
|
200 |
'final', 'firstname', 'for_user', |
|
201 |
'from_entity', 'from_state', 'fulltext_container', 'fulltextindexed', |
|
202 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
203 |
'has_text', |
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
204 |
'identity', 'in_group', 'in_state', 'indexed', |
0 | 205 |
'initial_state', 'inlined', 'internationalizable', 'is', 'is_instance_of', |
206 |
||
207 |
'label', 'last_login_time', 'login', |
|
208 |
||
2456
aa25d6b244c8
new cwuri metadata + a few tests fixes on the way
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
209 |
'mainvars', 'modification_date', |
0 | 210 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
211 |
'name', 'nom', |
0 | 212 |
|
213 |
'ordernum', 'owned_by', |
|
214 |
||
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
215 |
'path', 'pkey', 'prefered_form', 'prenom', 'primary_email', |
0 | 216 |
|
217 |
'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
|
218 |
|
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
|
219 |
'specializes', 'state_of', 'subworkflow', 'subworkflow_exit', 'subworkflow_state', 'surname', 'symmetric', 'synopsis', |
0 | 220 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
221 |
'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type', |
0 | 222 |
|
2456
aa25d6b244c8
new cwuri metadata + a few tests fixes on the way
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
223 |
'upassword', 'update_permission', 'uri', 'use_email', |
0 | 224 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
225 |
'value', |
0 | 226 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
227 |
'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
|
228 |
|
0 | 229 |
self.assertListEquals(relations, expected_relations) |
230 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
231 |
eschema = schema.eschema('CWUser') |
0 | 232 |
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
|
233 |
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
|
234 |
'evaluee', 'firstname', 'has_text', 'identity', |
0 | 235 |
'in_group', 'in_state', 'is', |
236 |
'is_instance_of', 'last_login_time', |
|
237 |
'login', 'modification_date', 'owned_by', |
|
238 |
'primary_email', 'surname', 'upassword', |
|
239 |
'use_email']) |
|
240 |
rels = sorted(r.type for r in eschema.object_relations()) |
|
241 |
self.assertListEquals(rels, ['bookmarked_by', 'created_by', 'for_user', |
|
242 |
'identity', 'owned_by', 'wf_info_for']) |
|
243 |
rschema = schema.rschema('relation_type') |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
244 |
properties = rschema.rdef('CWAttribute', 'CWRType') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
245 |
self.assertEquals(properties.cardinality, '1*') |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
246 |
constraints = properties.constraints |
0 | 247 |
self.failUnlessEqual(len(constraints), 1, constraints) |
248 |
constraint = constraints[0] |
|
249 |
self.failUnless(isinstance(constraint, RQLConstraint)) |
|
250 |
self.failUnlessEqual(constraint.restriction, 'O final TRUE') |
|
251 |
||
252 |
def test_fulltext_container(self): |
|
253 |
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
|
254 |
self.failUnless('has_text' in schema['CWUser'].subject_relations()) |
0 | 255 |
self.failIf('has_text' in schema['EmailAddress'].subject_relations()) |
256 |
||
5179
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
()) |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
264 |
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
|
265 |
set(('managers',))) |
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
266 |
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
|
267 |
['U has_update_permission X']) |
0 | 268 |
|
269 |
class BadSchemaRQLExprTC(TestCase): |
|
270 |
def setUp(self): |
|
271 |
self.loader = CubicWebSchemaLoader() |
|
272 |
self.loader.defined = {} |
|
951 | 273 |
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
|
274 |
self.loader.post_build_callbacks = [] |
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
275 |
self.loader._pyreader = PyFileReader(self.loader) |
0 | 276 |
|
277 |
def _test(self, schemafile, msg): |
|
278 |
self.loader.handle_file(join(DATADIR, schemafile)) |
|
279 |
ex = self.assertRaises(BadSchemaDefinition, |
|
280 |
self.loader._build_schema, 'toto', False) |
|
281 |
self.assertEquals(str(ex), msg) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
282 |
|
0 | 283 |
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
|
284 |
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
|
285 |
"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
|
286 |
|
0 | 287 |
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
|
288 |
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
|
289 |
"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
|
290 |
|
0 | 291 |
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
|
292 |
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
|
293 |
"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
|
294 |
|
0 | 295 |
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
|
296 |
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
|
297 |
"can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression") |
0 | 298 |
|
299 |
||
300 |
class NormalizeExpressionTC(TestCase): |
|
301 |
||
302 |
def test(self): |
|
303 |
self.assertEquals(normalize_expression('X bla Y,Y blur Z , Z zigoulou X '), |
|
304 |
'X bla Y, Y blur Z, Z zigoulou X') |
|
305 |
||
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
306 |
class RQLExpressionTC(TestCase): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
ERQLExpression('X is CWGroup', 'X', 0)) |
4181 | 312 |
|
4132
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
313 |
class GuessRrqlExprMainVarsTC(TestCase): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
314 |
def test_exists(self): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
315 |
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
|
316 |
self.assertEquals(mainvars, 'O') |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
317 |
|
4181 | 318 |
|
0 | 319 |
if __name__ == '__main__': |
320 |
unittest_main() |