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