author | sylvain.thenault@logilab.fr |
Wed, 29 Apr 2009 09:03:31 +0200 | |
branch | tls-sprint |
changeset 1530 | 849fd3d64f11 |
parent 1398 | 5fe84a5f7035 |
child 1787 | 71c143c0ada3 |
permissions | -rw-r--r-- |
0 | 1 |
"""unit tests for module cubicweb.server.migractions |
2 |
""" |
|
3 |
||
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
4 |
from datetime import date |
0 | 5 |
|
6 |
from logilab.common.testlib import TestCase, unittest_main |
|
7 |
from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions |
|
8 |
||
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:
972
diff
changeset
|
9 |
from cubicweb.schema import CubicWebSchemaLoader |
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:
972
diff
changeset
|
10 |
from cubicweb.server.sqlutils import SQL_PREFIX |
0 | 11 |
from cubicweb.server.repository import Repository |
12 |
from cubicweb.server.migractions import * |
|
13 |
||
14 |
orig_get_versions = Repository.get_versions |
|
15 |
||
16 |
def setup_module(*args): |
|
17 |
Repository.get_versions = get_versions |
|
18 |
||
19 |
def teardown_module(*args): |
|
20 |
Repository.get_versions = orig_get_versions |
|
21 |
||
22 |
||
23 |
class MigrationCommandsTC(RepositoryBasedTC): |
|
24 |
copy_schema = True |
|
25 |
||
26 |
def setUp(self): |
|
27 |
if not hasattr(self, '_repo'): |
|
28 |
# first initialization |
|
29 |
repo = self.repo # set by the RepositoryBasedTC metaclass |
|
30 |
# force to read schema from the database |
|
31 |
repo.config._cubes = None |
|
32 |
repo.fill_schema() |
|
33 |
# hack to read the schema from data/migrschema |
|
34 |
CubicWebSchemaLoader.main_schema_directory = 'migrschema' |
|
35 |
global migrschema |
|
36 |
migrschema = self.repo.config.load_schema() |
|
37 |
del CubicWebSchemaLoader.main_schema_directory |
|
38 |
assert 'Folder' in migrschema |
|
39 |
self.repo.hm.deactivate_verification_hooks() |
|
40 |
RepositoryBasedTC.setUp(self) |
|
41 |
self.mh = ServerMigrationHelper(self.repo.config, migrschema, |
|
42 |
repo=self.repo, cnx=self.cnx, |
|
43 |
interactive=False) |
|
972 | 44 |
assert self.cnx is self.mh._cnx |
45 |
assert self.session is self.mh.session, (self.session.id, self.mh.session.id) |
|
0 | 46 |
|
47 |
def test_add_attribute_int(self): |
|
48 |
self.failIf('whatever' in self.schema) |
|
49 |
paraordernum = self.mh.rqlexec('Any O WHERE X name "Note", RT name "para", RDEF from_entity X, RDEF relation_type RT, RDEF ordernum O')[0][0] |
|
50 |
self.mh.cmd_add_attribute('Note', 'whatever') |
|
51 |
self.failUnless('whatever' in self.schema) |
|
52 |
self.assertEquals(self.schema['whatever'].subjects(), ('Note',)) |
|
53 |
self.assertEquals(self.schema['whatever'].objects(), ('Int',)) |
|
54 |
paraordernum2 = self.mh.rqlexec('Any O WHERE X name "Note", RT name "para", RDEF from_entity X, RDEF relation_type RT, RDEF ordernum O')[0][0] |
|
55 |
self.assertEquals(paraordernum2, paraordernum+1) |
|
56 |
#self.assertEquals([r.type for r in self.schema['Note'].ordered_relations()], |
|
57 |
# ['modification_date', 'creation_date', 'owned_by', |
|
58 |
# 'eid', 'ecrit_par', 'inline1', 'date', 'type', |
|
59 |
# 'whatever', 'para', 'in_basket']) |
|
60 |
# NB: commit instead of rollback make following test fail with py2.5 |
|
61 |
# this sounds like a pysqlite/2.5 bug (the same eid is affected to |
|
62 |
# two different entities) |
|
63 |
self.mh.rollback() |
|
64 |
||
65 |
def test_add_attribute_varchar(self): |
|
66 |
self.failIf('shortpara' in self.schema) |
|
67 |
self.mh.cmd_add_attribute('Note', 'shortpara') |
|
68 |
self.failUnless('shortpara' in self.schema) |
|
69 |
self.assertEquals(self.schema['shortpara'].subjects(), ('Note', )) |
|
70 |
self.assertEquals(self.schema['shortpara'].objects(), ('String', )) |
|
71 |
# test created column is actually a varchar(64) |
|
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:
972
diff
changeset
|
72 |
notesql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' and name='%sNote'" % SQL_PREFIX)[0][0] |
0 | 73 |
fields = dict(x.strip().split()[:2] for x in notesql.split('(', 1)[1].rsplit(')', 1)[0].split(',')) |
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:
972
diff
changeset
|
74 |
self.assertEquals(fields['%sshortpara' % SQL_PREFIX], 'varchar(64)') |
0 | 75 |
self.mh.rollback() |
76 |
||
77 |
def test_add_datetime_with_default_value_attribute(self): |
|
78 |
self.failIf('mydate' in self.schema) |
|
79 |
self.mh.cmd_add_attribute('Note', 'mydate') |
|
80 |
self.failUnless('mydate' in self.schema) |
|
81 |
self.assertEquals(self.schema['mydate'].subjects(), ('Note', )) |
|
82 |
self.assertEquals(self.schema['mydate'].objects(), ('Date', )) |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
83 |
testdate = date(2005, 12, 13) |
0 | 84 |
eid1 = self.mh.rqlexec('INSERT Note N')[0][0] |
85 |
eid2 = self.mh.rqlexec('INSERT Note N: N mydate %(mydate)s', {'mydate' : testdate})[0][0] |
|
86 |
d1 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid1}, 'x')[0][0] |
|
87 |
d2 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid2}, 'x')[0][0] |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
88 |
self.assertEquals(d1, date.today()) |
0 | 89 |
self.assertEquals(d2, testdate) |
90 |
self.mh.rollback() |
|
91 |
||
92 |
def test_rename_attribute(self): |
|
93 |
self.failIf('civility' in self.schema) |
|
94 |
eid1 = self.mh.rqlexec('INSERT Personne X: X nom "lui", X sexe "M"')[0][0] |
|
95 |
eid2 = self.mh.rqlexec('INSERT Personne X: X nom "l\'autre", X sexe NULL')[0][0] |
|
96 |
self.mh.cmd_rename_attribute('Personne', 'sexe', 'civility') |
|
97 |
self.failIf('sexe' in self.schema) |
|
98 |
self.failUnless('civility' in self.schema) |
|
99 |
# test data has been backported |
|
100 |
c1 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid1)[0][0] |
|
101 |
self.failUnlessEqual(c1, 'M') |
|
102 |
c2 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid2)[0][0] |
|
103 |
self.failUnlessEqual(c2, None) |
|
104 |
||
105 |
||
106 |
def test_workflow_actions(self): |
|
107 |
foo = self.mh.cmd_add_state(u'foo', ('Personne', 'Email'), initial=True) |
|
108 |
for etype in ('Personne', 'Email'): |
|
109 |
s1 = self.mh.rqlexec('Any N WHERE S state_of ET, ET name "%s", S name N' % |
|
110 |
etype)[0][0] |
|
111 |
self.assertEquals(s1, "foo") |
|
112 |
s1 = self.mh.rqlexec('Any N WHERE ET initial_state S, ET name "%s", S name N' % |
|
113 |
etype)[0][0] |
|
114 |
self.assertEquals(s1, "foo") |
|
115 |
bar = self.mh.cmd_add_state(u'bar', ('Personne', 'Email'), initial=True) |
|
116 |
baz = self.mh.cmd_add_transition(u'baz', ('Personne', 'Email'), |
|
117 |
(foo,), bar, ('managers',)) |
|
118 |
for etype in ('Personne', 'Email'): |
|
119 |
t1 = self.mh.rqlexec('Any N WHERE T transition_of ET, ET name "%s", T name N' % |
|
120 |
etype)[0][0] |
|
121 |
self.assertEquals(t1, "baz") |
|
122 |
gn = self.mh.rqlexec('Any GN WHERE T require_group G, G name GN, T eid %s' % baz)[0][0] |
|
123 |
self.assertEquals(gn, 'managers') |
|
124 |
||
125 |
def test_add_entity_type(self): |
|
126 |
self.failIf('Folder2' in self.schema) |
|
127 |
self.failIf('filed_under2' in self.schema) |
|
128 |
self.mh.cmd_add_entity_type('Folder2') |
|
129 |
self.failUnless('Folder2' in self.schema) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
130 |
self.failUnless(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 131 |
self.failUnless('filed_under2' in self.schema) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
132 |
self.failUnless(self.execute('CWRType X WHERE X name "filed_under2"')) |
0 | 133 |
self.assertEquals(sorted(str(rs) for rs in self.schema['Folder2'].subject_relations()), |
134 |
['created_by', 'creation_date', 'description', 'description_format', 'eid', |
|
135 |
'filed_under2', 'has_text', 'identity', 'is', 'is_instance_of', |
|
136 |
'modification_date', 'name', 'owned_by']) |
|
137 |
self.assertEquals([str(rs) for rs in self.schema['Folder2'].object_relations()], |
|
138 |
['filed_under2', 'identity']) |
|
139 |
self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()), |
|
439 | 140 |
['Affaire', 'Card', 'Division', 'Email', 'EmailThread', 'File', |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
141 |
'Folder2', 'Image', 'Note', 'Personne', 'Societe', 'SubDivision']) |
0 | 142 |
self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) |
143 |
eschema = self.schema.eschema('Folder2') |
|
144 |
for cstr in eschema.constraints('name'): |
|
145 |
self.failUnless(hasattr(cstr, 'eid')) |
|
146 |
||
147 |
def test_drop_entity_type(self): |
|
148 |
self.mh.cmd_add_entity_type('Folder2') |
|
149 |
todoeid = self.mh.cmd_add_state(u'todo', 'Folder2', initial=True) |
|
150 |
doneeid = self.mh.cmd_add_state(u'done', 'Folder2') |
|
151 |
self.mh.cmd_add_transition(u'redoit', 'Folder2', (doneeid,), todoeid) |
|
152 |
self.mh.cmd_add_transition(u'markasdone', 'Folder2', (todoeid,), doneeid) |
|
153 |
self.commit() |
|
154 |
eschema = self.schema.eschema('Folder2') |
|
155 |
self.mh.cmd_drop_entity_type('Folder2') |
|
156 |
self.failIf('Folder2' in self.schema) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
157 |
self.failIf(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 158 |
# test automatic workflow deletion |
159 |
self.failIf(self.execute('State X WHERE NOT X state_of ET')) |
|
160 |
self.failIf(self.execute('Transition X WHERE NOT X transition_of ET')) |
|
161 |
||
162 |
def test_add_relation_type(self): |
|
163 |
self.mh.cmd_add_entity_type('Folder2', auto=False) |
|
164 |
self.mh.cmd_add_relation_type('filed_under2') |
|
165 |
self.failUnless('filed_under2' in self.schema) |
|
166 |
self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()), |
|
439 | 167 |
['Affaire', 'Card', 'Division', 'Email', 'EmailThread', 'File', |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
168 |
'Folder2', 'Image', 'Note', 'Personne', 'Societe', 'SubDivision']) |
0 | 169 |
self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) |
170 |
||
171 |
||
172 |
def test_drop_relation_type(self): |
|
173 |
self.mh.cmd_add_entity_type('Folder2', auto=False) |
|
174 |
self.mh.cmd_add_relation_type('filed_under2') |
|
175 |
self.failUnless('filed_under2' in self.schema) |
|
176 |
self.mh.cmd_drop_relation_type('filed_under2') |
|
177 |
self.failIf('filed_under2' in self.schema) |
|
178 |
||
179 |
def test_add_relation_definition(self): |
|
180 |
self.mh.cmd_add_relation_definition('Societe', 'in_state', 'State') |
|
181 |
self.assertEquals(sorted(self.schema['in_state'].subjects()), |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
182 |
['Affaire', 'Division', 'CWUser', 'Note', 'Societe', 'SubDivision']) |
0 | 183 |
self.assertEquals(self.schema['in_state'].objects(), ('State',)) |
184 |
||
185 |
def test_add_relation_definition_nortype(self): |
|
186 |
self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire') |
|
187 |
self.assertEquals(self.schema['concerne2'].subjects(), |
|
188 |
('Personne',)) |
|
189 |
self.assertEquals(self.schema['concerne2'].objects(), ('Affaire',)) |
|
190 |
||
191 |
def test_drop_relation_definition1(self): |
|
192 |
self.failUnless('concerne' in self.schema) |
|
193 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne']) |
|
194 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
|
195 |
self.mh.cmd_drop_relation_definition('Personne', 'concerne', 'Affaire') |
|
196 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire']) |
|
197 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Division', 'Note', 'Societe', 'SubDivision']) |
|
198 |
||
199 |
def test_drop_relation_definition_with_specialization(self): |
|
200 |
self.failUnless('concerne' in self.schema) |
|
201 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne']) |
|
202 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
|
203 |
self.mh.cmd_drop_relation_definition('Affaire', 'concerne', 'Societe') |
|
204 |
self.mh.cmd_drop_relation_definition('None', 'concerne', 'Societe') |
|
205 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne']) |
|
206 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Note']) |
|
207 |
||
208 |
def test_drop_relation_definition2(self): |
|
209 |
self.failUnless('evaluee' in self.schema) |
|
210 |
self.mh.cmd_drop_relation_definition('Personne', 'evaluee', 'Note') |
|
211 |
self.failUnless('evaluee' in self.schema) |
|
212 |
self.assertEquals(sorted(self.schema['evaluee'].subjects()), |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
213 |
['Division', 'CWUser', 'Societe', 'SubDivision']) |
0 | 214 |
self.assertEquals(sorted(self.schema['evaluee'].objects()), |
215 |
['Note']) |
|
216 |
||
217 |
def test_rename_relation(self): |
|
218 |
self.skip('implement me') |
|
219 |
||
220 |
def test_change_relation_props_non_final(self): |
|
221 |
rschema = self.schema['concerne'] |
|
222 |
card = rschema.rproperty('Affaire', 'Societe', 'cardinality') |
|
223 |
self.assertEquals(card, '**') |
|
224 |
try: |
|
225 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
226 |
cardinality='?*') |
|
227 |
card = rschema.rproperty('Affaire', 'Societe', 'cardinality') |
|
228 |
self.assertEquals(card, '?*') |
|
229 |
finally: |
|
230 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
231 |
cardinality='**') |
|
232 |
||
233 |
def test_change_relation_props_final(self): |
|
234 |
rschema = self.schema['adel'] |
|
235 |
card = rschema.rproperty('Personne', 'String', 'fulltextindexed') |
|
236 |
self.assertEquals(card, False) |
|
237 |
try: |
|
238 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
239 |
fulltextindexed=True) |
|
240 |
card = rschema.rproperty('Personne', 'String', 'fulltextindexed') |
|
241 |
self.assertEquals(card, True) |
|
242 |
finally: |
|
243 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
244 |
fulltextindexed=False) |
|
245 |
||
246 |
def test_synchronize_schema(self): |
|
247 |
cursor = self.mh.rqlcursor |
|
248 |
nbrqlexpr_start = len(cursor.execute('RQLExpression X')) |
|
249 |
migrschema['titre']._rproperties[('Personne', 'String')]['order'] = 7 |
|
250 |
migrschema['adel']._rproperties[('Personne', 'String')]['order'] = 6 |
|
251 |
migrschema['ass']._rproperties[('Personne', 'String')]['order'] = 5 |
|
252 |
# expected = ['eid', 'has_text', 'creation_date', 'modification_date', |
|
253 |
# 'nom', 'prenom', 'civility', 'promo', 'ass', 'adel', 'titre', |
|
254 |
# 'web', 'tel', 'fax', 'datenaiss', 'test'] |
|
255 |
# self.assertEquals([rs.type for rs in migrschema['Personne'].ordered_relations() if rs.is_final()], |
|
256 |
# expected) |
|
257 |
migrschema['Personne'].description = 'blabla bla' |
|
258 |
migrschema['titre'].description = 'usually a title' |
|
259 |
migrschema['titre']._rproperties[('Personne', 'String')]['description'] = 'title for this person' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
260 |
# rinorderbefore = cursor.execute('Any O,N WHERE X is CWAttribute, X relation_type RT, RT name N,' |
0 | 261 |
# 'X from_entity FE, FE name "Personne",' |
262 |
# 'X ordernum O ORDERBY O') |
|
263 |
# expected = [u'creation_date', u'modification_date', u'nom', u'prenom', |
|
264 |
# u'sexe', u'promo', u'titre', u'adel', u'ass', u'web', u'tel', |
|
265 |
# u'fax', u'datenaiss', u'test', u'description'] |
|
266 |
# self.assertListEquals(rinorderbefore, map(list, zip([0, 0]+range(1, len(expected)), expected))) |
|
267 |
||
268 |
self.mh.cmd_synchronize_schema(commit=False) |
|
269 |
||
270 |
self.assertEquals(cursor.execute('Any D WHERE X name "Personne", X description D')[0][0], |
|
271 |
'blabla bla') |
|
272 |
self.assertEquals(cursor.execute('Any D WHERE X name "titre", X description D')[0][0], |
|
273 |
'usually a title') |
|
274 |
self.assertEquals(cursor.execute('Any D WHERE X relation_type RT, RT name "titre",' |
|
275 |
'X from_entity FE, FE name "Personne",' |
|
276 |
'X description D')[0][0], |
|
277 |
'title for this person') |
|
278 |
# skip "sexe" and "description" since they aren't in the migration |
|
279 |
# schema and so behaviour is undefined |
|
280 |
# "civility" is also skipped since it may have been added by |
|
281 |
# test_rename_attribut :o/ |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
282 |
rinorder = [n for n, in cursor.execute('Any N ORDERBY O WHERE X is CWAttribute, X relation_type RT, RT name N,' |
0 | 283 |
'X from_entity FE, FE name "Personne",' |
284 |
'X ordernum O') if n not in ('sexe', 'description', 'civility')] |
|
285 |
expected = [u'nom', u'prenom', u'promo', u'ass', u'adel', u'titre', |
|
286 |
u'web', u'tel', u'fax', u'datenaiss', u'test', u'firstname', |
|
287 |
u'creation_date', u'modification_date'] |
|
288 |
self.assertEquals(rinorder, expected) |
|
289 |
||
290 |
# test permissions synchronization #################################### |
|
291 |
# new rql expr to add note entity |
|
292 |
eexpr = self._erqlexpr_entity('add', 'Note') |
|
293 |
self.assertEquals(eexpr.expression, |
|
294 |
'X ecrit_part PE, U in_group G, ' |
|
295 |
'PE require_permission P, P name "add_note", P require_group G') |
|
296 |
self.assertEquals([et.name for et in eexpr.reverse_add_permission], ['Note']) |
|
297 |
self.assertEquals(eexpr.reverse_read_permission, []) |
|
298 |
self.assertEquals(eexpr.reverse_delete_permission, []) |
|
299 |
self.assertEquals(eexpr.reverse_update_permission, []) |
|
300 |
# no more rqlexpr to delete and add para attribute |
|
301 |
self.failIf(self._rrqlexpr_rset('add', 'para')) |
|
302 |
self.failIf(self._rrqlexpr_rset('delete', 'para')) |
|
303 |
# new rql expr to add ecrit_par relation |
|
304 |
rexpr = self._rrqlexpr_entity('add', 'ecrit_par') |
|
305 |
self.assertEquals(rexpr.expression, |
|
306 |
'O require_permission P, P name "add_note", ' |
|
307 |
'U in_group G, P require_group G') |
|
308 |
self.assertEquals([rt.name for rt in rexpr.reverse_add_permission], ['ecrit_par']) |
|
309 |
self.assertEquals(rexpr.reverse_read_permission, []) |
|
310 |
self.assertEquals(rexpr.reverse_delete_permission, []) |
|
311 |
# no more rqlexpr to delete and add travaille relation |
|
312 |
self.failIf(self._rrqlexpr_rset('add', 'travaille')) |
|
313 |
self.failIf(self._rrqlexpr_rset('delete', 'travaille')) |
|
314 |
# no more rqlexpr to delete and update Societe entity |
|
315 |
self.failIf(self._erqlexpr_rset('update', 'Societe')) |
|
316 |
self.failIf(self._erqlexpr_rset('delete', 'Societe')) |
|
317 |
# no more rqlexpr to read Affaire entity |
|
318 |
self.failIf(self._erqlexpr_rset('read', 'Affaire')) |
|
319 |
# rqlexpr to update Affaire entity has been updated |
|
320 |
eexpr = self._erqlexpr_entity('update', 'Affaire') |
|
321 |
self.assertEquals(eexpr.expression, 'X concerne S, S owned_by U') |
|
322 |
# no change for rqlexpr to add and delete Affaire entity |
|
323 |
self.assertEquals(len(self._erqlexpr_rset('delete', 'Affaire')), 1) |
|
324 |
self.assertEquals(len(self._erqlexpr_rset('add', 'Affaire')), 1) |
|
325 |
# no change for rqlexpr to add and delete concerne relation |
|
326 |
self.assertEquals(len(self._rrqlexpr_rset('delete', 'concerne')), 1) |
|
327 |
self.assertEquals(len(self._rrqlexpr_rset('add', 'concerne')), 1) |
|
328 |
# * migrschema involve: |
|
329 |
# * 8 deletion (2 in Affaire read + Societe + travaille + para rqlexprs) |
|
330 |
# * 1 update (Affaire update) |
|
331 |
# * 2 new (Note add, ecrit_par add) |
|
332 |
# remaining orphan rql expr which should be deleted at commit (composite relation) |
|
333 |
self.assertEquals(len(cursor.execute('RQLExpression X WHERE NOT ET1 read_permission X, NOT ET2 add_permission X, ' |
|
334 |
'NOT ET3 delete_permission X, NOT ET4 update_permission X')), 8+1) |
|
335 |
# finally |
|
336 |
self.assertEquals(len(cursor.execute('RQLExpression X')), nbrqlexpr_start + 1 + 2) |
|
337 |
||
338 |
self.mh.rollback() |
|
339 |
||
340 |
def _erqlexpr_rset(self, action, ertype): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
341 |
rql = 'RQLExpression X WHERE ET is CWEType, ET %s_permission X, ET name %%(name)s' % action |
0 | 342 |
return self.mh.rqlcursor.execute(rql, {'name': ertype}) |
343 |
def _erqlexpr_entity(self, action, ertype): |
|
344 |
rset = self._erqlexpr_rset(action, ertype) |
|
345 |
self.assertEquals(len(rset), 1) |
|
346 |
return rset.get_entity(0, 0) |
|
347 |
def _rrqlexpr_rset(self, action, ertype): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
348 |
rql = 'RQLExpression X WHERE ET is CWRType, ET %s_permission X, ET name %%(name)s' % action |
0 | 349 |
return self.mh.rqlcursor.execute(rql, {'name': ertype}) |
350 |
def _rrqlexpr_entity(self, action, ertype): |
|
351 |
rset = self._rrqlexpr_rset(action, ertype) |
|
352 |
self.assertEquals(len(rset), 1) |
|
353 |
return rset.get_entity(0, 0) |
|
354 |
||
355 |
def test_set_size_constraint(self): |
|
356 |
# existing previous value |
|
357 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
358 |
self.mh.cmd_set_size_constraint('CWEType', 'name', 128) |
0 | 359 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
360 |
self.mh.cmd_set_size_constraint('CWEType', 'name', 64) |
0 | 361 |
# non existing previous value |
362 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
363 |
self.mh.cmd_set_size_constraint('CWEType', 'description', 256) |
0 | 364 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
365 |
self.mh.cmd_set_size_constraint('CWEType', 'description', None) |
0 | 366 |
|
367 |
def test_add_remove_cube(self): |
|
368 |
cubes = set(self.config.cubes()) |
|
369 |
schema = self.repo.schema |
|
439 | 370 |
self.assertEquals(sorted(schema['see_also']._rproperties.keys()), |
371 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
|
372 |
('Bookmark', 'Bookmark'), ('Bookmark', 'Note'), |
|
373 |
('Note', 'Note'), ('Note', 'Bookmark')])) |
|
0 | 374 |
try: |
439 | 375 |
try: |
376 |
self.mh.cmd_remove_cube('email') |
|
377 |
# file was there because it's an email dependancy, should have been removed |
|
378 |
cubes.remove('email') |
|
379 |
cubes.remove('file') |
|
380 |
self.assertEquals(set(self.config.cubes()), cubes) |
|
381 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', |
|
382 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
|
383 |
self.failIf(ertype in schema, ertype) |
|
384 |
self.assertEquals(sorted(schema['see_also']._rproperties.keys()), |
|
385 |
sorted([('Folder', 'Folder'), |
|
386 |
('Bookmark', 'Bookmark'), |
|
387 |
('Bookmark', 'Note'), |
|
388 |
('Note', 'Note'), |
|
389 |
('Note', 'Bookmark')])) |
|
390 |
self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'Folder', 'Note']) |
|
391 |
self.assertEquals(sorted(schema['see_also'].objects()), ['Bookmark', 'Folder', 'Note']) |
|
392 |
self.assertEquals(self.execute('Any X WHERE X pkey "system.version.email"').rowcount, 0) |
|
393 |
self.assertEquals(self.execute('Any X WHERE X pkey "system.version.file"').rowcount, 0) |
|
394 |
self.failIf('email' in self.config.cubes()) |
|
395 |
self.failIf('file' in self.config.cubes()) |
|
396 |
except : |
|
397 |
import traceback |
|
398 |
traceback.print_exc() |
|
399 |
raise |
|
0 | 400 |
finally: |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
401 |
self.mh.cmd_add_cube('email') |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
402 |
cubes.add('email') |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
403 |
cubes.add('file') |
0 | 404 |
self.assertEquals(set(self.config.cubes()), cubes) |
405 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', |
|
406 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
|
407 |
self.failUnless(ertype in schema, ertype) |
|
408 |
self.assertEquals(sorted(schema['see_also']._rproperties.keys()), |
|
439 | 409 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
410 |
('Bookmark', 'Bookmark'), |
|
411 |
('Bookmark', 'Note'), |
|
412 |
('Note', 'Note'), |
|
413 |
('Note', 'Bookmark')])) |
|
414 |
self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'EmailThread', 'Folder', 'Note']) |
|
415 |
self.assertEquals(sorted(schema['see_also'].objects()), ['Bookmark', 'EmailThread', 'Folder', 'Note']) |
|
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
416 |
from cubes.email.__pkginfo__ import version as email_version |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
417 |
from cubes.file.__pkginfo__ import version as file_version |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
418 |
self.assertEquals(self.execute('Any V WHERE X value V, X pkey "system.version.email"')[0][0], |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
419 |
email_version) |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
420 |
self.assertEquals(self.execute('Any V WHERE X value V, X pkey "system.version.file"')[0][0], |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
421 |
file_version) |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
422 |
self.failUnless('email' in self.config.cubes()) |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
423 |
self.failUnless('file' in self.config.cubes()) |
0 | 424 |
# trick: overwrite self.maxeid to avoid deletion of just reintroduced |
425 |
# types (and their associated tables!) |
|
426 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
|
427 |
# why this commit is necessary is unclear to me (though without it |
|
428 |
# next test may fail complaining of missing tables |
|
429 |
self.commit() |
|
972 | 430 |
|
431 |
def test_set_state(self): |
|
432 |
user = self.session.user |
|
433 |
self.set_debug(True) |
|
434 |
self.mh.set_state(user.eid, 'deactivated') |
|
435 |
user.clear_related_cache('in_state', 'subject') |
|
436 |
try: |
|
437 |
self.assertEquals(user.state, 'deactivated') |
|
438 |
finally: |
|
439 |
self.set_debug(False) |
|
0 | 440 |
|
441 |
if __name__ == '__main__': |
|
442 |
unittest_main() |