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