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