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