author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 17 Feb 2011 16:46:25 +0100 | |
branch | stable |
changeset 7008 | 5d0be45ee69d |
parent 6910 | bab54e22f94d |
child 6944 | 0cf10429ad39 |
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 |
|
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6768
diff
changeset
|
20 |
from __future__ import with_statement |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6768
diff
changeset
|
21 |
|
0 | 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 promo String'), |
|
78 |
# real relations |
|
79 |
('Personne travaille Societe'), |
|
80 |
('Personne evaluee Note'), |
|
81 |
('Societe evaluee Note'), |
|
82 |
('Personne concerne Affaire'), |
|
83 |
('Personne concerne Societe'), |
|
6861
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
84 |
('Affaire concerne Societe'), |
0 | 85 |
) |
86 |
done = {} |
|
87 |
for rel in RELS: |
|
88 |
_from, _type, _to = rel.split() |
|
89 |
if not _type.lower() in done: |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
90 |
schema.add_relation_type(RelationType(_type)) |
0 | 91 |
done[_type.lower()] = True |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
92 |
if _type == 'concerne': |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
93 |
schema.add_relation_def(RelationDefinition(_from, _type, _to, |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
94 |
__permissions__=CONCERNE_PERMISSIONS)) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
95 |
else: |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
96 |
schema.add_relation_def(RelationDefinition(_from, _type, _to)) |
0 | 97 |
|
98 |
class CubicWebSchemaTC(TestCase): |
|
99 |
||
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
100 |
def test_rql_constraints_inheritance(self): |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
101 |
# isinstance(cstr, RQLVocabularyConstraint) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
102 |
# -> expected to return RQLVocabularyConstraint and RQLConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
103 |
# instances but not RQLUniqueConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
104 |
# |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
105 |
# isinstance(cstr, RQLConstraint) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
106 |
# -> 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
|
107 |
# RRQLVocabularyConstraint and QLUniqueConstraint |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
108 |
self.failIf(issubclass(RQLUniqueConstraint, RQLVocabularyConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
109 |
self.failIf(issubclass(RQLUniqueConstraint, RQLConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
110 |
self.failUnless(issubclass(RQLConstraint, RQLVocabularyConstraint)) |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3899
diff
changeset
|
111 |
|
0 | 112 |
def test_entity_perms(self): |
113 |
self.assertEqual(eperson.get_groups('read'), set(('managers', 'users', 'guests'))) |
|
114 |
self.assertEqual(eperson.get_groups('update'), set(('managers', 'owners',))) |
|
115 |
self.assertEqual(eperson.get_groups('delete'), set(('managers', 'owners'))) |
|
116 |
self.assertEqual(eperson.get_groups('add'), set(('managers',))) |
|
117 |
self.assertEqual([str(e) for e in eperson.get_rqlexprs('add')], |
|
118 |
['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
|
119 |
eperson.set_action_permissions('read', ('managers',)) |
0 | 120 |
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
|
121 |
|
0 | 122 |
def test_relation_perms(self): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
123 |
rconcerne = schema.rschema('concerne').rdef('Personne', 'Societe') |
0 | 124 |
self.assertEqual(rconcerne.get_groups('read'), set(('managers', 'users', 'guests'))) |
125 |
self.assertEqual(rconcerne.get_groups('delete'), set(('managers',))) |
|
126 |
self.assertEqual(rconcerne.get_groups('add'), set(('managers', ))) |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
127 |
rconcerne.set_action_permissions('read', ('managers',)) |
0 | 128 |
self.assertEqual(rconcerne.get_groups('read'), set(('managers',))) |
129 |
self.assertEqual([str(e) for e in rconcerne.get_rqlexprs('add')], |
|
3899
78a2c8e7eef5
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
130 |
['Any S,U WHERE U has_update_permission S, S eid %(s)s, U eid %(u)s']) |
0 | 131 |
|
132 |
def test_erqlexpression(self): |
|
133 |
self.assertRaises(RQLSyntaxError, ERQLExpression, '1') |
|
134 |
expr = ERQLExpression('X travaille S, S owned_by U') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6306
diff
changeset
|
135 |
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
|
136 |
|
0 | 137 |
def test_rrqlexpression(self): |
138 |
self.assertRaises(Exception, RRQLExpression, '1') |
|
139 |
self.assertRaises(RQLSyntaxError, RRQLExpression, 'O X Y') |
|
140 |
expr = RRQLExpression('U has_update_permission O') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6306
diff
changeset
|
141 |
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
|
142 |
|
0 | 143 |
loader = CubicWebSchemaLoader() |
6640
4c4616c02f69
[test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
144 |
config = TestConfiguration('data', apphome=DATADIR) |
0 | 145 |
config.bootstrap_cubes() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
146 |
|
2926
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
147 |
class SchemaReaderClassTest(TestCase): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
148 |
|
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
149 |
def test_order_eschemas(self): |
4484387ed012
when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
150 |
schema = loader.load(config) |
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(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
|
152 |
[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
|
153 |
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
|
154 |
[schema['Note'], schema['SubNote']]) |
0 | 155 |
|
156 |
def test_knownValues_load_schema(self): |
|
157 |
schema = loader.load(config) |
|
158 |
self.assert_(isinstance(schema, CubicWebSchema)) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6306
diff
changeset
|
159 |
self.assertEqual(schema.name, 'data') |
6415 | 160 |
entities = sorted([str(e) for e in schema.entities()]) |
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', |
6306
e6557be1127e
[test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6117
diff
changeset
|
165 |
'CWPermission', 'CWProperty', 'CWRType', |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
166 |
'CWSource', 'CWSourceHostConfig', |
6306
e6557be1127e
[test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6117
diff
changeset
|
167 |
'CWUniqueTogetherConstraint', 'CWUser', |
5563
26e242ba3da5
with cw 3.9, no more Image type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
168 |
'ExternalUri', 'File', 'Float', 'Int', 'Interval', 'Note', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
169 |
'Password', 'Personne', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
170 |
'RQLExpression', |
6910
bab54e22f94d
fix test broken by addition of new entity in test schema
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6873
diff
changeset
|
171 |
'Societe', 'State', 'StateFull', 'String', 'SubNote', 'SubWorkflowExitPoint', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
172 |
'Tag', 'Time', 'Transition', 'TrInfo', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
173 |
'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
|
174 |
self.assertListEqual(entities, sorted(expected_entities)) |
6415 | 175 |
relations = sorted([str(r) for r in schema.relations()]) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
176 |
expected_relations = ['add_permission', 'address', 'alias', 'allowed_transition', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
177 |
'bookmarked_by', 'by_transition', |
0 | 178 |
|
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
179 |
'cardinality', 'comment', 'comment_format', |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
180 |
'composite', 'condition', 'config', 'connait', |
6306
e6557be1127e
[test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6117
diff
changeset
|
181 |
'constrained_by', 'constraint_of', |
e6557be1127e
[test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6117
diff
changeset
|
182 |
'content', 'content_format', |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
183 |
'created_by', 'creation_date', 'cstrtype', 'custom_workflow', |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
184 |
'cwuri', 'cw_source', 'cw_host_config_of', |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
185 |
'cw_support', 'cw_dont_cross', 'cw_may_cross', |
0 | 186 |
|
3587 | 187 |
'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
|
188 |
'description', 'description_format', 'destination_state', |
0 | 189 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
190 |
'ecrit_par', 'eid', 'evaluee', 'expression', 'exprtype', |
0 | 191 |
|
192 |
'final', 'firstname', 'for_user', |
|
193 |
'from_entity', 'from_state', 'fulltext_container', 'fulltextindexed', |
|
194 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
195 |
'has_text', |
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
196 |
'identity', 'in_group', 'in_state', 'indexed', |
0 | 197 |
'initial_state', 'inlined', 'internationalizable', 'is', 'is_instance_of', |
198 |
||
199 |
'label', 'last_login_time', 'login', |
|
200 |
||
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
201 |
'mainvars', 'match_host', 'modification_date', |
0 | 202 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
203 |
'name', 'nom', |
0 | 204 |
|
205 |
'ordernum', 'owned_by', |
|
206 |
||
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2943
diff
changeset
|
207 |
'path', 'pkey', 'prefered_form', 'prenom', 'primary_email', |
0 | 208 |
|
6306
e6557be1127e
[test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6117
diff
changeset
|
209 |
'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
|
210 |
|
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
|
211 |
'specializes', 'state_of', 'subworkflow', 'subworkflow_exit', 'subworkflow_state', 'surname', 'symmetric', 'synopsis', |
0 | 212 |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
213 |
'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type', |
0 | 214 |
|
2456
aa25d6b244c8
new cwuri metadata + a few tests fixes on the way
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
215 |
'upassword', 'update_permission', 'uri', 'use_email', |
0 | 216 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
217 |
'value', |
0 | 218 |
|
6768
b75f688bded7
fix unittest broken by TrInfo schema change
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6640
diff
changeset
|
219 |
'wf_info_for', 'wikiid', 'workflow_of', 'tr_count'] |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
220 |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
221 |
self.assertListEqual(relations, sorted(expected_relations)) |
0 | 222 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
985
diff
changeset
|
223 |
eschema = schema.eschema('CWUser') |
0 | 224 |
rels = sorted(str(r) for r in eschema.subject_relations()) |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
225 |
self.assertListEqual(rels, ['created_by', 'creation_date', 'custom_workflow', |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
226 |
'cw_source', 'cwuri', 'eid', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
624
diff
changeset
|
227 |
'evaluee', 'firstname', 'has_text', 'identity', |
0 | 228 |
'in_group', 'in_state', 'is', |
229 |
'is_instance_of', 'last_login_time', |
|
230 |
'login', 'modification_date', 'owned_by', |
|
231 |
'primary_email', 'surname', 'upassword', |
|
232 |
'use_email']) |
|
233 |
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
|
234 |
self.assertListEqual(rels, ['bookmarked_by', 'created_by', 'for_user', |
0 | 235 |
'identity', 'owned_by', 'wf_info_for']) |
236 |
rschema = schema.rschema('relation_type') |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
237 |
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
|
238 |
self.assertEqual(properties.cardinality, '1*') |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
239 |
constraints = properties.constraints |
0 | 240 |
self.failUnlessEqual(len(constraints), 1, constraints) |
241 |
constraint = constraints[0] |
|
242 |
self.failUnless(isinstance(constraint, RQLConstraint)) |
|
243 |
self.failUnlessEqual(constraint.restriction, 'O final TRUE') |
|
244 |
||
245 |
def test_fulltext_container(self): |
|
246 |
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
|
247 |
self.failUnless('has_text' in schema['CWUser'].subject_relations()) |
0 | 248 |
self.failIf('has_text' in schema['EmailAddress'].subject_relations()) |
249 |
||
5179
f08943f22334
[schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4611
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
()) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6306
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
['U has_update_permission X']) |
0 | 261 |
|
6861
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
262 |
class BadSchemaTC(TestCase): |
0 | 263 |
def setUp(self): |
264 |
self.loader = CubicWebSchemaLoader() |
|
265 |
self.loader.defined = {} |
|
951 | 266 |
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
|
267 |
self.loader.post_build_callbacks = [] |
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2456
diff
changeset
|
268 |
self.loader._pyreader = PyFileReader(self.loader) |
0 | 269 |
|
270 |
def _test(self, schemafile, msg): |
|
271 |
self.loader.handle_file(join(DATADIR, schemafile)) |
|
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6768
diff
changeset
|
272 |
with self.assertRaises(BadSchemaDefinition) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6768
diff
changeset
|
273 |
self.loader._build_schema('toto', False) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6768
diff
changeset
|
274 |
self.assertEqual(str(cm.exception), msg) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
275 |
|
6861
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
276 |
def test_lowered_etype(self): |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
277 |
self._test('lowered_etype.py', |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
278 |
"'my_etype' is not a valid name for an entity type. It should " |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
279 |
"start with an upper cased letter and be followed by at least " |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
280 |
"a lower cased letter") |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
281 |
|
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
282 |
def test_uppered_rtype(self): |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
283 |
self._test('uppered_rtype.py', |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
284 |
"'ARelation' is not a valid name for a relation type. It should be lower cased") |
9d4e11d6e783
[schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
285 |
|
0 | 286 |
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
|
287 |
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
|
288 |
"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
|
289 |
|
0 | 290 |
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
|
291 |
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
|
292 |
"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
|
293 |
|
0 | 294 |
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
|
295 |
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
|
296 |
"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
|
297 |
|
0 | 298 |
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
|
299 |
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
|
300 |
"can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression") |
0 | 301 |
|
302 |
||
303 |
class NormalizeExpressionTC(TestCase): |
|
304 |
||
305 |
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
|
306 |
self.assertEqual(normalize_expression('X bla Y,Y blur Z , Z zigoulou X '), |
0 | 307 |
'X bla Y, Y blur Z, Z zigoulou X') |
308 |
||
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
309 |
class RQLExpressionTC(TestCase): |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
310 |
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
|
311 |
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
|
312 |
ERQLExpression('X is CWUser', 'X', 0)) |
6415 | 313 |
self.assertNotEqual(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
|
314 |
ERQLExpression('X is CWGroup', 'X', 0)) |
4181 | 315 |
|
4132
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
316 |
class GuessRrqlExprMainVarsTC(TestCase): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
317 |
def test_exists(self): |
440d383367eb
fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
|
4181 | 321 |
|
0 | 322 |
if __name__ == '__main__': |
323 |
unittest_main() |