author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 23 Jul 2009 15:28:41 +0200 | |
changeset 2456 | aa25d6b244c8 |
parent 2251 | 799ff50ddfe8 |
child 2591 | 287e43c6ed81 |
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): |
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
26 |
copy_schema = False |
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 |
||
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
149 |
def test_add_drop_entity_type(self): |
0 | 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 |
||
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
164 |
def test_add_drop_relation_type(self): |
0 | 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 |
self.mh.cmd_drop_relation_type('filed_under2') |
|
173 |
self.failIf('filed_under2' in self.schema) |
|
174 |
||
175 |
def test_add_relation_definition_nortype(self): |
|
176 |
self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire') |
|
177 |
self.assertEquals(self.schema['concerne2'].subjects(), |
|
178 |
('Personne',)) |
|
179 |
self.assertEquals(self.schema['concerne2'].objects(), ('Affaire',)) |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
180 |
self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Affaire') |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
181 |
self.failIf('concerne2' in self.schema) |
0 | 182 |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
183 |
def test_drop_relation_definition_existant_rtype(self): |
0 | 184 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne']) |
185 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
|
186 |
self.mh.cmd_drop_relation_definition('Personne', 'concerne', 'Affaire') |
|
187 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire']) |
|
188 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Division', 'Note', 'Societe', 'SubDivision']) |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
189 |
self.mh.cmd_add_relation_definition('Personne', 'concerne', 'Affaire') |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
190 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne']) |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
191 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
192 |
# trick: overwrite self.maxeid to avoid deletion of just reintroduced types |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
193 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
1787 | 194 |
|
0 | 195 |
def test_drop_relation_definition_with_specialization(self): |
196 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne']) |
|
197 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
|
198 |
self.mh.cmd_drop_relation_definition('Affaire', 'concerne', 'Societe') |
|
199 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne']) |
|
200 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Note']) |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
201 |
self.mh.cmd_add_relation_definition('Affaire', 'concerne', 'Societe') |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
202 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne']) |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
203 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
204 |
# trick: overwrite self.maxeid to avoid deletion of just reintroduced types |
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
205 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
0 | 206 |
|
207 |
def test_rename_relation(self): |
|
208 |
self.skip('implement me') |
|
209 |
||
210 |
def test_change_relation_props_non_final(self): |
|
211 |
rschema = self.schema['concerne'] |
|
212 |
card = rschema.rproperty('Affaire', 'Societe', 'cardinality') |
|
213 |
self.assertEquals(card, '**') |
|
214 |
try: |
|
215 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
216 |
cardinality='?*') |
|
217 |
card = rschema.rproperty('Affaire', 'Societe', 'cardinality') |
|
218 |
self.assertEquals(card, '?*') |
|
219 |
finally: |
|
220 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
221 |
cardinality='**') |
|
1787 | 222 |
|
0 | 223 |
def test_change_relation_props_final(self): |
224 |
rschema = self.schema['adel'] |
|
225 |
card = rschema.rproperty('Personne', 'String', 'fulltextindexed') |
|
226 |
self.assertEquals(card, False) |
|
227 |
try: |
|
228 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
229 |
fulltextindexed=True) |
|
230 |
card = rschema.rproperty('Personne', 'String', 'fulltextindexed') |
|
231 |
self.assertEquals(card, True) |
|
232 |
finally: |
|
233 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
234 |
fulltextindexed=False) |
|
235 |
||
236 |
def test_synchronize_schema(self): |
|
237 |
cursor = self.mh.rqlcursor |
|
238 |
nbrqlexpr_start = len(cursor.execute('RQLExpression X')) |
|
239 |
migrschema['titre']._rproperties[('Personne', 'String')]['order'] = 7 |
|
240 |
migrschema['adel']._rproperties[('Personne', 'String')]['order'] = 6 |
|
241 |
migrschema['ass']._rproperties[('Personne', 'String')]['order'] = 5 |
|
242 |
# expected = ['eid', 'has_text', 'creation_date', 'modification_date', |
|
243 |
# 'nom', 'prenom', 'civility', 'promo', 'ass', 'adel', 'titre', |
|
244 |
# 'web', 'tel', 'fax', 'datenaiss', 'test'] |
|
245 |
# self.assertEquals([rs.type for rs in migrschema['Personne'].ordered_relations() if rs.is_final()], |
|
246 |
# expected) |
|
247 |
migrschema['Personne'].description = 'blabla bla' |
|
1787 | 248 |
migrschema['titre'].description = 'usually a title' |
0 | 249 |
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
|
250 |
# rinorderbefore = cursor.execute('Any O,N WHERE X is CWAttribute, X relation_type RT, RT name N,' |
0 | 251 |
# 'X from_entity FE, FE name "Personne",' |
252 |
# 'X ordernum O ORDERBY O') |
|
253 |
# expected = [u'creation_date', u'modification_date', u'nom', u'prenom', |
|
254 |
# u'sexe', u'promo', u'titre', u'adel', u'ass', u'web', u'tel', |
|
255 |
# u'fax', u'datenaiss', u'test', u'description'] |
|
256 |
# self.assertListEquals(rinorderbefore, map(list, zip([0, 0]+range(1, len(expected)), expected))) |
|
1787 | 257 |
|
258 |
self.mh.cmd_sync_schema_props_perms(commit=False) |
|
259 |
||
0 | 260 |
self.assertEquals(cursor.execute('Any D WHERE X name "Personne", X description D')[0][0], |
261 |
'blabla bla') |
|
262 |
self.assertEquals(cursor.execute('Any D WHERE X name "titre", X description D')[0][0], |
|
263 |
'usually a title') |
|
264 |
self.assertEquals(cursor.execute('Any D WHERE X relation_type RT, RT name "titre",' |
|
265 |
'X from_entity FE, FE name "Personne",' |
|
266 |
'X description D')[0][0], |
|
267 |
'title for this person') |
|
268 |
# skip "sexe" and "description" since they aren't in the migration |
|
269 |
# schema and so behaviour is undefined |
|
270 |
# "civility" is also skipped since it may have been added by |
|
271 |
# 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
|
272 |
rinorder = [n for n, in cursor.execute('Any N ORDERBY O WHERE X is CWAttribute, X relation_type RT, RT name N,' |
0 | 273 |
'X from_entity FE, FE name "Personne",' |
274 |
'X ordernum O') if n not in ('sexe', 'description', 'civility')] |
|
275 |
expected = [u'nom', u'prenom', u'promo', u'ass', u'adel', u'titre', |
|
276 |
u'web', u'tel', u'fax', u'datenaiss', u'test', u'firstname', |
|
277 |
u'creation_date', u'modification_date'] |
|
278 |
self.assertEquals(rinorder, expected) |
|
279 |
||
280 |
# test permissions synchronization #################################### |
|
281 |
# new rql expr to add note entity |
|
282 |
eexpr = self._erqlexpr_entity('add', 'Note') |
|
283 |
self.assertEquals(eexpr.expression, |
|
284 |
'X ecrit_part PE, U in_group G, ' |
|
285 |
'PE require_permission P, P name "add_note", P require_group G') |
|
286 |
self.assertEquals([et.name for et in eexpr.reverse_add_permission], ['Note']) |
|
287 |
self.assertEquals(eexpr.reverse_read_permission, []) |
|
288 |
self.assertEquals(eexpr.reverse_delete_permission, []) |
|
289 |
self.assertEquals(eexpr.reverse_update_permission, []) |
|
290 |
# no more rqlexpr to delete and add para attribute |
|
291 |
self.failIf(self._rrqlexpr_rset('add', 'para')) |
|
292 |
self.failIf(self._rrqlexpr_rset('delete', 'para')) |
|
1787 | 293 |
# new rql expr to add ecrit_par relation |
0 | 294 |
rexpr = self._rrqlexpr_entity('add', 'ecrit_par') |
295 |
self.assertEquals(rexpr.expression, |
|
296 |
'O require_permission P, P name "add_note", ' |
|
297 |
'U in_group G, P require_group G') |
|
298 |
self.assertEquals([rt.name for rt in rexpr.reverse_add_permission], ['ecrit_par']) |
|
299 |
self.assertEquals(rexpr.reverse_read_permission, []) |
|
300 |
self.assertEquals(rexpr.reverse_delete_permission, []) |
|
301 |
# no more rqlexpr to delete and add travaille relation |
|
302 |
self.failIf(self._rrqlexpr_rset('add', 'travaille')) |
|
303 |
self.failIf(self._rrqlexpr_rset('delete', 'travaille')) |
|
304 |
# no more rqlexpr to delete and update Societe entity |
|
305 |
self.failIf(self._erqlexpr_rset('update', 'Societe')) |
|
306 |
self.failIf(self._erqlexpr_rset('delete', 'Societe')) |
|
307 |
# no more rqlexpr to read Affaire entity |
|
308 |
self.failIf(self._erqlexpr_rset('read', 'Affaire')) |
|
309 |
# rqlexpr to update Affaire entity has been updated |
|
310 |
eexpr = self._erqlexpr_entity('update', 'Affaire') |
|
311 |
self.assertEquals(eexpr.expression, 'X concerne S, S owned_by U') |
|
312 |
# no change for rqlexpr to add and delete Affaire entity |
|
313 |
self.assertEquals(len(self._erqlexpr_rset('delete', 'Affaire')), 1) |
|
314 |
self.assertEquals(len(self._erqlexpr_rset('add', 'Affaire')), 1) |
|
315 |
# no change for rqlexpr to add and delete concerne relation |
|
316 |
self.assertEquals(len(self._rrqlexpr_rset('delete', 'concerne')), 1) |
|
317 |
self.assertEquals(len(self._rrqlexpr_rset('add', 'concerne')), 1) |
|
318 |
# * migrschema involve: |
|
319 |
# * 8 deletion (2 in Affaire read + Societe + travaille + para rqlexprs) |
|
320 |
# * 1 update (Affaire update) |
|
321 |
# * 2 new (Note add, ecrit_par add) |
|
322 |
# remaining orphan rql expr which should be deleted at commit (composite relation) |
|
323 |
self.assertEquals(len(cursor.execute('RQLExpression X WHERE NOT ET1 read_permission X, NOT ET2 add_permission X, ' |
|
324 |
'NOT ET3 delete_permission X, NOT ET4 update_permission X')), 8+1) |
|
325 |
# finally |
|
1787 | 326 |
self.assertEquals(len(cursor.execute('RQLExpression X')), nbrqlexpr_start + 1 + 2) |
327 |
||
0 | 328 |
self.mh.rollback() |
329 |
||
330 |
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
|
331 |
rql = 'RQLExpression X WHERE ET is CWEType, ET %s_permission X, ET name %%(name)s' % action |
0 | 332 |
return self.mh.rqlcursor.execute(rql, {'name': ertype}) |
333 |
def _erqlexpr_entity(self, action, ertype): |
|
334 |
rset = self._erqlexpr_rset(action, ertype) |
|
335 |
self.assertEquals(len(rset), 1) |
|
336 |
return rset.get_entity(0, 0) |
|
337 |
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
|
338 |
rql = 'RQLExpression X WHERE ET is CWRType, ET %s_permission X, ET name %%(name)s' % action |
0 | 339 |
return self.mh.rqlcursor.execute(rql, {'name': ertype}) |
340 |
def _rrqlexpr_entity(self, action, ertype): |
|
341 |
rset = self._rrqlexpr_rset(action, ertype) |
|
342 |
self.assertEquals(len(rset), 1) |
|
343 |
return rset.get_entity(0, 0) |
|
1787 | 344 |
|
0 | 345 |
def test_set_size_constraint(self): |
346 |
# existing previous value |
|
347 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
348 |
self.mh.cmd_set_size_constraint('CWEType', 'name', 128) |
0 | 349 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
350 |
self.mh.cmd_set_size_constraint('CWEType', 'name', 64) |
0 | 351 |
# non existing previous value |
352 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
353 |
self.mh.cmd_set_size_constraint('CWEType', 'description', 256) |
0 | 354 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
355 |
self.mh.cmd_set_size_constraint('CWEType', 'description', None) |
0 | 356 |
|
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
|
357 |
def test_add_remove_cube_and_deps(self): |
0 | 358 |
cubes = set(self.config.cubes()) |
359 |
schema = self.repo.schema |
|
439 | 360 |
self.assertEquals(sorted(schema['see_also']._rproperties.keys()), |
361 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
|
362 |
('Bookmark', 'Bookmark'), ('Bookmark', 'Note'), |
|
363 |
('Note', 'Note'), ('Note', 'Bookmark')])) |
|
0 | 364 |
try: |
439 | 365 |
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
|
366 |
self.mh.cmd_remove_cube('email', removedeps=True) |
439 | 367 |
# 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
|
368 |
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
|
369 |
self.failIf('file' in self.config.cubes()) |
1787 | 370 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', |
439 | 371 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
372 |
self.failIf(ertype in schema, ertype) |
|
373 |
self.assertEquals(sorted(schema['see_also']._rproperties.keys()), |
|
374 |
sorted([('Folder', 'Folder'), |
|
375 |
('Bookmark', 'Bookmark'), |
|
376 |
('Bookmark', 'Note'), |
|
377 |
('Note', 'Note'), |
|
378 |
('Note', 'Bookmark')])) |
|
379 |
self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'Folder', 'Note']) |
|
380 |
self.assertEquals(sorted(schema['see_also'].objects()), ['Bookmark', 'Folder', 'Note']) |
|
381 |
self.assertEquals(self.execute('Any X WHERE X pkey "system.version.email"').rowcount, 0) |
|
382 |
self.assertEquals(self.execute('Any X WHERE X pkey "system.version.file"').rowcount, 0) |
|
383 |
except : |
|
384 |
import traceback |
|
385 |
traceback.print_exc() |
|
386 |
raise |
|
0 | 387 |
finally: |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
388 |
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
|
389 |
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
|
390 |
self.failUnless('file' in self.config.cubes()) |
1787 | 391 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', |
0 | 392 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
393 |
self.failUnless(ertype in schema, ertype) |
|
394 |
self.assertEquals(sorted(schema['see_also']._rproperties.keys()), |
|
439 | 395 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
396 |
('Bookmark', 'Bookmark'), |
|
397 |
('Bookmark', 'Note'), |
|
398 |
('Note', 'Note'), |
|
399 |
('Note', 'Bookmark')])) |
|
400 |
self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'EmailThread', 'Folder', 'Note']) |
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
email_version) |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
406 |
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
|
407 |
file_version) |
0 | 408 |
# trick: overwrite self.maxeid to avoid deletion of just reintroduced |
409 |
# types (and their associated tables!) |
|
410 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
|
411 |
# why this commit is necessary is unclear to me (though without it |
|
412 |
# next test may fail complaining of missing tables |
|
1787 | 413 |
self.commit() |
972 | 414 |
|
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
|
415 |
|
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
|
416 |
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
|
417 |
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
|
418 |
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
|
419 |
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
|
420 |
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
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
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
|
425 |
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
|
426 |
'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
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
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
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
# 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
|
436 |
# 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
|
437 |
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
|
438 |
# 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
|
439 |
# 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
|
440 |
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
|
441 |
|
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 |
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
|
443 |
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
|
444 |
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
|
445 |
|
972 | 446 |
def test_set_state(self): |
447 |
user = self.session.user |
|
448 |
self.mh.set_state(user.eid, 'deactivated') |
|
449 |
user.clear_related_cache('in_state', 'subject') |
|
1787 | 450 |
self.assertEquals(user.state, 'deactivated') |
451 |
||
0 | 452 |
if __name__ == '__main__': |
453 |
unittest_main() |