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