author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 03 Dec 2009 12:44:30 +0100 | |
branch | stable |
changeset 3987 | f85ef29f6214 |
parent 3689 | deb13e88e037 |
child 3720 | 5376aaadd16b |
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 |
|
3267
320a715e2a22
backport default fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3266
diff
changeset
|
48 |
|
0 | 49 |
def test_add_attribute_int(self): |
50 |
self.failIf('whatever' in self.schema) |
|
3543
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
51 |
self.add_entity('Note') |
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
52 |
self.commit() |
3134
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
53 |
orderdict = dict(self.mh.rqlexec('Any RTN, O WHERE X name "Note", RDEF from_entity X, ' |
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
54 |
'RDEF relation_type RT, RDEF ordernum O, RT name RTN')) |
0 | 55 |
self.mh.cmd_add_attribute('Note', 'whatever') |
56 |
self.failUnless('whatever' in self.schema) |
|
57 |
self.assertEquals(self.schema['whatever'].subjects(), ('Note',)) |
|
58 |
self.assertEquals(self.schema['whatever'].objects(), ('Int',)) |
|
3543
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
59 |
self.assertEquals(self.schema['Note'].default('whatever'), 2) |
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
60 |
note = self.execute('Note X').get_entity(0, 0) |
ed152fe5aa8b
[migration] when adding a new attribute with a default value, set this value on existing entities (test and fix)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
61 |
self.assertEquals(note.whatever, 2) |
3134
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
62 |
orderdict2 = dict(self.mh.rqlexec('Any RTN, O WHERE X name "Note", RDEF from_entity X, ' |
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
63 |
'RDEF relation_type RT, RDEF ordernum O, RT name RTN')) |
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
64 |
whateverorder = migrschema['whatever'].rproperty('Note', 'Int', 'order') |
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
65 |
for k, v in orderdict.iteritems(): |
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
66 |
if v >= whateverorder: |
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
67 |
orderdict[k] = v+1 |
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
68 |
orderdict['whatever'] = whateverorder |
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
69 |
self.assertDictEquals(orderdict, orderdict2) |
0 | 70 |
#self.assertEquals([r.type for r in self.schema['Note'].ordered_relations()], |
71 |
# ['modification_date', 'creation_date', 'owned_by', |
|
72 |
# 'eid', 'ecrit_par', 'inline1', 'date', 'type', |
|
3134
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
73 |
# 'whatever', 'date', 'in_basket']) |
0 | 74 |
# NB: commit instead of rollback make following test fail with py2.5 |
75 |
# this sounds like a pysqlite/2.5 bug (the same eid is affected to |
|
76 |
# two different entities) |
|
77 |
self.mh.rollback() |
|
78 |
||
79 |
def test_add_attribute_varchar(self): |
|
80 |
self.failIf('shortpara' in self.schema) |
|
81 |
self.mh.cmd_add_attribute('Note', 'shortpara') |
|
82 |
self.failUnless('shortpara' in self.schema) |
|
83 |
self.assertEquals(self.schema['shortpara'].subjects(), ('Note', )) |
|
84 |
self.assertEquals(self.schema['shortpara'].objects(), ('String', )) |
|
85 |
# 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
|
86 |
notesql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' and name='%sNote'" % SQL_PREFIX)[0][0] |
0 | 87 |
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
|
88 |
self.assertEquals(fields['%sshortpara' % SQL_PREFIX], 'varchar(64)') |
0 | 89 |
self.mh.rollback() |
1787 | 90 |
|
0 | 91 |
def test_add_datetime_with_default_value_attribute(self): |
92 |
self.failIf('mydate' in self.schema) |
|
2642 | 93 |
self.failIf('shortpara' in self.schema) |
0 | 94 |
self.mh.cmd_add_attribute('Note', 'mydate') |
95 |
self.failUnless('mydate' in self.schema) |
|
96 |
self.assertEquals(self.schema['mydate'].subjects(), ('Note', )) |
|
97 |
self.assertEquals(self.schema['mydate'].objects(), ('Date', )) |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
98 |
testdate = date(2005, 12, 13) |
0 | 99 |
eid1 = self.mh.rqlexec('INSERT Note N')[0][0] |
100 |
eid2 = self.mh.rqlexec('INSERT Note N: N mydate %(mydate)s', {'mydate' : testdate})[0][0] |
|
101 |
d1 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid1}, 'x')[0][0] |
|
102 |
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
|
103 |
self.assertEquals(d1, date.today()) |
0 | 104 |
self.assertEquals(d2, testdate) |
105 |
self.mh.rollback() |
|
1787 | 106 |
|
0 | 107 |
def test_rename_attribute(self): |
108 |
self.failIf('civility' in self.schema) |
|
109 |
eid1 = self.mh.rqlexec('INSERT Personne X: X nom "lui", X sexe "M"')[0][0] |
|
110 |
eid2 = self.mh.rqlexec('INSERT Personne X: X nom "l\'autre", X sexe NULL')[0][0] |
|
111 |
self.mh.cmd_rename_attribute('Personne', 'sexe', 'civility') |
|
112 |
self.failIf('sexe' in self.schema) |
|
113 |
self.failUnless('civility' in self.schema) |
|
114 |
# test data has been backported |
|
115 |
c1 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid1)[0][0] |
|
116 |
self.failUnlessEqual(c1, 'M') |
|
117 |
c2 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid2)[0][0] |
|
118 |
self.failUnlessEqual(c2, None) |
|
119 |
||
120 |
||
121 |
def test_workflow_actions(self): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
122 |
wf = self.mh.cmd_add_workflow(u'foo', ('Personne', 'Email')) |
0 | 123 |
for etype in ('Personne', 'Email'): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
124 |
s1 = self.mh.rqlexec('Any N WHERE WF workflow_of ET, ET name "%s", WF name N' % |
0 | 125 |
etype)[0][0] |
126 |
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
|
127 |
s1 = self.mh.rqlexec('Any N WHERE ET default_workflow WF, ET name "%s", WF name N' % |
0 | 128 |
etype)[0][0] |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
129 |
self.assertEquals(s1, "foo") |
1787 | 130 |
|
0 | 131 |
def test_add_entity_type(self): |
132 |
self.failIf('Folder2' in self.schema) |
|
133 |
self.failIf('filed_under2' in self.schema) |
|
134 |
self.mh.cmd_add_entity_type('Folder2') |
|
135 |
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
|
136 |
self.failUnless(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 137 |
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
|
138 |
self.failUnless(self.execute('CWRType X WHERE X name "filed_under2"')) |
3266
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
139 |
self.schema.rebuild_infered_relations() |
0 | 140 |
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
|
141 |
['created_by', 'creation_date', 'cwuri', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
142 |
'description', 'description_format', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
143 |
'eid', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
144 |
'filed_under2', 'has_text', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
145 |
'identity', 'in_basket', 'is', 'is_instance_of', |
0 | 146 |
'modification_date', 'name', 'owned_by']) |
147 |
self.assertEquals([str(rs) for rs in self.schema['Folder2'].object_relations()], |
|
148 |
['filed_under2', 'identity']) |
|
149 |
self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()), |
|
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
150 |
sorted(str(e) for e in self.schema.entities() if not e.final)) |
0 | 151 |
self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) |
152 |
eschema = self.schema.eschema('Folder2') |
|
153 |
for cstr in eschema.constraints('name'): |
|
154 |
self.failUnless(hasattr(cstr, 'eid')) |
|
155 |
||
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
156 |
def test_add_drop_entity_type(self): |
0 | 157 |
self.mh.cmd_add_entity_type('Folder2') |
3252
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
158 |
wf = self.mh.cmd_add_workflow(u'folder2 wf', 'Folder2') |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
159 |
todo = wf.add_state(u'todo', initial=True) |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
160 |
done = wf.add_state(u'done') |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
161 |
wf.add_transition(u'redoit', done, todo) |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
162 |
wf.add_transition(u'markasdone', todo, done) |
0 | 163 |
self.commit() |
164 |
eschema = self.schema.eschema('Folder2') |
|
165 |
self.mh.cmd_drop_entity_type('Folder2') |
|
166 |
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
|
167 |
self.failIf(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 168 |
# test automatic workflow deletion |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
169 |
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
|
170 |
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
|
171 |
self.failIf(self.execute('Transition X WHERE NOT X transition_of WF')) |
0 | 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') |
|
3266
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
176 |
self.schema.rebuild_infered_relations() |
0 | 177 |
self.failUnless('filed_under2' in self.schema) |
178 |
self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()), |
|
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
179 |
sorted(str(e) for e in self.schema.entities() if not e.final)) |
0 | 180 |
self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) |
181 |
self.mh.cmd_drop_relation_type('filed_under2') |
|
182 |
self.failIf('filed_under2' in self.schema) |
|
183 |
||
184 |
def test_add_relation_definition_nortype(self): |
|
185 |
self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire') |
|
186 |
self.assertEquals(self.schema['concerne2'].subjects(), |
|
187 |
('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
|
188 |
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
|
189 |
('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
|
190 |
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
|
191 |
'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
|
192 |
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
|
193 |
self.assertEquals(sorted(self.schema['concerne2'].objects()), ['Affaire', 'Note']) |
3252
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
194 |
self.mh.create_entity('Personne', nom=u'tot') |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
195 |
self.mh.create_entity('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
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
self.failIf('concerne2' in self.schema) |
0 | 202 |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
203 |
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
|
204 |
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
|
205 |
['Affaire', 'Personne']) |
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'].objects()), |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
207 |
['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
0 | 208 |
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
|
209 |
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
|
210 |
['Affaire']) |
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'].objects()), |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
212 |
['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
|
213 |
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
|
214 |
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
|
215 |
['Affaire', 'Personne']) |
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'].objects()), |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
217 |
['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
|
218 |
# 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
|
219 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
1787 | 220 |
|
0 | 221 |
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
|
222 |
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
|
223 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
224 |
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
|
225 |
['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
0 | 226 |
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
|
227 |
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
|
228 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
229 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), |
3266
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
230 |
['Affaire', 'Division', 'Note', 'SubDivision']) |
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
231 |
self.schema.rebuild_infered_relations() # need to be explicitly called once everything is in place |
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
232 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
233 |
['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
|
234 |
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
|
235 |
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
|
236 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
237 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), |
3266
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
238 |
['Affaire', 'Note', 'Societe']) |
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
239 |
self.schema.rebuild_infered_relations() # need to be explicitly called once everything is in place |
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
240 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
241 |
['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
|
242 |
# 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
|
243 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
0 | 244 |
|
245 |
def test_rename_relation(self): |
|
246 |
self.skip('implement me') |
|
247 |
||
248 |
def test_change_relation_props_non_final(self): |
|
249 |
rschema = self.schema['concerne'] |
|
250 |
card = rschema.rproperty('Affaire', 'Societe', 'cardinality') |
|
251 |
self.assertEquals(card, '**') |
|
252 |
try: |
|
253 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
254 |
cardinality='?*') |
|
255 |
card = rschema.rproperty('Affaire', 'Societe', 'cardinality') |
|
256 |
self.assertEquals(card, '?*') |
|
257 |
finally: |
|
258 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
259 |
cardinality='**') |
|
1787 | 260 |
|
0 | 261 |
def test_change_relation_props_final(self): |
262 |
rschema = self.schema['adel'] |
|
263 |
card = rschema.rproperty('Personne', 'String', 'fulltextindexed') |
|
264 |
self.assertEquals(card, False) |
|
265 |
try: |
|
266 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
267 |
fulltextindexed=True) |
|
268 |
card = rschema.rproperty('Personne', 'String', 'fulltextindexed') |
|
269 |
self.assertEquals(card, True) |
|
270 |
finally: |
|
271 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
272 |
fulltextindexed=False) |
|
273 |
||
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
274 |
def test_sync_schema_props_perms(self): |
2903
043c8fcb3819
[migration] drop rqlcursor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
275 |
cursor = self.mh.session |
0 | 276 |
nbrqlexpr_start = len(cursor.execute('RQLExpression X')) |
277 |
migrschema['titre']._rproperties[('Personne', 'String')]['order'] = 7 |
|
278 |
migrschema['adel']._rproperties[('Personne', 'String')]['order'] = 6 |
|
279 |
migrschema['ass']._rproperties[('Personne', 'String')]['order'] = 5 |
|
280 |
migrschema['Personne'].description = 'blabla bla' |
|
1787 | 281 |
migrschema['titre'].description = 'usually a title' |
0 | 282 |
migrschema['titre']._rproperties[('Personne', 'String')]['description'] = 'title for this person' |
1787 | 283 |
self.mh.cmd_sync_schema_props_perms(commit=False) |
284 |
||
0 | 285 |
self.assertEquals(cursor.execute('Any D WHERE X name "Personne", X description D')[0][0], |
286 |
'blabla bla') |
|
287 |
self.assertEquals(cursor.execute('Any D WHERE X name "titre", X description D')[0][0], |
|
288 |
'usually a title') |
|
289 |
self.assertEquals(cursor.execute('Any D WHERE X relation_type RT, RT name "titre",' |
|
290 |
'X from_entity FE, FE name "Personne",' |
|
291 |
'X description D')[0][0], |
|
292 |
'title for this person') |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
293 |
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
|
294 |
'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
|
295 |
'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
|
296 |
'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
|
297 |
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
|
298 |
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
|
299 |
u'creation_date', 'cwuri', u'modification_date'] |
0 | 300 |
self.assertEquals(rinorder, expected) |
301 |
||
302 |
# test permissions synchronization #################################### |
|
303 |
# new rql expr to add note entity |
|
304 |
eexpr = self._erqlexpr_entity('add', 'Note') |
|
305 |
self.assertEquals(eexpr.expression, |
|
306 |
'X ecrit_part PE, U in_group G, ' |
|
307 |
'PE require_permission P, P name "add_note", P require_group G') |
|
308 |
self.assertEquals([et.name for et in eexpr.reverse_add_permission], ['Note']) |
|
3587 | 309 |
self.assertEquals(eexpr.reverse_read_permission, ()) |
310 |
self.assertEquals(eexpr.reverse_delete_permission, ()) |
|
311 |
self.assertEquals(eexpr.reverse_update_permission, ()) |
|
0 | 312 |
# no more rqlexpr to delete and add para attribute |
313 |
self.failIf(self._rrqlexpr_rset('add', 'para')) |
|
314 |
self.failIf(self._rrqlexpr_rset('delete', 'para')) |
|
1787 | 315 |
# new rql expr to add ecrit_par relation |
0 | 316 |
rexpr = self._rrqlexpr_entity('add', 'ecrit_par') |
317 |
self.assertEquals(rexpr.expression, |
|
318 |
'O require_permission P, P name "add_note", ' |
|
319 |
'U in_group G, P require_group G') |
|
320 |
self.assertEquals([rt.name for rt in rexpr.reverse_add_permission], ['ecrit_par']) |
|
3587 | 321 |
self.assertEquals(rexpr.reverse_read_permission, ()) |
322 |
self.assertEquals(rexpr.reverse_delete_permission, ()) |
|
0 | 323 |
# no more rqlexpr to delete and add travaille relation |
324 |
self.failIf(self._rrqlexpr_rset('add', 'travaille')) |
|
325 |
self.failIf(self._rrqlexpr_rset('delete', 'travaille')) |
|
326 |
# no more rqlexpr to delete and update Societe entity |
|
327 |
self.failIf(self._erqlexpr_rset('update', 'Societe')) |
|
328 |
self.failIf(self._erqlexpr_rset('delete', 'Societe')) |
|
329 |
# no more rqlexpr to read Affaire entity |
|
330 |
self.failIf(self._erqlexpr_rset('read', 'Affaire')) |
|
331 |
# rqlexpr to update Affaire entity has been updated |
|
332 |
eexpr = self._erqlexpr_entity('update', 'Affaire') |
|
333 |
self.assertEquals(eexpr.expression, 'X concerne S, S owned_by U') |
|
334 |
# no change for rqlexpr to add and delete Affaire entity |
|
335 |
self.assertEquals(len(self._erqlexpr_rset('delete', 'Affaire')), 1) |
|
336 |
self.assertEquals(len(self._erqlexpr_rset('add', 'Affaire')), 1) |
|
337 |
# no change for rqlexpr to add and delete concerne relation |
|
338 |
self.assertEquals(len(self._rrqlexpr_rset('delete', 'concerne')), 1) |
|
339 |
self.assertEquals(len(self._rrqlexpr_rset('add', 'concerne')), 1) |
|
340 |
# * migrschema involve: |
|
341 |
# * 8 deletion (2 in Affaire read + Societe + travaille + para rqlexprs) |
|
342 |
# * 1 update (Affaire update) |
|
343 |
# * 2 new (Note add, ecrit_par add) |
|
344 |
# remaining orphan rql expr which should be deleted at commit (composite relation) |
|
345 |
self.assertEquals(len(cursor.execute('RQLExpression X WHERE NOT ET1 read_permission X, NOT ET2 add_permission X, ' |
|
346 |
'NOT ET3 delete_permission X, NOT ET4 update_permission X')), 8+1) |
|
347 |
# finally |
|
1787 | 348 |
self.assertEquals(len(cursor.execute('RQLExpression X')), nbrqlexpr_start + 1 + 2) |
349 |
||
0 | 350 |
self.mh.rollback() |
351 |
||
352 |
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
|
353 |
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
|
354 |
return self.mh.session.execute(rql, {'name': ertype}) |
0 | 355 |
def _erqlexpr_entity(self, action, ertype): |
356 |
rset = self._erqlexpr_rset(action, ertype) |
|
357 |
self.assertEquals(len(rset), 1) |
|
358 |
return rset.get_entity(0, 0) |
|
359 |
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
|
360 |
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
|
361 |
return self.mh.session.execute(rql, {'name': ertype}) |
0 | 362 |
def _rrqlexpr_entity(self, action, ertype): |
363 |
rset = self._rrqlexpr_rset(action, ertype) |
|
364 |
self.assertEquals(len(rset), 1) |
|
365 |
return rset.get_entity(0, 0) |
|
1787 | 366 |
|
0 | 367 |
def test_set_size_constraint(self): |
368 |
# existing previous value |
|
369 |
try: |
|
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', 'name', 128) |
0 | 371 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
372 |
self.mh.cmd_set_size_constraint('CWEType', 'name', 64) |
0 | 373 |
# non existing previous value |
374 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
375 |
self.mh.cmd_set_size_constraint('CWEType', 'description', 256) |
0 | 376 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
377 |
self.mh.cmd_set_size_constraint('CWEType', 'description', None) |
0 | 378 |
|
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
|
379 |
def test_add_remove_cube_and_deps(self): |
0 | 380 |
cubes = set(self.config.cubes()) |
381 |
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
|
382 |
self.assertEquals(sorted((str(s), str(o)) for s, o in schema['see_also']._rproperties.keys()), |
439 | 383 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
384 |
('Bookmark', 'Bookmark'), ('Bookmark', 'Note'), |
|
385 |
('Note', 'Note'), ('Note', 'Bookmark')])) |
|
0 | 386 |
try: |
439 | 387 |
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
|
388 |
self.mh.cmd_remove_cube('email', removedeps=True) |
439 | 389 |
# 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
|
390 |
self.failIf('email' in self.config.cubes()) |
3126
2a71f8ab667e
test cubes_path is updated as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
391 |
self.failIf(self.config.cube_dir('email') in self.config.cubes_path()) |
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
|
392 |
self.failIf('file' in self.config.cubes()) |
3126
2a71f8ab667e
test cubes_path is updated as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
393 |
self.failIf(self.config.cube_dir('file') in self.config.cubes_path()) |
1787 | 394 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', |
439 | 395 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
396 |
self.failIf(ertype in schema, ertype) |
|
397 |
self.assertEquals(sorted(schema['see_also']._rproperties.keys()), |
|
398 |
sorted([('Folder', 'Folder'), |
|
399 |
('Bookmark', 'Bookmark'), |
|
400 |
('Bookmark', 'Note'), |
|
401 |
('Note', 'Note'), |
|
402 |
('Note', 'Bookmark')])) |
|
403 |
self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'Folder', 'Note']) |
|
404 |
self.assertEquals(sorted(schema['see_also'].objects()), ['Bookmark', 'Folder', 'Note']) |
|
405 |
self.assertEquals(self.execute('Any X WHERE X pkey "system.version.email"').rowcount, 0) |
|
406 |
self.assertEquals(self.execute('Any X WHERE X pkey "system.version.file"').rowcount, 0) |
|
407 |
except : |
|
408 |
import traceback |
|
409 |
traceback.print_exc() |
|
410 |
raise |
|
0 | 411 |
finally: |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
412 |
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
|
413 |
self.failUnless('email' in self.config.cubes()) |
3126
2a71f8ab667e
test cubes_path is updated as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
414 |
self.failUnless(self.config.cube_dir('email') in self.config.cubes_path()) |
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 |
self.failUnless('file' in self.config.cubes()) |
3126
2a71f8ab667e
test cubes_path is updated as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
416 |
self.failUnless(self.config.cube_dir('file') in self.config.cubes_path()) |
1787 | 417 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', |
0 | 418 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
419 |
self.failUnless(ertype in schema, ertype) |
|
420 |
self.assertEquals(sorted(schema['see_also']._rproperties.keys()), |
|
439 | 421 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
422 |
('Bookmark', 'Bookmark'), |
|
423 |
('Bookmark', 'Note'), |
|
424 |
('Note', 'Note'), |
|
425 |
('Note', 'Bookmark')])) |
|
426 |
self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'EmailThread', 'Folder', 'Note']) |
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
email_version) |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
432 |
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
|
433 |
file_version) |
0 | 434 |
# trick: overwrite self.maxeid to avoid deletion of just reintroduced |
435 |
# types (and their associated tables!) |
|
436 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
|
437 |
# why this commit is necessary is unclear to me (though without it |
|
438 |
# next test may fail complaining of missing tables |
|
1787 | 439 |
self.commit() |
972 | 440 |
|
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
|
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_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
|
443 |
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
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
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
|
448 |
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
|
449 |
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
|
450 |
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
|
451 |
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
|
452 |
'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
|
453 |
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
|
454 |
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
|
455 |
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
|
456 |
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
|
457 |
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
|
458 |
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
|
459 |
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
|
460 |
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
|
461 |
# 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
|
462 |
# 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
|
463 |
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
|
464 |
# 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
|
465 |
# 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
|
466 |
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
|
467 |
|
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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
|
2963
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
472 |
def test_introduce_base_class(self): |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
473 |
self.mh.cmd_add_entity_type('Para') |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
474 |
self.mh.repo.schema.rebuild_infered_relations() |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
475 |
self.assertEquals(sorted(et.type for et in self.schema['Para'].specialized_by()), |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
476 |
['Note']) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
477 |
self.assertEquals(self.schema['Note'].specializes().type, 'Para') |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
478 |
self.mh.cmd_add_entity_type('Text') |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
479 |
self.mh.repo.schema.rebuild_infered_relations() |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
480 |
self.assertEquals(sorted(et.type for et in self.schema['Para'].specialized_by()), |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
481 |
['Note', 'Text']) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
482 |
self.assertEquals(self.schema['Text'].specializes().type, 'Para') |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
483 |
# test columns have been actually added |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
484 |
text = self.execute('INSERT Text X: X para "hip", X summary "hop", X newattr "momo"').get_entity(0, 0) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
485 |
note = self.execute('INSERT Note X: X para "hip", X shortpara "hop", X newattr "momo"').get_entity(0, 0) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
486 |
aff = self.execute('INSERT Affaire X').get_entity(0, 0) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
487 |
self.failUnless(self.execute('SET X newnotinlined Y WHERE X eid %(x)s, Y eid %(y)s', |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
488 |
{'x': text.eid, 'y': aff.eid}, 'x')) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
489 |
self.failUnless(self.execute('SET X newnotinlined Y WHERE X eid %(x)s, Y eid %(y)s', |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
490 |
{'x': note.eid, 'y': aff.eid}, 'x')) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
491 |
self.failUnless(self.execute('SET X newinlined Y WHERE X eid %(x)s, Y eid %(y)s', |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
492 |
{'x': text.eid, 'y': aff.eid}, 'x')) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
493 |
self.failUnless(self.execute('SET X newinlined Y WHERE X eid %(x)s, Y eid %(y)s', |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
494 |
{'x': note.eid, 'y': aff.eid}, 'x')) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
495 |
# XXX remove specializes by ourselves, else tearDown fails when removing |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
496 |
# Para because of Note inheritance. This could be fixed by putting the |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
497 |
# MemSchemaCWETypeDel(session, name) operation in the |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
498 |
# after_delete_entity(CWEType) hook, since in that case the MemSchemaSpecializesDel |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
499 |
# operation would be removed before, but I'm not sure this is a desired behaviour. |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
500 |
# |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
501 |
# also we need more tests about introducing/removing base classes or |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
502 |
# specialization relationship... |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
503 |
self.session.data['rebuild-infered'] = True |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
504 |
try: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
505 |
self.execute('DELETE X specializes Y WHERE Y name "Para"') |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
506 |
self.commit() |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
507 |
finally: |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
508 |
self.session.data['rebuild-infered'] = False |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
509 |
self.assertEquals(sorted(et.type for et in self.schema['Para'].specialized_by()), |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
510 |
[]) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
511 |
self.assertEquals(self.schema['Note'].specializes(), None) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
512 |
self.assertEquals(self.schema['Text'].specializes(), None) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
513 |
|
0 | 514 |
if __name__ == '__main__': |
515 |
unittest_main() |