author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 16 Nov 2009 19:05:54 +0100 | |
branch | stable |
changeset 3867 | 06ac8f00a99f |
parent 3526 | dfb2ebb765e2 |
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): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
40 |
self.execute('INSERT CWUser X: X login "toto", X upassword "hop", X in_group Y ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
41 |
'WHERE Y name "users"') |
0 | 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_inlined(self): |
|
64 |
self.assertEquals(self.repo.schema['sender'].inlined, True) |
|
65 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
66 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
67 |
eeid = self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
68 |
'WHERE Y is EmailAddress, P is EmailPart')[0][0] |
|
69 |
self.execute('SET X sender Y WHERE X is Email, Y is EmailAddress') |
|
70 |
rset = self.execute('Any S WHERE X sender S, X eid %s' % eeid) |
|
71 |
self.assertEquals(len(rset), 1) |
|
1787 | 72 |
|
0 | 73 |
def test_composite_1(self): |
74 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
75 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
76 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
77 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
78 |
self.failUnless(self.execute('Email X WHERE X sender Y')) |
|
79 |
self.commit() |
|
80 |
self.execute('DELETE Email X') |
|
81 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
82 |
self.assertEquals(len(rset), 1) |
|
83 |
self.commit() |
|
84 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
85 |
self.assertEquals(len(rset), 0) |
|
1787 | 86 |
|
0 | 87 |
def test_composite_2(self): |
88 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
89 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
90 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
91 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
92 |
self.commit() |
|
93 |
self.execute('DELETE Email X') |
|
94 |
self.execute('DELETE EmailPart X') |
|
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_redirection(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.execute('INSERT Email X: X messageid "<2345>", X subject "test2", X sender Y, X recipients Y ' |
|
105 |
'WHERE Y is EmailAddress') |
|
106 |
self.commit() |
|
107 |
self.execute('DELETE X parts Y WHERE X messageid "<1234>"') |
|
108 |
self.execute('SET X parts Y WHERE X messageid "<2345>"') |
|
109 |
self.commit() |
|
110 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
111 |
self.assertEquals(len(rset), 1) |
|
112 |
self.assertEquals(rset.get_entity(0, 0).reverse_parts[0].messageid, '<2345>') |
|
113 |
||
114 |
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
|
115 |
self.execute('INSERT CWRelation X: X from_entity FE, X relation_type RT, X to_entity TE ' |
0 | 116 |
'WHERE FE name "Affaire", RT name "concerne", TE name "String"') |
117 |
self.assertRaises(ValidationError, |
|
118 |
self.commit) |
|
119 |
||
120 |
||
121 |
def test_html_tidy_hook(self): |
|
122 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "yo"').get_entity(0, 0) |
|
123 |
self.assertEquals(entity.descr, u'yo') |
|
124 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "<b>yo"').get_entity(0, 0) |
|
125 |
self.assertEquals(entity.descr, u'<b>yo</b>') |
|
126 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "<b>yo</b>"').get_entity(0, 0) |
|
127 |
self.assertEquals(entity.descr, u'<b>yo</b>') |
|
128 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "<b>R&D</b>"').get_entity(0, 0) |
|
129 |
self.assertEquals(entity.descr, u'<b>R&D</b>') |
|
130 |
xml = u"<div>c'est <b>l'été" |
|
131 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr %(d)s', |
|
132 |
{'d': xml}).get_entity(0, 0) |
|
133 |
self.assertEquals(entity.descr, u"<div>c'est <b>l'été</b></div>") |
|
134 |
||
135 |
def test_nonregr_html_tidy_hook_no_update(self): |
|
136 |
entity = self.execute('INSERT Affaire A: A descr_format "text/html", A descr "yo"').get_entity(0, 0) |
|
137 |
self.assertEquals(entity.descr, u'yo') |
|
138 |
self.execute('SET A ref "REF" WHERE A eid %s' % entity.eid) |
|
139 |
entity = self.execute('Any A WHERE A eid %s' % entity.eid).get_entity(0, 0) |
|
140 |
self.assertEquals(entity.descr, u'yo') |
|
141 |
self.execute('SET A descr "R&D<p>yo" WHERE A eid %s' % entity.eid) |
|
142 |
entity = self.execute('Any A WHERE A eid %s' % entity.eid).get_entity(0, 0) |
|
143 |
self.assertEquals(entity.descr, u'R&D<p>yo</p>') |
|
1787 | 144 |
|
145 |
||
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
146 |
def test_metadata_cwuri(self): |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
147 |
eid = self.execute('INSERT Note X')[0][0] |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
148 |
cwuri = self.execute('Any U WHERE X eid %s, X cwuri U' % eid)[0][0] |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
149 |
self.assertEquals(cwuri, self.repo.config['base-url'] + 'eid/%s' % eid) |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
150 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
151 |
def test_metadata_creation_modification_date(self): |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
152 |
_now = datetime.now() |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
153 |
eid = self.execute('INSERT Note X')[0][0] |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
154 |
creation_date, modification_date = self.execute('Any CD, MD WHERE X eid %s, ' |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
155 |
'X creation_date CD, ' |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
156 |
'X modification_date MD' % eid)[0] |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
157 |
self.assertEquals((creation_date - _now).seconds, 0) |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
158 |
self.assertEquals((modification_date - _now).seconds, 0) |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
159 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
160 |
def test_metadata__date(self): |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
161 |
_now = datetime.now() |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
162 |
eid = self.execute('INSERT Note X')[0][0] |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
163 |
creation_date = self.execute('Any D WHERE X eid %s, X creation_date D' % eid)[0][0] |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
164 |
self.assertEquals((creation_date - _now).seconds, 0) |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
165 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
166 |
def test_metadata_created_by(self): |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
167 |
eid = self.execute('INSERT Note X')[0][0] |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
168 |
self.commit() # fire operations |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
169 |
rset = self.execute('Any U WHERE X eid %s, X created_by U' % eid) |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
170 |
self.assertEquals(len(rset), 1) # make sure we have only one creator |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
171 |
self.assertEquals(rset[0][0], self.session.user.eid) |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
172 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
173 |
def test_metadata_owned_by(self): |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
174 |
eid = self.execute('INSERT Note X')[0][0] |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
175 |
self.commit() # fire operations |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
176 |
rset = self.execute('Any U WHERE X eid %s, X owned_by U' % eid) |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
177 |
self.assertEquals(len(rset), 1) # make sure we have only one owner |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
178 |
self.assertEquals(rset[0][0], self.session.user.eid) |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
179 |
|
0 | 180 |
|
181 |
class UserGroupHooksTC(RepositoryBasedTC): |
|
1787 | 182 |
|
0 | 183 |
def test_user_synchronization(self): |
184 |
self.create_user('toto', password='hop', commit=False) |
|
185 |
self.assertRaises(AuthenticationError, |
|
186 |
self.repo.connect, u'toto', 'hop') |
|
187 |
self.commit() |
|
188 |
cnxid = self.repo.connect(u'toto', 'hop') |
|
189 |
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
|
190 |
self.execute('DELETE CWUser X WHERE X login "toto"') |
0 | 191 |
self.repo.execute(cnxid, 'State X') |
192 |
self.commit() |
|
193 |
self.assertRaises(BadConnectionId, |
|
194 |
self.repo.execute, cnxid, 'State X') |
|
195 |
||
196 |
def test_user_group_synchronization(self): |
|
197 |
user = self.session.user |
|
198 |
self.assertEquals(user.groups, set(('managers',))) |
|
199 |
self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
200 |
self.assertEquals(user.groups, set(('managers',))) |
|
201 |
self.commit() |
|
202 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
203 |
self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
204 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
205 |
self.commit() |
|
206 |
self.assertEquals(user.groups, set(('managers',))) |
|
207 |
||
208 |
def test_user_composite_owner(self): |
|
209 |
ueid = self.create_user('toto') |
|
210 |
# composite of euser should be owned by the euser regardless of who created it |
|
211 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X ' |
|
212 |
'WHERE U login "toto"') |
|
213 |
self.commit() |
|
214 |
self.assertEquals(self.execute('Any A WHERE X owned_by U, U use_email X,' |
|
215 |
'U login "toto", X address A')[0][0], |
|
216 |
'toto@logilab.fr') |
|
217 |
||
218 |
def test_no_created_by_on_deleted_entity(self): |
|
219 |
eid = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0] |
|
220 |
self.execute('DELETE EmailAddress X WHERE X eid %s' % eid) |
|
221 |
self.commit() |
|
222 |
self.failIf(self.execute('Any X WHERE X created_by Y, X eid >= %(x)s', {'x': eid})) |
|
1787 | 223 |
|
2746 | 224 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
225 |
class CWPropertyHooksTC(RepositoryBasedTC): |
1787 | 226 |
|
0 | 227 |
def test_unexistant_eproperty(self): |
228 |
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
|
229 |
self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U') |
0 | 230 |
self.assertEquals(ex.errors, {'pkey': 'unknown property key'}) |
231 |
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
|
232 |
self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop"') |
0 | 233 |
self.assertEquals(ex.errors, {'pkey': 'unknown property key'}) |
1787 | 234 |
|
0 | 235 |
def test_site_wide_eproperty(self): |
236 |
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
|
237 |
self.execute, 'INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U') |
0 | 238 |
self.assertEquals(ex.errors, {'for_user': "site-wide property can't be set for user"}) |
1787 | 239 |
|
0 | 240 |
def test_bad_type_eproperty(self): |
241 |
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
|
242 |
self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U') |
0 | 243 |
self.assertEquals(ex.errors, {'value': u'unauthorized value'}) |
244 |
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
|
245 |
self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop"') |
0 | 246 |
self.assertEquals(ex.errors, {'value': u'unauthorized value'}) |
1787 | 247 |
|
248 |
||
0 | 249 |
class SchemaHooksTC(RepositoryBasedTC): |
1787 | 250 |
|
0 | 251 |
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
|
252 |
# check we can't add a CWEType or CWRType entity if it already exists one |
0 | 253 |
# with the same name |
254 |
# |
|
255 |
# according to hook order, we'll get a repository or validation error |
|
256 |
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
|
257 |
self.execute, 'INSERT CWEType X: X name "Societe"') |
0 | 258 |
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
|
259 |
self.execute, 'INSERT CWRType X: X name "in_group"') |
1787 | 260 |
|
0 | 261 |
def test_validation_unique_constraint(self): |
262 |
self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
263 |
self.execute, 'INSERT CWUser X: X login "admin"') |
0 | 264 |
try: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
265 |
self.execute('INSERT CWUser X: X login "admin"') |
0 | 266 |
except ValidationError, ex: |
267 |
self.assertIsInstance(ex.entity, int) |
|
268 |
self.assertEquals(ex.errors, {'login': 'the value "admin" is already used, use another one'}) |
|
269 |
||
270 |
||
271 |
class SchemaModificationHooksTC(RepositoryBasedTC): |
|
272 |
||
273 |
def setUp(self): |
|
274 |
if not hasattr(self, '_repo'): |
|
275 |
# first initialization |
|
276 |
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
|
277 |
# force to read schema from the database to get proper eid set on schema instances |
0 | 278 |
repo.config._cubes = None |
279 |
repo.fill_schema() |
|
280 |
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
|
281 |
|
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
|
282 |
def index_exists(self, etype, attr, unique=False): |
1787 | 283 |
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
|
284 |
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
|
285 |
return dbhelper.index_exists(sqlcursor, SQL_PREFIX + etype, SQL_PREFIX + attr, unique=unique) |
1787 | 286 |
|
0 | 287 |
def test_base(self): |
288 |
schema = self.repo.schema |
|
1787 | 289 |
dbhelper = self.session.pool.source('system').dbhelper |
0 | 290 |
sqlcursor = self.session.pool['system'] |
291 |
self.failIf(schema.has_entity('Societe2')) |
|
292 |
self.failIf(schema.has_entity('concerne2')) |
|
293 |
# 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
|
294 |
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
|
295 |
self.execute('INSERT CWRType X: X name "concerne2", X description "", X final FALSE, X symetric FALSE') |
0 | 296 |
self.failIf(schema.has_entity('Societe2')) |
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
self.execute('SET X delete_permission G WHERE X is CWRType, X name "concerne2", G is CWGroup, G name "owners"') |
0 | 304 |
# have to commit before adding definition relations |
305 |
self.commit() |
|
306 |
self.failUnless(schema.has_entity('Societe2')) |
|
307 |
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
|
308 |
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 | 309 |
'WHERE RT name "nom", E name "Societe2", F name "String"') |
310 |
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
|
311 |
'INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E ' |
0 | 312 |
'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
|
313 |
self.execute('INSERT CWRelation X: X cardinality "?*", X relation_type RT, X from_entity E, X to_entity C ' |
0 | 314 |
'WHERE RT name "comments", E name "Societe2", C name "Comment"') |
315 |
self.failIf('nom' in schema['Societe2'].subject_relations()) |
|
316 |
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
|
317 |
self.failIf(self.index_exists('Societe2', 'nom')) |
0 | 318 |
self.commit() |
319 |
self.failUnless('nom' in schema['Societe2'].subject_relations()) |
|
320 |
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
|
321 |
self.failUnless(self.index_exists('Societe2', 'nom')) |
0 | 322 |
# now we should be able to insert and query Societe2 |
323 |
s2eid = self.execute('INSERT Societe2 X: X nom "logilab"')[0][0] |
|
324 |
self.execute('Societe2 X WHERE X nom "logilab"') |
|
325 |
self.execute('SET X concerne2 X WHERE X nom "logilab"') |
|
326 |
rset = self.execute('Any X WHERE X concerne2 Y') |
|
327 |
self.assertEquals(rset.rows, [[s2eid]]) |
|
328 |
# 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
|
329 |
self.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E ' |
0 | 330 |
'WHERE RT name "concerne2", E name "Societe"') |
331 |
self.commit() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
332 |
self.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid}, 'x') |
0 | 333 |
self.commit() |
334 |
self.failUnless('concerne2' in schema['Societe'].subject_relations()) |
|
335 |
self.failIf('concerne2' in schema['Societe2'].subject_relations()) |
|
336 |
self.failIf(self.execute('Any X WHERE X concerne2 Y')) |
|
337 |
# 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
|
338 |
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
|
339 |
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
|
340 |
self.failUnless(self.index_exists('Societe2', 'nom')) |
0 | 341 |
self.failUnless(schema.has_entity('Societe2')) |
342 |
self.failUnless(schema.has_relation('concerne2')) |
|
343 |
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
|
344 |
self.failIf(self.index_exists('Societe2', 'nom')) |
0 | 345 |
self.failIf(schema.has_entity('Societe2')) |
346 |
self.failIf(schema.has_entity('concerne2')) |
|
347 |
||
348 |
def test_is_instance_of_insertions(self): |
|
349 |
seid = self.execute('INSERT SubDivision S: S nom "subdiv"')[0][0] |
|
350 |
is_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is ET, ET name ETN' % seid)] |
|
351 |
self.assertEquals(is_etypes, ['SubDivision']) |
|
352 |
instanceof_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is_instance_of ET, ET name ETN' % seid)] |
|
353 |
self.assertEquals(sorted(instanceof_etypes), ['Division', 'Societe', 'SubDivision']) |
|
354 |
snames = [name for name, in self.execute('Any N WHERE S is Societe, S nom N')] |
|
355 |
self.failIf('subdiv' in snames) |
|
356 |
snames = [name for name, in self.execute('Any N WHERE S is Division, S nom N')] |
|
357 |
self.failIf('subdiv' in snames) |
|
358 |
snames = [name for name, in self.execute('Any N WHERE S is_instance_of Societe, S nom N')] |
|
359 |
self.failUnless('subdiv' in snames) |
|
360 |
snames = [name for name, in self.execute('Any N WHERE S is_instance_of Division, S nom N')] |
|
361 |
self.failUnless('subdiv' in snames) |
|
1787 | 362 |
|
363 |
||
0 | 364 |
def test_perms_synchronization_1(self): |
365 |
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
|
366 |
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
|
367 |
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
|
368 |
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
|
369 |
self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users', ))) |
0 | 370 |
self.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
371 |
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
|
372 |
self.execute('SET X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"') |
0 | 373 |
self.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
374 |
self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users',))) |
0 | 375 |
|
376 |
def test_perms_synchronization_2(self): |
|
377 |
schema = self.repo.schema['in_group'] |
|
378 |
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
|
379 |
self.execute('DELETE X read_permission Y WHERE X is CWRType, X name "in_group", Y name "guests"') |
0 | 380 |
self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests'))) |
381 |
self.commit() |
|
382 |
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
|
383 |
self.execute('SET X read_permission Y WHERE X is CWRType, X name "in_group", Y name "guests"') |
0 | 384 |
self.assertEquals(schema.get_groups('read'), set(('managers', 'users'))) |
385 |
self.commit() |
|
386 |
self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests'))) |
|
387 |
||
388 |
def test_nonregr_user_edit_itself(self): |
|
389 |
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
|
390 |
groupeids = [eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')] |
0 | 391 |
self.execute('DELETE X in_group Y WHERE X eid %s' % ueid) |
392 |
self.execute('SET X surname "toto" WHERE X eid %s' % ueid) |
|
393 |
self.execute('SET X in_group Y WHERE X eid %s, Y name "managers"' % ueid) |
|
394 |
self.commit() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
395 |
eeid = self.execute('Any X WHERE X is CWEType, X name "CWEType"')[0][0] |
0 | 396 |
self.execute('DELETE X read_permission Y WHERE X eid %s' % eeid) |
397 |
self.execute('SET X final FALSE WHERE X eid %s' % eeid) |
|
398 |
self.execute('SET X read_permission Y WHERE X eid %s, Y eid in (%s, %s)' |
|
399 |
% (eeid, groupeids[0], groupeids[1])) |
|
400 |
self.commit() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
401 |
self.execute('Any X WHERE X is CWEType, X name "CWEType"') |
0 | 402 |
|
403 |
# schema modification hooks tests ######################################### |
|
1787 | 404 |
|
0 | 405 |
def test_uninline_relation(self): |
1787 | 406 |
dbhelper = self.session.pool.source('system').dbhelper |
0 | 407 |
sqlcursor = self.session.pool['system'] |
408 |
# Personne inline2 Affaire inline |
|
409 |
# insert a person without inline2 relation (not mandatory) |
|
410 |
self.execute('INSERT Personne X: X nom "toto"') |
|
411 |
peid = self.execute('INSERT Personne X: X nom "tutu"')[0][0] |
|
412 |
aeid = self.execute('INSERT Affaire X: X ref "tata"')[0][0] |
|
413 |
self.execute('SET X inline2 Y WHERE X eid %(x)s, Y eid %(y)s', {'x': peid, 'y': aeid}) |
|
414 |
self.failUnless(self.schema['inline2'].inlined) |
|
415 |
try: |
|
416 |
try: |
|
417 |
self.execute('SET X inlined FALSE WHERE X name "inline2"') |
|
418 |
self.failUnless(self.schema['inline2'].inlined) |
|
419 |
self.commit() |
|
420 |
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
|
421 |
self.failIf(self.index_exists('Personne', 'inline2')) |
0 | 422 |
rset = self.execute('Any X, Y WHERE X inline2 Y') |
423 |
self.assertEquals(len(rset), 1) |
|
424 |
self.assertEquals(rset.rows[0], [peid, aeid]) |
|
425 |
except: |
|
426 |
import traceback |
|
427 |
traceback.print_exc() |
|
428 |
raise |
|
429 |
finally: |
|
430 |
self.execute('SET X inlined TRUE WHERE X name "inline2"') |
|
431 |
self.failIf(self.schema['inline2'].inlined) |
|
432 |
self.commit() |
|
433 |
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
|
434 |
self.failUnless(self.index_exists('Personne', 'inline2')) |
0 | 435 |
rset = self.execute('Any X, Y WHERE X inline2 Y') |
436 |
self.assertEquals(len(rset), 1) |
|
437 |
self.assertEquals(rset.rows[0], [peid, aeid]) |
|
438 |
||
439 |
def test_indexed_change(self): |
|
1787 | 440 |
dbhelper = self.session.pool.source('system').dbhelper |
0 | 441 |
sqlcursor = self.session.pool['system'] |
442 |
try: |
|
443 |
self.execute('SET X indexed TRUE WHERE X relation_type R, R name "sujet"') |
|
444 |
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
|
445 |
self.failIf(self.index_exists('Affaire', 'sujet')) |
0 | 446 |
self.commit() |
447 |
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
|
448 |
self.failUnless(self.index_exists('Affaire', 'sujet')) |
0 | 449 |
finally: |
450 |
self.execute('SET X indexed FALSE WHERE X relation_type R, R name "sujet"') |
|
451 |
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
|
452 |
self.failUnless(self.index_exists('Affaire', 'sujet')) |
0 | 453 |
self.commit() |
454 |
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
|
455 |
self.failIf(self.index_exists('Affaire', 'sujet')) |
0 | 456 |
|
457 |
def test_unique_change(self): |
|
1787 | 458 |
dbhelper = self.session.pool.source('system').dbhelper |
0 | 459 |
sqlcursor = self.session.pool['system'] |
460 |
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
|
461 |
try: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
462 |
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
|
463 |
'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
|
464 |
'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
|
465 |
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
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
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
|
472 |
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
|
473 |
raise |
0 | 474 |
finally: |
475 |
self.execute('DELETE DEF constrained_by X WHERE X cstrtype CT, ' |
|
476 |
'CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,' |
|
477 |
'RT name "sujet", E name "Affaire"') |
|
478 |
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
|
479 |
self.failUnless(self.index_exists('Affaire', 'sujet', unique=True)) |
0 | 480 |
self.commit() |
481 |
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
|
482 |
self.failIf(self.index_exists('Affaire', 'sujet', unique=True)) |
1787 | 483 |
|
1981
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
484 |
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
|
485 |
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
|
486 |
'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
|
487 |
'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
|
488 |
self.commit() |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
489 |
# 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
|
490 |
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
|
491 |
self.commit() |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
492 |
|
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
493 |
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
|
494 |
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
|
495 |
'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
|
496 |
'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
|
497 |
self.commit() |
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
498 |
# 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
|
499 |
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
|
500 |
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
|
501 |
'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
|
502 |
'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
|
503 |
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
|
504 |
|
3526
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
505 |
|
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
506 |
def test_add_attribute_to_base_class(self): |
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
507 |
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 ' |
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
508 |
'WHERE RT name "nom", E name "BaseTransition", F name "String"') |
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
509 |
self.commit() |
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
510 |
self.schema.rebuild_infered_relations() |
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
511 |
self.failUnless('Transition' in self.schema['nom'].subjects()) |
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
512 |
self.failUnless('WorkflowTransition' in self.schema['nom'].subjects()) |
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
513 |
self.execute('Any X WHERE X is_instance_of BaseTransition, X nom "hop"') |
dfb2ebb765e2
[migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2923
diff
changeset
|
514 |
|
0 | 515 |
if __name__ == '__main__': |
516 |
unittest_main() |