author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 21 Jul 2009 23:09:27 +0200 | |
branch | stable |
changeset 2413 | b1bea4cab594 |
parent 2251 | 799ff50ddfe8 |
child 2453 | 0faf7b5cdc71 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
"""functional tests for core hooks |
|
3 |
||
4 |
note: most schemahooks.py hooks are actually tested in unittest_migrations.py |
|
1981
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
5 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 6 |
""" |
7 |
||
8 |
from logilab.common.testlib import TestCase, unittest_main |
|
9 |
from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions |
|
10 |
||
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
11 |
from cubicweb import ConnectionError, RepositoryError, ValidationError, AuthenticationError, BadConnectionId |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
12 |
from cubicweb.server.sqlutils import SQL_PREFIX |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
13 |
from cubicweb.server.repository import Repository |
0 | 14 |
|
15 |
orig_get_versions = Repository.get_versions |
|
16 |
||
17 |
def setup_module(*args): |
|
18 |
Repository.get_versions = get_versions |
|
19 |
||
20 |
def teardown_module(*args): |
|
21 |
Repository.get_versions = orig_get_versions |
|
22 |
||
23 |
||
1787 | 24 |
|
0 | 25 |
class CoreHooksTC(RepositoryBasedTC): |
1787 | 26 |
|
0 | 27 |
def test_delete_internal_entities(self): |
28 |
self.assertRaises(RepositoryError, self.execute, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
29 |
'DELETE CWEType X WHERE X name "CWEType"') |
0 | 30 |
self.assertRaises(RepositoryError, self.execute, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
31 |
'DELETE CWRType X WHERE X name "relation_type"') |
0 | 32 |
self.assertRaises(RepositoryError, self.execute, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
33 |
'DELETE CWGroup X WHERE X name "owners"') |
0 | 34 |
|
35 |
def test_delete_required_relations_subject(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
36 |
self.execute('INSERT CWUser X: X login "toto", X upassword "hop", X in_group Y, X in_state S ' |
0 | 37 |
'WHERE Y name "users", S name "activated"') |
38 |
self.commit() |
|
39 |
self.execute('DELETE X in_group Y WHERE X login "toto", Y name "users"') |
|
40 |
self.assertRaises(ValidationError, self.commit) |
|
41 |
self.execute('DELETE X in_group Y WHERE X login "toto"') |
|
42 |
self.execute('SET X in_group Y WHERE X login "toto", Y name "guests"') |
|
43 |
self.commit() |
|
1787 | 44 |
|
0 | 45 |
def test_delete_required_relations_object(self): |
46 |
self.skip('no sample in the schema ! YAGNI ? Kermaat ?') |
|
1787 | 47 |
|
0 | 48 |
def test_static_vocabulary_check(self): |
49 |
self.assertRaises(ValidationError, |
|
50 |
self.execute, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
51 |
'SET X composite "whatever" WHERE X from_entity FE, FE name "CWUser", X relation_type RT, RT name "in_group"') |
1787 | 52 |
|
0 | 53 |
def test_missing_required_relations_subject_inline(self): |
1787 | 54 |
# missing in_group relation |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
55 |
self.execute('INSERT CWUser X: X login "toto", X upassword "hop"') |
0 | 56 |
self.assertRaises(ValidationError, |
57 |
self.commit) |
|
58 |
||
59 |
def test_delete_if_singlecard1(self): |
|
60 |
self.assertEquals(self.repo.schema['in_state'].inlined, False) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
61 |
ueid, = self.execute('INSERT CWUser X: X login "toto", X upassword "hop", X in_group Y, X in_state S ' |
0 | 62 |
'WHERE Y name "users", S name "activated"')[0] |
63 |
self.commit() |
|
64 |
self.execute('SET X in_state S WHERE S name "deactivated", X eid %(x)s', {'x': ueid}) |
|
65 |
rset = self.execute('Any S WHERE X in_state S, X eid %(x)s', {'x': ueid}) |
|
66 |
self.assertEquals(len(rset), 1) |
|
67 |
self.assertRaises(Exception, self.execute, 'SET X in_state S WHERE S name "deactivated", X eid %s' % ueid) |
|
68 |
rset2 = self.execute('Any S WHERE X in_state S, X eid %(x)s', {'x': ueid}) |
|
69 |
self.assertEquals(rset.rows, rset2.rows) |
|
70 |
||
71 |
def test_inlined(self): |
|
72 |
self.assertEquals(self.repo.schema['sender'].inlined, True) |
|
73 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
74 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
75 |
eeid = self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
76 |
'WHERE Y is EmailAddress, P is EmailPart')[0][0] |
|
77 |
self.execute('SET X sender Y WHERE X is Email, Y is EmailAddress') |
|
78 |
rset = self.execute('Any S WHERE X sender S, X eid %s' % eeid) |
|
79 |
self.assertEquals(len(rset), 1) |
|
1787 | 80 |
|
0 | 81 |
def test_composite_1(self): |
82 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
83 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
84 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
85 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
86 |
self.failUnless(self.execute('Email X WHERE X sender Y')) |
|
87 |
self.commit() |
|
88 |
self.execute('DELETE Email X') |
|
89 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
90 |
self.assertEquals(len(rset), 1) |
|
91 |
self.commit() |
|
92 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
93 |
self.assertEquals(len(rset), 0) |
|
1787 | 94 |
|
0 | 95 |
def test_composite_2(self): |
96 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
97 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
98 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
99 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
100 |
self.commit() |
|
101 |
self.execute('DELETE Email X') |
|
102 |
self.execute('DELETE EmailPart X') |
|
103 |
self.commit() |
|
104 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
105 |
self.assertEquals(len(rset), 0) |
|
1787 | 106 |
|
0 | 107 |
def test_composite_redirection(self): |
108 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
109 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
110 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
111 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
112 |
self.execute('INSERT Email X: X messageid "<2345>", X subject "test2", X sender Y, X recipients Y ' |
|
113 |
'WHERE Y is EmailAddress') |
|
114 |
self.commit() |
|
115 |
self.execute('DELETE X parts Y WHERE X messageid "<1234>"') |
|
116 |
self.execute('SET X parts Y WHERE X messageid "<2345>"') |
|
117 |
self.commit() |
|
118 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
119 |
self.assertEquals(len(rset), 1) |
|
120 |
self.assertEquals(rset.get_entity(0, 0).reverse_parts[0].messageid, '<2345>') |
|
121 |
||
122 |
def test_unsatisfied_constraints(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
123 |
self.execute('INSERT CWRelation X: X from_entity FE, X relation_type RT, X to_entity TE ' |
0 | 124 |
'WHERE FE name "Affaire", RT name "concerne", TE name "String"') |
125 |
self.assertRaises(ValidationError, |
|
126 |
self.commit) |
|
127 |
||
128 |
||
129 |
def test_html_tidy_hook(self): |
|
130 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "yo"').get_entity(0, 0) |
|
131 |
self.assertEquals(entity.descr, u'yo') |
|
132 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "<b>yo"').get_entity(0, 0) |
|
133 |
self.assertEquals(entity.descr, u'<b>yo</b>') |
|
134 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "<b>yo</b>"').get_entity(0, 0) |
|
135 |
self.assertEquals(entity.descr, u'<b>yo</b>') |
|
136 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "<b>R&D</b>"').get_entity(0, 0) |
|
137 |
self.assertEquals(entity.descr, u'<b>R&D</b>') |
|
138 |
xml = u"<div>c'est <b>l'été" |
|
139 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr %(d)s', |
|
140 |
{'d': xml}).get_entity(0, 0) |
|
141 |
self.assertEquals(entity.descr, u"<div>c'est <b>l'été</b></div>") |
|
142 |
||
143 |
def test_nonregr_html_tidy_hook_no_update(self): |
|
144 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "yo"').get_entity(0, 0) |
|
145 |
self.assertEquals(entity.descr, u'yo') |
|
146 |
self.execute('SET A ref "REF" WHERE A eid %s' % entity.eid) |
|
147 |
entity = self.execute('Any A WHERE A eid %s' % entity.eid).get_entity(0, 0) |
|
148 |
self.assertEquals(entity.descr, u'yo') |
|
149 |
self.execute('SET A descr "R&D<p>yo" WHERE A eid %s' % entity.eid) |
|
150 |
entity = self.execute('Any A WHERE A eid %s' % entity.eid).get_entity(0, 0) |
|
151 |
self.assertEquals(entity.descr, u'R&D<p>yo</p>') |
|
1787 | 152 |
|
153 |
||
0 | 154 |
|
155 |
class UserGroupHooksTC(RepositoryBasedTC): |
|
1787 | 156 |
|
0 | 157 |
def test_user_synchronization(self): |
158 |
self.create_user('toto', password='hop', commit=False) |
|
159 |
self.assertRaises(AuthenticationError, |
|
160 |
self.repo.connect, u'toto', 'hop') |
|
161 |
self.commit() |
|
162 |
cnxid = self.repo.connect(u'toto', 'hop') |
|
163 |
self.failIfEqual(cnxid, self.cnxid) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
164 |
self.execute('DELETE CWUser X WHERE X login "toto"') |
0 | 165 |
self.repo.execute(cnxid, 'State X') |
166 |
self.commit() |
|
167 |
self.assertRaises(BadConnectionId, |
|
168 |
self.repo.execute, cnxid, 'State X') |
|
169 |
||
170 |
def test_user_group_synchronization(self): |
|
171 |
user = self.session.user |
|
172 |
self.assertEquals(user.groups, set(('managers',))) |
|
173 |
self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
174 |
self.assertEquals(user.groups, set(('managers',))) |
|
175 |
self.commit() |
|
176 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
177 |
self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
178 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
179 |
self.commit() |
|
180 |
self.assertEquals(user.groups, set(('managers',))) |
|
181 |
||
182 |
def test_user_composite_owner(self): |
|
183 |
ueid = self.create_user('toto') |
|
184 |
# composite of euser should be owned by the euser regardless of who created it |
|
185 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X ' |
|
186 |
'WHERE U login "toto"') |
|
187 |
self.commit() |
|
188 |
self.assertEquals(self.execute('Any A WHERE X owned_by U, U use_email X,' |
|
189 |
'U login "toto", X address A')[0][0], |
|
190 |
'toto@logilab.fr') |
|
191 |
||
192 |
def test_no_created_by_on_deleted_entity(self): |
|
193 |
eid = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0] |
|
194 |
self.execute('DELETE EmailAddress X WHERE X eid %s' % eid) |
|
195 |
self.commit() |
|
196 |
self.failIf(self.execute('Any X WHERE X created_by Y, X eid >= %(x)s', {'x': eid})) |
|
1787 | 197 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
198 |
class CWPropertyHooksTC(RepositoryBasedTC): |
1787 | 199 |
|
0 | 200 |
def test_unexistant_eproperty(self): |
201 |
ex = self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
202 |
self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U') |
0 | 203 |
self.assertEquals(ex.errors, {'pkey': 'unknown property key'}) |
204 |
ex = self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
205 |
self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop"') |
0 | 206 |
self.assertEquals(ex.errors, {'pkey': 'unknown property key'}) |
1787 | 207 |
|
0 | 208 |
def test_site_wide_eproperty(self): |
209 |
ex = self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
210 |
self.execute, 'INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U') |
0 | 211 |
self.assertEquals(ex.errors, {'for_user': "site-wide property can't be set for user"}) |
1787 | 212 |
|
0 | 213 |
def test_bad_type_eproperty(self): |
214 |
ex = self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
215 |
self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U') |
0 | 216 |
self.assertEquals(ex.errors, {'value': u'unauthorized value'}) |
217 |
ex = self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
218 |
self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop"') |
0 | 219 |
self.assertEquals(ex.errors, {'value': u'unauthorized value'}) |
1787 | 220 |
|
221 |
||
0 | 222 |
class SchemaHooksTC(RepositoryBasedTC): |
1787 | 223 |
|
0 | 224 |
def test_duplicate_etype_error(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
225 |
# check we can't add a CWEType or CWRType entity if it already exists one |
0 | 226 |
# with the same name |
227 |
# |
|
228 |
# according to hook order, we'll get a repository or validation error |
|
229 |
self.assertRaises((ValidationError, RepositoryError), |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
230 |
self.execute, 'INSERT CWEType X: X name "Societe"') |
0 | 231 |
self.assertRaises((ValidationError, RepositoryError), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
232 |
self.execute, 'INSERT CWRType X: X name "in_group"') |
1787 | 233 |
|
0 | 234 |
def test_validation_unique_constraint(self): |
235 |
self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
236 |
self.execute, 'INSERT CWUser X: X login "admin"') |
0 | 237 |
try: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
238 |
self.execute('INSERT CWUser X: X login "admin"') |
0 | 239 |
except ValidationError, ex: |
240 |
self.assertIsInstance(ex.entity, int) |
|
241 |
self.assertEquals(ex.errors, {'login': 'the value "admin" is already used, use another one'}) |
|
242 |
||
243 |
||
244 |
class SchemaModificationHooksTC(RepositoryBasedTC): |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1990
diff
changeset
|
245 |
#copy_schema = True |
0 | 246 |
|
247 |
def setUp(self): |
|
248 |
if not hasattr(self, '_repo'): |
|
249 |
# first initialization |
|
250 |
repo = self.repo # set by the RepositoryBasedTC metaclass |
|
251 |
# force to read schema from the database |
|
252 |
repo.config._cubes = None |
|
253 |
repo.fill_schema() |
|
254 |
RepositoryBasedTC.setUp(self) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
255 |
|
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
256 |
def index_exists(self, etype, attr, unique=False): |
1787 | 257 |
dbhelper = self.session.pool.source('system').dbhelper |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
258 |
sqlcursor = self.session.pool['system'] |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
259 |
return dbhelper.index_exists(sqlcursor, SQL_PREFIX + etype, SQL_PREFIX + attr, unique=unique) |
1787 | 260 |
|
0 | 261 |
def test_base(self): |
262 |
schema = self.repo.schema |
|
1787 | 263 |
dbhelper = self.session.pool.source('system').dbhelper |
0 | 264 |
sqlcursor = self.session.pool['system'] |
265 |
self.failIf(schema.has_entity('Societe2')) |
|
266 |
self.failIf(schema.has_entity('concerne2')) |
|
267 |
# schema should be update on insertion (after commit) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
268 |
self.execute('INSERT CWEType X: X name "Societe2", X description "", X meta FALSE, X final FALSE') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
269 |
self.execute('INSERT CWRType X: X name "concerne2", X description "", X meta FALSE, X final FALSE, X symetric FALSE') |
0 | 270 |
self.failIf(schema.has_entity('Societe2')) |
271 |
self.failIf(schema.has_entity('concerne2')) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
272 |
self.execute('SET X read_permission G WHERE X is CWEType, X name "Societe2", G is CWGroup') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
273 |
self.execute('SET X read_permission G WHERE X is CWRType, X name "concerne2", G is CWGroup') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
274 |
self.execute('SET X add_permission G WHERE X is CWEType, X name "Societe2", G is CWGroup, G name "managers"') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
275 |
self.execute('SET X add_permission G WHERE X is CWRType, X name "concerne2", G is CWGroup, G name "managers"') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
276 |
self.execute('SET X delete_permission G WHERE X is CWEType, X name "Societe2", G is CWGroup, G name "owners"') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
277 |
self.execute('SET X delete_permission G WHERE X is CWRType, X name "concerne2", G is CWGroup, G name "owners"') |
0 | 278 |
# have to commit before adding definition relations |
279 |
self.commit() |
|
280 |
self.failUnless(schema.has_entity('Societe2')) |
|
281 |
self.failUnless(schema.has_relation('concerne2')) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
282 |
self.execute('INSERT CWAttribute X: X cardinality "11", X defaultval "noname", X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F ' |
0 | 283 |
'WHERE RT name "nom", E name "Societe2", F name "String"') |
284 |
concerne2_rdef_eid = self.execute( |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
285 |
'INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E ' |
0 | 286 |
'WHERE RT name "concerne2", E name "Societe2"')[0][0] |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
287 |
self.execute('INSERT CWRelation X: X cardinality "?*", X relation_type RT, X from_entity E, X to_entity C ' |
0 | 288 |
'WHERE RT name "comments", E name "Societe2", C name "Comment"') |
289 |
self.failIf('nom' in schema['Societe2'].subject_relations()) |
|
290 |
self.failIf('concerne2' in schema['Societe2'].subject_relations()) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
291 |
self.failIf(self.index_exists('Societe2', 'nom')) |
0 | 292 |
self.commit() |
293 |
self.failUnless('nom' in schema['Societe2'].subject_relations()) |
|
294 |
self.failUnless('concerne2' in schema['Societe2'].subject_relations()) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
295 |
self.failUnless(self.index_exists('Societe2', 'nom')) |
0 | 296 |
# now we should be able to insert and query Societe2 |
297 |
s2eid = self.execute('INSERT Societe2 X: X nom "logilab"')[0][0] |
|
298 |
self.execute('Societe2 X WHERE X nom "logilab"') |
|
299 |
self.execute('SET X concerne2 X WHERE X nom "logilab"') |
|
300 |
rset = self.execute('Any X WHERE X concerne2 Y') |
|
301 |
self.assertEquals(rset.rows, [[s2eid]]) |
|
302 |
# check that when a relation definition is deleted, existing relations are deleted |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
303 |
self.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E ' |
0 | 304 |
'WHERE RT name "concerne2", E name "Societe"') |
305 |
self.commit() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
306 |
self.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid}, 'x') |
0 | 307 |
self.commit() |
308 |
self.failUnless('concerne2' in schema['Societe'].subject_relations()) |
|
309 |
self.failIf('concerne2' in schema['Societe2'].subject_relations()) |
|
310 |
self.failIf(self.execute('Any X WHERE X concerne2 Y')) |
|
311 |
# schema should be cleaned on delete (after commit) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
312 |
self.execute('DELETE CWEType X WHERE X name "Societe2"') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
313 |
self.execute('DELETE CWRType X WHERE X name "concerne2"') |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
314 |
self.failUnless(self.index_exists('Societe2', 'nom')) |
0 | 315 |
self.failUnless(schema.has_entity('Societe2')) |
316 |
self.failUnless(schema.has_relation('concerne2')) |
|
317 |
self.commit() |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
318 |
self.failIf(self.index_exists('Societe2', 'nom')) |
0 | 319 |
self.failIf(schema.has_entity('Societe2')) |
320 |
self.failIf(schema.has_entity('concerne2')) |
|
321 |
||
322 |
def test_is_instance_of_insertions(self): |
|
323 |
seid = self.execute('INSERT SubDivision S: S nom "subdiv"')[0][0] |
|
324 |
is_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is ET, ET name ETN' % seid)] |
|
325 |
self.assertEquals(is_etypes, ['SubDivision']) |
|
326 |
instanceof_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is_instance_of ET, ET name ETN' % seid)] |
|
327 |
self.assertEquals(sorted(instanceof_etypes), ['Division', 'Societe', 'SubDivision']) |
|
328 |
snames = [name for name, in self.execute('Any N WHERE S is Societe, S nom N')] |
|
329 |
self.failIf('subdiv' in snames) |
|
330 |
snames = [name for name, in self.execute('Any N WHERE S is Division, S nom N')] |
|
331 |
self.failIf('subdiv' in snames) |
|
332 |
snames = [name for name, in self.execute('Any N WHERE S is_instance_of Societe, S nom N')] |
|
333 |
self.failUnless('subdiv' in snames) |
|
334 |
snames = [name for name, in self.execute('Any N WHERE S is_instance_of Division, S nom N')] |
|
335 |
self.failUnless('subdiv' in snames) |
|
1787 | 336 |
|
337 |
||
0 | 338 |
def test_perms_synchronization_1(self): |
339 |
schema = self.repo.schema |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
340 |
self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users'))) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
341 |
self.failUnless(self.execute('Any X, Y WHERE X is CWEType, X name "CWUser", Y is CWGroup, Y name "users"')[0]) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
342 |
self.execute('DELETE X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
343 |
self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users', ))) |
0 | 344 |
self.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
345 |
self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', ))) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
346 |
self.execute('SET X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"') |
0 | 347 |
self.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
348 |
self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users',))) |
0 | 349 |
|
350 |
def test_perms_synchronization_2(self): |
|
351 |
schema = self.repo.schema['in_group'] |
|
352 |
self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests'))) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
353 |
self.execute('DELETE X read_permission Y WHERE X is CWRType, X name "in_group", Y name "guests"') |
0 | 354 |
self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests'))) |
355 |
self.commit() |
|
356 |
self.assertEquals(schema.get_groups('read'), set(('managers', 'users'))) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
357 |
self.execute('SET X read_permission Y WHERE X is CWRType, X name "in_group", Y name "guests"') |
0 | 358 |
self.assertEquals(schema.get_groups('read'), set(('managers', 'users'))) |
359 |
self.commit() |
|
360 |
self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests'))) |
|
361 |
||
362 |
def test_nonregr_user_edit_itself(self): |
|
363 |
ueid = self.session.user.eid |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
364 |
groupeids = [eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')] |
0 | 365 |
self.execute('DELETE X in_group Y WHERE X eid %s' % ueid) |
366 |
self.execute('SET X surname "toto" WHERE X eid %s' % ueid) |
|
367 |
self.execute('SET X in_group Y WHERE X eid %s, Y name "managers"' % ueid) |
|
368 |
self.commit() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
369 |
eeid = self.execute('Any X WHERE X is CWEType, X name "CWEType"')[0][0] |
0 | 370 |
self.execute('DELETE X read_permission Y WHERE X eid %s' % eeid) |
371 |
self.execute('SET X final FALSE WHERE X eid %s' % eeid) |
|
372 |
self.execute('SET X read_permission Y WHERE X eid %s, Y eid in (%s, %s)' |
|
373 |
% (eeid, groupeids[0], groupeids[1])) |
|
374 |
self.commit() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
375 |
self.execute('Any X WHERE X is CWEType, X name "CWEType"') |
0 | 376 |
|
377 |
# schema modification hooks tests ######################################### |
|
1787 | 378 |
|
0 | 379 |
def test_uninline_relation(self): |
1787 | 380 |
dbhelper = self.session.pool.source('system').dbhelper |
0 | 381 |
sqlcursor = self.session.pool['system'] |
382 |
# Personne inline2 Affaire inline |
|
383 |
# insert a person without inline2 relation (not mandatory) |
|
384 |
self.execute('INSERT Personne X: X nom "toto"') |
|
385 |
peid = self.execute('INSERT Personne X: X nom "tutu"')[0][0] |
|
386 |
aeid = self.execute('INSERT Affaire X: X ref "tata"')[0][0] |
|
387 |
self.execute('SET X inline2 Y WHERE X eid %(x)s, Y eid %(y)s', {'x': peid, 'y': aeid}) |
|
388 |
self.failUnless(self.schema['inline2'].inlined) |
|
389 |
try: |
|
390 |
try: |
|
391 |
self.execute('SET X inlined FALSE WHERE X name "inline2"') |
|
392 |
self.failUnless(self.schema['inline2'].inlined) |
|
393 |
self.commit() |
|
394 |
self.failIf(self.schema['inline2'].inlined) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
395 |
self.failIf(self.index_exists('Personne', 'inline2')) |
0 | 396 |
rset = self.execute('Any X, Y WHERE X inline2 Y') |
397 |
self.assertEquals(len(rset), 1) |
|
398 |
self.assertEquals(rset.rows[0], [peid, aeid]) |
|
399 |
except: |
|
400 |
import traceback |
|
401 |
traceback.print_exc() |
|
402 |
raise |
|
403 |
finally: |
|
404 |
self.execute('SET X inlined TRUE WHERE X name "inline2"') |
|
405 |
self.failIf(self.schema['inline2'].inlined) |
|
406 |
self.commit() |
|
407 |
self.failUnless(self.schema['inline2'].inlined) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
408 |
self.failUnless(self.index_exists('Personne', 'inline2')) |
0 | 409 |
rset = self.execute('Any X, Y WHERE X inline2 Y') |
410 |
self.assertEquals(len(rset), 1) |
|
411 |
self.assertEquals(rset.rows[0], [peid, aeid]) |
|
412 |
||
413 |
def test_indexed_change(self): |
|
1787 | 414 |
dbhelper = self.session.pool.source('system').dbhelper |
0 | 415 |
sqlcursor = self.session.pool['system'] |
416 |
try: |
|
417 |
self.execute('SET X indexed TRUE WHERE X relation_type R, R name "sujet"') |
|
418 |
self.failIf(self.schema['sujet'].rproperty('Affaire', 'String', 'indexed')) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
419 |
self.failIf(self.index_exists('Affaire', 'sujet')) |
0 | 420 |
self.commit() |
421 |
self.failUnless(self.schema['sujet'].rproperty('Affaire', 'String', 'indexed')) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
422 |
self.failUnless(self.index_exists('Affaire', 'sujet')) |
0 | 423 |
finally: |
424 |
self.execute('SET X indexed FALSE WHERE X relation_type R, R name "sujet"') |
|
425 |
self.failUnless(self.schema['sujet'].rproperty('Affaire', 'String', 'indexed')) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
426 |
self.failUnless(self.index_exists('Affaire', 'sujet')) |
0 | 427 |
self.commit() |
428 |
self.failIf(self.schema['sujet'].rproperty('Affaire', 'String', 'indexed')) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
429 |
self.failIf(self.index_exists('Affaire', 'sujet')) |
0 | 430 |
|
431 |
def test_unique_change(self): |
|
1787 | 432 |
dbhelper = self.session.pool.source('system').dbhelper |
0 | 433 |
sqlcursor = self.session.pool['system'] |
434 |
try: |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
435 |
try: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
436 |
self.execute('INSERT CWConstraint X: X cstrtype CT, DEF constrained_by X ' |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
437 |
'WHERE CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,' |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
438 |
'RT name "sujet", E name "Affaire"') |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
439 |
self.failIf(self.schema['Affaire'].has_unique_values('sujet')) |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
440 |
self.failIf(self.index_exists('Affaire', 'sujet', unique=True)) |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
441 |
self.commit() |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
442 |
self.failUnless(self.schema['Affaire'].has_unique_values('sujet')) |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
443 |
self.failUnless(self.index_exists('Affaire', 'sujet', unique=True)) |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
444 |
except: |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
445 |
import traceback |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
446 |
traceback.print_exc() |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
447 |
raise |
0 | 448 |
finally: |
449 |
self.execute('DELETE DEF constrained_by X WHERE X cstrtype CT, ' |
|
450 |
'CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,' |
|
451 |
'RT name "sujet", E name "Affaire"') |
|
452 |
self.failUnless(self.schema['Affaire'].has_unique_values('sujet')) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
453 |
self.failUnless(self.index_exists('Affaire', 'sujet', unique=True)) |
0 | 454 |
self.commit() |
455 |
self.failIf(self.schema['Affaire'].has_unique_values('sujet')) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
456 |
self.failIf(self.index_exists('Affaire', 'sujet', unique=True)) |
1787 | 457 |
|
1981
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
458 |
def test_required_change_1(self): |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
459 |
self.execute('SET DEF cardinality "?1" ' |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
460 |
'WHERE DEF relation_type RT, DEF from_entity E,' |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
461 |
'RT name "nom", E name "Personne"') |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
462 |
self.commit() |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
463 |
# should now be able to add personne without nom |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
464 |
self.execute('INSERT Personne X') |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
465 |
self.commit() |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
466 |
|
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
467 |
def test_required_change_2(self): |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
468 |
self.execute('SET DEF cardinality "11" ' |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
469 |
'WHERE DEF relation_type RT, DEF from_entity E,' |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
470 |
'RT name "prenom", E name "Personne"') |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
471 |
self.commit() |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
472 |
# should not be able anymore to add personne without prenom |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
473 |
self.assertRaises(ValidationError, self.execute, 'INSERT Personne X: X nom "toto"') |
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1990
diff
changeset
|
474 |
self.execute('SET DEF cardinality "?1" ' |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1990
diff
changeset
|
475 |
'WHERE DEF relation_type RT, DEF from_entity E,' |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1990
diff
changeset
|
476 |
'RT name "prenom", E name "Personne"') |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1990
diff
changeset
|
477 |
self.commit() |
1981
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
478 |
|
0 | 479 |
|
480 |
class WorkflowHooksTC(RepositoryBasedTC): |
|
481 |
||
482 |
def setUp(self): |
|
483 |
RepositoryBasedTC.setUp(self) |
|
484 |
self.s_activated = self.execute('State X WHERE X name "activated"')[0][0] |
|
485 |
self.s_deactivated = self.execute('State X WHERE X name "deactivated"')[0][0] |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
486 |
self.s_dummy = self.execute('INSERT State X: X name "dummy", X state_of E WHERE E name "CWUser"')[0][0] |
0 | 487 |
self.create_user('stduser') |
488 |
# give access to users group on the user's wf transitions |
|
489 |
# so we can test wf enforcing on euser (managers don't have anymore this |
|
490 |
# enforcement |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
491 |
self.execute('SET X require_group G WHERE G name "users", X transition_of ET, ET name "CWUser"') |
0 | 492 |
self.commit() |
1787 | 493 |
|
0 | 494 |
def tearDown(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
495 |
self.execute('DELETE X require_group G WHERE G name "users", X transition_of ET, ET name "CWUser"') |
0 | 496 |
self.commit() |
497 |
RepositoryBasedTC.tearDown(self) |
|
498 |
||
499 |
def test_set_initial_state(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
500 |
ueid = self.execute('INSERT CWUser E: E login "x", E upassword "x", E in_group G ' |
0 | 501 |
'WHERE G name "users"')[0][0] |
502 |
self.failIf(self.execute('Any N WHERE S name N, X in_state S, X eid %(x)s', |
|
503 |
{'x' : ueid})) |
|
504 |
self.commit() |
|
505 |
initialstate = self.execute('Any N WHERE S name N, X in_state S, X eid %(x)s', |
|
506 |
{'x' : ueid})[0][0] |
|
507 |
self.assertEquals(initialstate, u'activated') |
|
1787 | 508 |
|
0 | 509 |
def test_initial_state(self): |
510 |
cnx = self.login('stduser') |
|
511 |
cu = cnx.cursor() |
|
512 |
self.assertRaises(ValidationError, cu.execute, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
513 |
'INSERT CWUser X: X login "badaboum", X upassword %(pwd)s, ' |
0 | 514 |
'X in_state S WHERE S name "deactivated"', {'pwd': 'oops'}) |
515 |
cnx.close() |
|
516 |
# though managers can do whatever he want |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
517 |
self.execute('INSERT CWUser X: X login "badaboum", X upassword %(pwd)s, ' |
0 | 518 |
'X in_state S, X in_group G WHERE S name "deactivated", G name "users"', {'pwd': 'oops'}) |
519 |
self.commit() |
|
1787 | 520 |
|
0 | 521 |
# test that the workflow is correctly enforced |
522 |
def test_transition_checking1(self): |
|
523 |
cnx = self.login('stduser') |
|
524 |
cu = cnx.cursor() |
|
525 |
ueid = cnx.user(self.current_session()).eid |
|
526 |
self.assertRaises(ValidationError, |
|
527 |
cu.execute, 'SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
528 |
{'x': ueid, 's': self.s_activated}, 'x') |
|
529 |
cnx.close() |
|
1787 | 530 |
|
0 | 531 |
def test_transition_checking2(self): |
532 |
cnx = self.login('stduser') |
|
533 |
cu = cnx.cursor() |
|
534 |
ueid = cnx.user(self.current_session()).eid |
|
535 |
self.assertRaises(ValidationError, |
|
536 |
cu.execute, 'SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
537 |
{'x': ueid, 's': self.s_dummy}, 'x') |
|
538 |
cnx.close() |
|
1787 | 539 |
|
0 | 540 |
def test_transition_checking3(self): |
541 |
cnx = self.login('stduser') |
|
542 |
cu = cnx.cursor() |
|
543 |
ueid = cnx.user(self.current_session()).eid |
|
544 |
cu.execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
545 |
{'x': ueid, 's': self.s_deactivated}, 'x') |
|
546 |
cnx.commit() |
|
547 |
self.assertRaises(ValidationError, |
|
548 |
cu.execute, 'SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
549 |
{'x': ueid, 's': self.s_deactivated}, 'x') |
|
550 |
# get back now |
|
551 |
cu.execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
552 |
{'x': ueid, 's': self.s_activated}, 'x') |
|
553 |
cnx.commit() |
|
554 |
cnx.close() |
|
1787 | 555 |
|
0 | 556 |
def test_transition_checking4(self): |
557 |
cnx = self.login('stduser') |
|
558 |
cu = cnx.cursor() |
|
559 |
ueid = cnx.user(self.current_session()).eid |
|
560 |
cu.execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
561 |
{'x': ueid, 's': self.s_deactivated}, 'x') |
|
562 |
cnx.commit() |
|
563 |
self.assertRaises(ValidationError, |
|
564 |
cu.execute, 'SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
565 |
{'x': ueid, 's': self.s_dummy}, 'x') |
|
566 |
# get back now |
|
567 |
cu.execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
568 |
{'x': ueid, 's': self.s_activated}, 'x') |
|
569 |
cnx.commit() |
|
570 |
cnx.close() |
|
571 |
||
572 |
def test_transition_information(self): |
|
573 |
ueid = self.session.user.eid |
|
574 |
self.execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
575 |
{'x': ueid, 's': self.s_deactivated}, 'x') |
|
576 |
self.commit() |
|
577 |
rset = self.execute('TrInfo T ORDERBY T WHERE T wf_info_for X, X eid %(x)s', {'x': ueid}) |
|
578 |
self.assertEquals(len(rset), 2) |
|
579 |
tr = rset.get_entity(1, 0) |
|
580 |
#tr.complete() |
|
581 |
self.assertEquals(tr.comment, None) |
|
582 |
self.assertEquals(tr.from_state[0].eid, self.s_activated) |
|
583 |
self.assertEquals(tr.to_state[0].eid, self.s_deactivated) |
|
1787 | 584 |
|
0 | 585 |
self.session.set_shared_data('trcomment', u'il est pas sage celui-la') |
586 |
self.session.set_shared_data('trcommentformat', u'text/plain') |
|
587 |
self.execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
|
588 |
{'x': ueid, 's': self.s_activated}, 'x') |
|
589 |
self.commit() |
|
590 |
rset = self.execute('TrInfo T ORDERBY T WHERE T wf_info_for X, X eid %(x)s', {'x': ueid}) |
|
591 |
self.assertEquals(len(rset), 3) |
|
592 |
tr = rset.get_entity(2, 0) |
|
593 |
#tr.complete() |
|
594 |
self.assertEquals(tr.comment, u'il est pas sage celui-la') |
|
595 |
self.assertEquals(tr.comment_format, u'text/plain') |
|
596 |
self.assertEquals(tr.from_state[0].eid, self.s_deactivated) |
|
597 |
self.assertEquals(tr.to_state[0].eid, self.s_activated) |
|
598 |
self.assertEquals(tr.owned_by[0].login, 'admin') |
|
599 |
||
600 |
def test_transition_information_on_creation(self): |
|
601 |
ueid = self.create_user('toto') |
|
602 |
rset = self.execute('TrInfo T WHERE T wf_info_for X, X eid %(x)s', {'x': ueid}) |
|
603 |
self.assertEquals(len(rset), 1) |
|
604 |
tr = rset.get_entity(0, 0) |
|
605 |
#tr.complete() |
|
606 |
self.assertEquals(tr.comment, None) |
|
607 |
self.assertEquals(tr.from_state, []) |
|
608 |
self.assertEquals(tr.to_state[0].eid, self.s_activated) |
|
609 |
||
610 |
def test_std_users_can_create_trinfo(self): |
|
611 |
self.create_user('toto') |
|
612 |
cnx = self.login('toto') |
|
613 |
cu = cnx.cursor() |
|
614 |
self.failUnless(cu.execute("INSERT Note X: X type 'a', X in_state S WHERE S name 'todo'")) |
|
615 |
cnx.commit() |
|
1787 | 616 |
|
0 | 617 |
if __name__ == '__main__': |
618 |
unittest_main() |