author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 21 Aug 2009 08:42:17 +0200 | |
branch | 3.5 |
changeset 2943 | 77622caef9bd |
parent 2931 | 17224e90a1c4 |
child 2967 | e7d348134006 |
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 |
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2591
diff
changeset
|
6 |
from os.path import join |
0 | 7 |
|
8 |
from logilab.common.testlib import TestCase, unittest_main |
|
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 |
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2591
diff
changeset
|
11 |
from cubicweb.devtools.apptest import RepositoryBasedTC, 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
|
12 |
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
|
13 |
from cubicweb.server.sqlutils import SQL_PREFIX |
0 | 14 |
from cubicweb.server.repository import Repository |
15 |
from cubicweb.server.migractions import * |
|
16 |
||
17 |
orig_get_versions = Repository.get_versions |
|
18 |
||
19 |
def setup_module(*args): |
|
20 |
Repository.get_versions = get_versions |
|
21 |
||
22 |
def teardown_module(*args): |
|
23 |
Repository.get_versions = orig_get_versions |
|
24 |
||
1787 | 25 |
|
0 | 26 |
class MigrationCommandsTC(RepositoryBasedTC): |
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 |
|
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2591
diff
changeset
|
36 |
self.repo.config.appid = join('data', 'migratedapp') |
0 | 37 |
global migrschema |
38 |
migrschema = self.repo.config.load_schema() |
|
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2591
diff
changeset
|
39 |
self.repo.config.appid = 'data' |
0 | 40 |
assert 'Folder' in migrschema |
41 |
RepositoryBasedTC.setUp(self) |
|
42 |
self.mh = ServerMigrationHelper(self.repo.config, migrschema, |
|
43 |
repo=self.repo, cnx=self.cnx, |
|
44 |
interactive=False) |
|
972 | 45 |
assert self.cnx is self.mh._cnx |
46 |
assert self.session is self.mh.session, (self.session.id, self.mh.session.id) |
|
1787 | 47 |
|
0 | 48 |
def test_add_attribute_int(self): |
49 |
self.failIf('whatever' in self.schema) |
|
50 |
paraordernum = self.mh.rqlexec('Any O WHERE X name "Note", RT name "para", RDEF from_entity X, RDEF relation_type RT, RDEF ordernum O')[0][0] |
|
51 |
self.mh.cmd_add_attribute('Note', 'whatever') |
|
52 |
self.failUnless('whatever' in self.schema) |
|
53 |
self.assertEquals(self.schema['whatever'].subjects(), ('Note',)) |
|
54 |
self.assertEquals(self.schema['whatever'].objects(), ('Int',)) |
|
55 |
paraordernum2 = self.mh.rqlexec('Any O WHERE X name "Note", RT name "para", RDEF from_entity X, RDEF relation_type RT, RDEF ordernum O')[0][0] |
|
56 |
self.assertEquals(paraordernum2, paraordernum+1) |
|
57 |
#self.assertEquals([r.type for r in self.schema['Note'].ordered_relations()], |
|
58 |
# ['modification_date', 'creation_date', 'owned_by', |
|
59 |
# 'eid', 'ecrit_par', 'inline1', 'date', 'type', |
|
60 |
# 'whatever', 'para', 'in_basket']) |
|
61 |
# NB: commit instead of rollback make following test fail with py2.5 |
|
62 |
# this sounds like a pysqlite/2.5 bug (the same eid is affected to |
|
63 |
# two different entities) |
|
64 |
self.mh.rollback() |
|
65 |
||
66 |
def test_add_attribute_varchar(self): |
|
67 |
self.failIf('shortpara' in self.schema) |
|
68 |
self.mh.cmd_add_attribute('Note', 'shortpara') |
|
69 |
self.failUnless('shortpara' in self.schema) |
|
70 |
self.assertEquals(self.schema['shortpara'].subjects(), ('Note', )) |
|
71 |
self.assertEquals(self.schema['shortpara'].objects(), ('String', )) |
|
72 |
# test created column is actually a varchar(64) |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
73 |
notesql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' and name='%sNote'" % SQL_PREFIX)[0][0] |
0 | 74 |
fields = dict(x.strip().split()[:2] for x in notesql.split('(', 1)[1].rsplit(')', 1)[0].split(',')) |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
75 |
self.assertEquals(fields['%sshortpara' % SQL_PREFIX], 'varchar(64)') |
0 | 76 |
self.mh.rollback() |
1787 | 77 |
|
0 | 78 |
def test_add_datetime_with_default_value_attribute(self): |
79 |
self.failIf('mydate' in self.schema) |
|
2642 | 80 |
self.failIf('shortpara' in self.schema) |
0 | 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): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
109 |
wf = self.mh.cmd_add_workflow(u'foo', ('Personne', 'Email')) |
0 | 110 |
for etype in ('Personne', 'Email'): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
111 |
s1 = self.mh.rqlexec('Any N WHERE WF workflow_of ET, ET name "%s", WF name N' % |
0 | 112 |
etype)[0][0] |
113 |
self.assertEquals(s1, "foo") |
|
2943
77622caef9bd
[schema] default_workflow_of more naturally expressed as default_workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2931
diff
changeset
|
114 |
s1 = self.mh.rqlexec('Any N WHERE ET default_workflow WF, ET name "%s", WF name N' % |
0 | 115 |
etype)[0][0] |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
116 |
self.assertEquals(s1, "foo") |
1787 | 117 |
|
0 | 118 |
def test_add_entity_type(self): |
119 |
self.failIf('Folder2' in self.schema) |
|
120 |
self.failIf('filed_under2' in self.schema) |
|
121 |
self.mh.cmd_add_entity_type('Folder2') |
|
122 |
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
|
123 |
self.failUnless(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 124 |
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
|
125 |
self.failUnless(self.execute('CWRType X WHERE X name "filed_under2"')) |
0 | 126 |
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
|
127 |
['created_by', 'creation_date', 'cwuri', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
128 |
'description', 'description_format', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
129 |
'eid', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
130 |
'filed_under2', 'has_text', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
131 |
'identity', 'in_basket', 'is', 'is_instance_of', |
0 | 132 |
'modification_date', 'name', 'owned_by']) |
133 |
self.assertEquals([str(rs) for rs in self.schema['Folder2'].object_relations()], |
|
134 |
['filed_under2', 'identity']) |
|
135 |
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
|
136 |
sorted(str(e) for e in self.schema.entities() if not e.is_final())) |
0 | 137 |
self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) |
138 |
eschema = self.schema.eschema('Folder2') |
|
139 |
for cstr in eschema.constraints('name'): |
|
140 |
self.failUnless(hasattr(cstr, 'eid')) |
|
141 |
||
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
142 |
def test_add_drop_entity_type(self): |
0 | 143 |
self.mh.cmd_add_entity_type('Folder2') |
144 |
todoeid = self.mh.cmd_add_state(u'todo', 'Folder2', initial=True) |
|
145 |
doneeid = self.mh.cmd_add_state(u'done', 'Folder2') |
|
146 |
self.mh.cmd_add_transition(u'redoit', 'Folder2', (doneeid,), todoeid) |
|
147 |
self.mh.cmd_add_transition(u'markasdone', 'Folder2', (todoeid,), doneeid) |
|
148 |
self.commit() |
|
149 |
eschema = self.schema.eschema('Folder2') |
|
150 |
self.mh.cmd_drop_entity_type('Folder2') |
|
151 |
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
|
152 |
self.failIf(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 153 |
# test automatic workflow deletion |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
154 |
self.failIf(self.execute('Workflow X WHERE NOT X workflow_of ET')) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
155 |
self.failIf(self.execute('State X WHERE NOT X state_of WF')) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
156 |
self.failIf(self.execute('Transition X WHERE NOT X transition_of WF')) |
0 | 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_relation_type(self): |
0 | 159 |
self.mh.cmd_add_entity_type('Folder2', auto=False) |
160 |
self.mh.cmd_add_relation_type('filed_under2') |
|
161 |
self.failUnless('filed_under2' in self.schema) |
|
162 |
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
|
163 |
sorted(str(e) for e in self.schema.entities() if not e.is_final())) |
0 | 164 |
self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) |
165 |
self.mh.cmd_drop_relation_type('filed_under2') |
|
166 |
self.failIf('filed_under2' in self.schema) |
|
167 |
||
168 |
def test_add_relation_definition_nortype(self): |
|
169 |
self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire') |
|
170 |
self.assertEquals(self.schema['concerne2'].subjects(), |
|
171 |
('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
|
172 |
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
|
173 |
('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
|
174 |
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
|
175 |
'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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
self.failIf('concerne2' in self.schema) |
0 | 186 |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
190 |
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
|
191 |
['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
0 | 192 |
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
|
193 |
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
|
194 |
['Affaire']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
195 |
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
|
196 |
['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
|
197 |
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
|
198 |
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
|
199 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
200 |
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
|
201 |
['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
|
202 |
# 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
|
203 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
1787 | 204 |
|
0 | 205 |
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
|
206 |
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
|
207 |
['Affaire', 'Personne']) |
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'].objects()), |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
209 |
['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
0 | 210 |
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
|
211 |
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
|
212 |
['Affaire', 'Personne']) |
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'].objects()), |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
214 |
['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
|
215 |
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
|
216 |
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
|
217 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
218 |
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
|
219 |
['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
|
220 |
# 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
|
221 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
0 | 222 |
|
223 |
def test_rename_relation(self): |
|
224 |
self.skip('implement me') |
|
225 |
||
226 |
def test_change_relation_props_non_final(self): |
|
227 |
rschema = self.schema['concerne'] |
|
228 |
card = rschema.rproperty('Affaire', 'Societe', 'cardinality') |
|
229 |
self.assertEquals(card, '**') |
|
230 |
try: |
|
231 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
232 |
cardinality='?*') |
|
233 |
card = rschema.rproperty('Affaire', 'Societe', 'cardinality') |
|
234 |
self.assertEquals(card, '?*') |
|
235 |
finally: |
|
236 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
237 |
cardinality='**') |
|
1787 | 238 |
|
0 | 239 |
def test_change_relation_props_final(self): |
240 |
rschema = self.schema['adel'] |
|
241 |
card = rschema.rproperty('Personne', 'String', 'fulltextindexed') |
|
242 |
self.assertEquals(card, False) |
|
243 |
try: |
|
244 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
245 |
fulltextindexed=True) |
|
246 |
card = rschema.rproperty('Personne', 'String', 'fulltextindexed') |
|
247 |
self.assertEquals(card, True) |
|
248 |
finally: |
|
249 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
250 |
fulltextindexed=False) |
|
251 |
||
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
252 |
def test_sync_schema_props_perms(self): |
2903
043c8fcb3819
[migration] drop rqlcursor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
253 |
cursor = self.mh.session |
0 | 254 |
nbrqlexpr_start = len(cursor.execute('RQLExpression X')) |
255 |
migrschema['titre']._rproperties[('Personne', 'String')]['order'] = 7 |
|
256 |
migrschema['adel']._rproperties[('Personne', 'String')]['order'] = 6 |
|
257 |
migrschema['ass']._rproperties[('Personne', 'String')]['order'] = 5 |
|
258 |
migrschema['Personne'].description = 'blabla bla' |
|
1787 | 259 |
migrschema['titre'].description = 'usually a title' |
0 | 260 |
migrschema['titre']._rproperties[('Personne', 'String')]['description'] = 'title for this person' |
1787 | 261 |
self.mh.cmd_sync_schema_props_perms(commit=False) |
262 |
||
0 | 263 |
self.assertEquals(cursor.execute('Any D WHERE X name "Personne", X description D')[0][0], |
264 |
'blabla bla') |
|
265 |
self.assertEquals(cursor.execute('Any D WHERE X name "titre", X description D')[0][0], |
|
266 |
'usually a title') |
|
267 |
self.assertEquals(cursor.execute('Any D WHERE X relation_type RT, RT name "titre",' |
|
268 |
'X from_entity FE, FE name "Personne",' |
|
269 |
'X description D')[0][0], |
|
270 |
'title for this person') |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
271 |
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
|
272 |
'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
|
273 |
'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
|
274 |
'X ordernum O')] |
2930
d7c23b2c7538
some test fixes, more in the 3.5 branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
275 |
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
|
276 |
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
|
277 |
u'creation_date', 'cwuri', u'modification_date'] |
0 | 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 |
2903
043c8fcb3819
[migration] drop rqlcursor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
332 |
return self.mh.session.execute(rql, {'name': ertype}) |
0 | 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 |
2903
043c8fcb3819
[migration] drop rqlcursor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
339 |
return self.mh.session.execute(rql, {'name': ertype}) |
0 | 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 |
|
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2591
diff
changeset
|
360 |
self.assertEquals(sorted((str(s), str(o)) for s, o in schema['see_also']._rproperties.keys()), |
439 | 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() |