author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 31 Mar 2010 15:59:32 +0200 | |
branch | stable |
changeset 5122 | c06078d59e87 |
parent 4774 | 89a7555020ba |
child 5174 | 78438ad513ca |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
0 | 1 |
"""unit tests for module cubicweb.server.migractions |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
2 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 3 |
""" |
4 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
5 |
from copy import deepcopy |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
6 |
from datetime import date |
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2591
diff
changeset
|
7 |
from os.path import join |
0 | 8 |
|
9 |
from logilab.common.testlib import TestCase, unittest_main |
|
10 |
||
2124
5a0b02f37b23
set removedeps to False by default, raise an exception instead of a simple assertion for error, more remove_cube tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
11 |
from cubicweb import ConfigurationError |
4689
4eb1f4490538
[test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4681
diff
changeset
|
12 |
from cubicweb.devtools.testlib import CubicWebTC |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
13 |
from cubicweb.schema import CubicWebSchemaLoader |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
14 |
from cubicweb.server.sqlutils import SQL_PREFIX |
0 | 15 |
from cubicweb.server.migractions import * |
16 |
||
4774
89a7555020ba
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4763
diff
changeset
|
17 |
migrschema = None |
89a7555020ba
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4763
diff
changeset
|
18 |
def teardown_module(*args): |
89a7555020ba
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4763
diff
changeset
|
19 |
global migrschema |
89a7555020ba
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4763
diff
changeset
|
20 |
del migrschema |
89a7555020ba
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4763
diff
changeset
|
21 |
del MigrationCommandsTC.origschema |
1787 | 22 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
23 |
class MigrationCommandsTC(CubicWebTC): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
24 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
25 |
@classmethod |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
26 |
def init_config(cls, config): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
27 |
super(MigrationCommandsTC, cls).init_config(config) |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4635
diff
changeset
|
28 |
# we have to read schema from the database to get eid for schema entities |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
29 |
config._cubes = None |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
30 |
cls.repo.fill_schema() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
31 |
cls.origschema = deepcopy(cls.repo.schema) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
32 |
# hack to read the schema from data/migrschema |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
33 |
config.appid = join('data', 'migratedapp') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
34 |
global migrschema |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
35 |
migrschema = config.load_schema() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
36 |
config.appid = 'data' |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
37 |
assert 'Folder' in migrschema |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
38 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
39 |
@classmethod |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
40 |
def _refresh_repo(cls): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
41 |
super(MigrationCommandsTC, cls)._refresh_repo() |
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
42 |
cls.repo.set_schema(deepcopy(cls.origschema), resetvreg=False) |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
43 |
# reset migration schema eids |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
44 |
for eschema in migrschema.entities(): |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
45 |
eschema.eid = None |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
46 |
for rschema in migrschema.relations(): |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
47 |
rschema.eid = None |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
48 |
for rdef in rschema.rdefs.values(): |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
49 |
rdef.eid = None |
1787 | 50 |
|
0 | 51 |
def setUp(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
52 |
CubicWebTC.setUp(self) |
0 | 53 |
self.mh = ServerMigrationHelper(self.repo.config, migrschema, |
54 |
repo=self.repo, cnx=self.cnx, |
|
55 |
interactive=False) |
|
972 | 56 |
assert self.cnx is self.mh._cnx |
57 |
assert self.session is self.mh.session, (self.session.id, self.mh.session.id) |
|
1787 | 58 |
|
0 | 59 |
def test_add_attribute_int(self): |
60 |
self.failIf('whatever' in self.schema) |
|
4100 | 61 |
self.request().create_entity('Note') |
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
|
62 |
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
|
63 |
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
|
64 |
'RDEF relation_type RT, RDEF ordernum O, RT name RTN')) |
0 | 65 |
self.mh.cmd_add_attribute('Note', 'whatever') |
66 |
self.failUnless('whatever' in self.schema) |
|
67 |
self.assertEquals(self.schema['whatever'].subjects(), ('Note',)) |
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
'RDEF relation_type RT, RDEF ordernum O, RT name RTN')) |
4100 | 74 |
whateverorder = migrschema['whatever'].rdef('Note', 'Int').order |
3134
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
self.assertDictEquals(orderdict, orderdict2) |
0 | 80 |
#self.assertEquals([r.type for r in self.schema['Note'].ordered_relations()], |
81 |
# ['modification_date', 'creation_date', 'owned_by', |
|
82 |
# '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
|
83 |
# 'whatever', 'date', 'in_basket']) |
0 | 84 |
# NB: commit instead of rollback make following test fail with py2.5 |
85 |
# this sounds like a pysqlite/2.5 bug (the same eid is affected to |
|
86 |
# two different entities) |
|
87 |
self.mh.rollback() |
|
88 |
||
89 |
def test_add_attribute_varchar(self): |
|
90 |
self.failIf('shortpara' in self.schema) |
|
91 |
self.mh.cmd_add_attribute('Note', 'shortpara') |
|
92 |
self.failUnless('shortpara' in self.schema) |
|
93 |
self.assertEquals(self.schema['shortpara'].subjects(), ('Note', )) |
|
94 |
self.assertEquals(self.schema['shortpara'].objects(), ('String', )) |
|
95 |
# 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
|
96 |
notesql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' and name='%sNote'" % SQL_PREFIX)[0][0] |
0 | 97 |
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
|
98 |
self.assertEquals(fields['%sshortpara' % SQL_PREFIX], 'varchar(64)') |
0 | 99 |
self.mh.rollback() |
1787 | 100 |
|
0 | 101 |
def test_add_datetime_with_default_value_attribute(self): |
102 |
self.failIf('mydate' in self.schema) |
|
2642 | 103 |
self.failIf('shortpara' in self.schema) |
0 | 104 |
self.mh.cmd_add_attribute('Note', 'mydate') |
105 |
self.failUnless('mydate' in self.schema) |
|
106 |
self.assertEquals(self.schema['mydate'].subjects(), ('Note', )) |
|
107 |
self.assertEquals(self.schema['mydate'].objects(), ('Date', )) |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
108 |
testdate = date(2005, 12, 13) |
0 | 109 |
eid1 = self.mh.rqlexec('INSERT Note N')[0][0] |
110 |
eid2 = self.mh.rqlexec('INSERT Note N: N mydate %(mydate)s', {'mydate' : testdate})[0][0] |
|
111 |
d1 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid1}, 'x')[0][0] |
|
112 |
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
|
113 |
self.assertEquals(d1, date.today()) |
0 | 114 |
self.assertEquals(d2, testdate) |
115 |
self.mh.rollback() |
|
1787 | 116 |
|
0 | 117 |
def test_rename_attribute(self): |
118 |
self.failIf('civility' in self.schema) |
|
119 |
eid1 = self.mh.rqlexec('INSERT Personne X: X nom "lui", X sexe "M"')[0][0] |
|
120 |
eid2 = self.mh.rqlexec('INSERT Personne X: X nom "l\'autre", X sexe NULL')[0][0] |
|
121 |
self.mh.cmd_rename_attribute('Personne', 'sexe', 'civility') |
|
122 |
self.failIf('sexe' in self.schema) |
|
123 |
self.failUnless('civility' in self.schema) |
|
124 |
# test data has been backported |
|
125 |
c1 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid1)[0][0] |
|
126 |
self.failUnlessEqual(c1, 'M') |
|
127 |
c2 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid2)[0][0] |
|
128 |
self.failUnlessEqual(c2, None) |
|
129 |
||
130 |
||
131 |
def test_workflow_actions(self): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
132 |
wf = self.mh.cmd_add_workflow(u'foo', ('Personne', 'Email')) |
0 | 133 |
for etype in ('Personne', 'Email'): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
134 |
s1 = self.mh.rqlexec('Any N WHERE WF workflow_of ET, ET name "%s", WF name N' % |
0 | 135 |
etype)[0][0] |
136 |
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
|
137 |
s1 = self.mh.rqlexec('Any N WHERE ET default_workflow WF, ET name "%s", WF name N' % |
0 | 138 |
etype)[0][0] |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
139 |
self.assertEquals(s1, "foo") |
1787 | 140 |
|
0 | 141 |
def test_add_entity_type(self): |
142 |
self.failIf('Folder2' in self.schema) |
|
143 |
self.failIf('filed_under2' in self.schema) |
|
144 |
self.mh.cmd_add_entity_type('Folder2') |
|
145 |
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
|
146 |
self.failUnless(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 147 |
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
|
148 |
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
|
149 |
self.schema.rebuild_infered_relations() |
0 | 150 |
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
|
151 |
['created_by', 'creation_date', 'cwuri', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
152 |
'description', 'description_format', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
153 |
'eid', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
154 |
'filed_under2', 'has_text', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
155 |
'identity', 'in_basket', 'is', 'is_instance_of', |
0 | 156 |
'modification_date', 'name', 'owned_by']) |
157 |
self.assertEquals([str(rs) for rs in self.schema['Folder2'].object_relations()], |
|
158 |
['filed_under2', 'identity']) |
|
159 |
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
|
160 |
sorted(str(e) for e in self.schema.entities() if not e.final)) |
0 | 161 |
self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) |
162 |
eschema = self.schema.eschema('Folder2') |
|
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
163 |
for cstr in eschema.rdef('name').constraints: |
0 | 164 |
self.failUnless(hasattr(cstr, 'eid')) |
165 |
||
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
166 |
def test_add_drop_entity_type(self): |
0 | 167 |
self.mh.cmd_add_entity_type('Folder2') |
3252
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
168 |
wf = self.mh.cmd_add_workflow(u'folder2 wf', 'Folder2') |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
169 |
todo = wf.add_state(u'todo', initial=True) |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
170 |
done = wf.add_state(u'done') |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
171 |
wf.add_transition(u'redoit', done, todo) |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
172 |
wf.add_transition(u'markasdone', todo, done) |
0 | 173 |
self.commit() |
174 |
eschema = self.schema.eschema('Folder2') |
|
175 |
self.mh.cmd_drop_entity_type('Folder2') |
|
176 |
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
|
177 |
self.failIf(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 178 |
# test automatic workflow deletion |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
self.failIf(self.execute('Transition X WHERE NOT X transition_of WF')) |
0 | 182 |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
183 |
def test_add_drop_relation_type(self): |
0 | 184 |
self.mh.cmd_add_entity_type('Folder2', auto=False) |
185 |
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
|
186 |
self.schema.rebuild_infered_relations() |
0 | 187 |
self.failUnless('filed_under2' in self.schema) |
188 |
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
|
189 |
sorted(str(e) for e in self.schema.entities() if not e.final)) |
0 | 190 |
self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) |
191 |
self.mh.cmd_drop_relation_type('filed_under2') |
|
192 |
self.failIf('filed_under2' in self.schema) |
|
193 |
||
194 |
def test_add_relation_definition_nortype(self): |
|
195 |
self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire') |
|
196 |
self.assertEquals(self.schema['concerne2'].subjects(), |
|
197 |
('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
|
198 |
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
|
199 |
('Affaire', )) |
4100 | 200 |
self.assertEquals(self.schema['concerne2'].rdef('Personne', 'Affaire').cardinality, |
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
|
201 |
'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
|
202 |
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
|
203 |
self.assertEquals(sorted(self.schema['concerne2'].objects()), ['Affaire', 'Note']) |
3252
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
204 |
self.mh.create_entity('Personne', nom=u'tot') |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
self.failIf('concerne2' in self.schema) |
0 | 212 |
|
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 |
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
|
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']) |
0 | 218 |
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
|
219 |
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
|
220 |
['Affaire']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
221 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
222 |
['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
|
223 |
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
|
224 |
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
|
225 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
226 |
self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
227 |
['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
|
228 |
# 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
|
229 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
1787 | 230 |
|
0 | 231 |
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
|
232 |
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
|
233 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
234 |
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
|
235 |
['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
0 | 236 |
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
|
237 |
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
|
238 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
239 |
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
|
240 |
['Affaire', 'Division', 'Note', 'SubDivision']) |
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
241 |
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
|
242 |
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
|
243 |
['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
|
244 |
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
|
245 |
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
|
246 |
['Affaire', 'Personne']) |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
247 |
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
|
248 |
['Affaire', 'Note', 'Societe']) |
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
249 |
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
|
250 |
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
|
251 |
['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
|
252 |
# 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
|
253 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
0 | 254 |
|
255 |
def test_rename_relation(self): |
|
256 |
self.skip('implement me') |
|
257 |
||
258 |
def test_change_relation_props_non_final(self): |
|
259 |
rschema = self.schema['concerne'] |
|
4100 | 260 |
card = rschema.rdef('Affaire', 'Societe').cardinality |
0 | 261 |
self.assertEquals(card, '**') |
262 |
try: |
|
263 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
264 |
cardinality='?*') |
|
4100 | 265 |
card = rschema.rdef('Affaire', 'Societe').cardinality |
0 | 266 |
self.assertEquals(card, '?*') |
267 |
finally: |
|
268 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
269 |
cardinality='**') |
|
1787 | 270 |
|
0 | 271 |
def test_change_relation_props_final(self): |
272 |
rschema = self.schema['adel'] |
|
4100 | 273 |
card = rschema.rdef('Personne', 'String').fulltextindexed |
0 | 274 |
self.assertEquals(card, False) |
275 |
try: |
|
276 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
277 |
fulltextindexed=True) |
|
4100 | 278 |
card = rschema.rdef('Personne', 'String').fulltextindexed |
0 | 279 |
self.assertEquals(card, True) |
280 |
finally: |
|
281 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
282 |
fulltextindexed=False) |
|
283 |
||
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
284 |
def test_sync_schema_props_perms(self): |
2903
043c8fcb3819
[migration] drop rqlcursor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
285 |
cursor = self.mh.session |
4100 | 286 |
cursor.set_pool() |
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
287 |
nbrqlexpr_start = cursor.execute('Any COUNT(X) WHERE X is RQLExpression')[0][0] |
4100 | 288 |
migrschema['titre'].rdefs[('Personne', 'String')].order = 7 |
289 |
migrschema['adel'].rdefs[('Personne', 'String')].order = 6 |
|
290 |
migrschema['ass'].rdefs[('Personne', 'String')].order = 5 |
|
0 | 291 |
migrschema['Personne'].description = 'blabla bla' |
1787 | 292 |
migrschema['titre'].description = 'usually a title' |
4103
dc04bede3502
yams api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4100
diff
changeset
|
293 |
migrschema['titre'].rdefs[('Personne', 'String')].description = 'title for this person' |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4103
diff
changeset
|
294 |
delete_concerne_rqlexpr = self._rrqlexpr_rset('delete', 'concerne') |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4103
diff
changeset
|
295 |
add_concerne_rqlexpr = self._rrqlexpr_rset('add', 'concerne') |
1787 | 296 |
self.mh.cmd_sync_schema_props_perms(commit=False) |
297 |
||
0 | 298 |
self.assertEquals(cursor.execute('Any D WHERE X name "Personne", X description D')[0][0], |
299 |
'blabla bla') |
|
300 |
self.assertEquals(cursor.execute('Any D WHERE X name "titre", X description D')[0][0], |
|
301 |
'usually a title') |
|
302 |
self.assertEquals(cursor.execute('Any D WHERE X relation_type RT, RT name "titre",' |
|
303 |
'X from_entity FE, FE name "Personne",' |
|
304 |
'X description D')[0][0], |
|
305 |
'title for this person') |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
306 |
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
|
307 |
'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
|
308 |
'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
|
309 |
'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
|
310 |
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
|
311 |
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
|
312 |
u'creation_date', 'cwuri', u'modification_date'] |
0 | 313 |
self.assertEquals(rinorder, expected) |
314 |
||
315 |
# test permissions synchronization #################################### |
|
316 |
# new rql expr to add note entity |
|
317 |
eexpr = self._erqlexpr_entity('add', 'Note') |
|
318 |
self.assertEquals(eexpr.expression, |
|
319 |
'X ecrit_part PE, U in_group G, ' |
|
320 |
'PE require_permission P, P name "add_note", P require_group G') |
|
321 |
self.assertEquals([et.name for et in eexpr.reverse_add_permission], ['Note']) |
|
3587 | 322 |
self.assertEquals(eexpr.reverse_read_permission, ()) |
323 |
self.assertEquals(eexpr.reverse_delete_permission, ()) |
|
324 |
self.assertEquals(eexpr.reverse_update_permission, ()) |
|
0 | 325 |
# no more rqlexpr to delete and add para attribute |
326 |
self.failIf(self._rrqlexpr_rset('add', 'para')) |
|
327 |
self.failIf(self._rrqlexpr_rset('delete', 'para')) |
|
1787 | 328 |
# new rql expr to add ecrit_par relation |
0 | 329 |
rexpr = self._rrqlexpr_entity('add', 'ecrit_par') |
330 |
self.assertEquals(rexpr.expression, |
|
331 |
'O require_permission P, P name "add_note", ' |
|
332 |
'U in_group G, P require_group G') |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4103
diff
changeset
|
333 |
self.assertEquals([rdef.rtype.name for rdef in rexpr.reverse_add_permission], ['ecrit_par']) |
3587 | 334 |
self.assertEquals(rexpr.reverse_read_permission, ()) |
335 |
self.assertEquals(rexpr.reverse_delete_permission, ()) |
|
0 | 336 |
# no more rqlexpr to delete and add travaille relation |
337 |
self.failIf(self._rrqlexpr_rset('add', 'travaille')) |
|
338 |
self.failIf(self._rrqlexpr_rset('delete', 'travaille')) |
|
339 |
# no more rqlexpr to delete and update Societe entity |
|
340 |
self.failIf(self._erqlexpr_rset('update', 'Societe')) |
|
341 |
self.failIf(self._erqlexpr_rset('delete', 'Societe')) |
|
342 |
# no more rqlexpr to read Affaire entity |
|
343 |
self.failIf(self._erqlexpr_rset('read', 'Affaire')) |
|
344 |
# rqlexpr to update Affaire entity has been updated |
|
345 |
eexpr = self._erqlexpr_entity('update', 'Affaire') |
|
346 |
self.assertEquals(eexpr.expression, 'X concerne S, S owned_by U') |
|
347 |
# no change for rqlexpr to add and delete Affaire entity |
|
348 |
self.assertEquals(len(self._erqlexpr_rset('delete', 'Affaire')), 1) |
|
349 |
self.assertEquals(len(self._erqlexpr_rset('add', 'Affaire')), 1) |
|
350 |
# no change for rqlexpr to add and delete concerne relation |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4103
diff
changeset
|
351 |
self.assertEquals(len(self._rrqlexpr_rset('delete', 'concerne')), len(delete_concerne_rqlexpr)) |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4103
diff
changeset
|
352 |
self.assertEquals(len(self._rrqlexpr_rset('add', 'concerne')), len(add_concerne_rqlexpr)) |
0 | 353 |
# * migrschema involve: |
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
354 |
# * 7 rqlexprs deletion (2 in (Affaire read + Societe + travaille) + 1 |
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
355 |
# in para attribute) |
0 | 356 |
# * 1 update (Affaire update) |
357 |
# * 2 new (Note add, ecrit_par add) |
|
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
358 |
# * 2 implicit new for attributes update_permission (Note.para, Personne.test) |
0 | 359 |
# remaining orphan rql expr which should be deleted at commit (composite relation) |
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
360 |
self.assertEquals(cursor.execute('Any COUNT(X) WHERE X is RQLExpression, ' |
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
361 |
'NOT ET1 read_permission X, NOT ET2 add_permission X, ' |
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
362 |
'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0], |
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
363 |
7+1) |
0 | 364 |
# finally |
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
365 |
self.assertEquals(cursor.execute('Any COUNT(X) WHERE X is RQLExpression')[0][0], |
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
366 |
nbrqlexpr_start + 1 + 2 + 2) |
1787 | 367 |
|
0 | 368 |
self.mh.rollback() |
369 |
||
370 |
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
|
371 |
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
|
372 |
return self.mh.session.execute(rql, {'name': ertype}) |
0 | 373 |
def _erqlexpr_entity(self, action, ertype): |
374 |
rset = self._erqlexpr_rset(action, ertype) |
|
375 |
self.assertEquals(len(rset), 1) |
|
376 |
return rset.get_entity(0, 0) |
|
377 |
def _rrqlexpr_rset(self, action, ertype): |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4103
diff
changeset
|
378 |
rql = 'RQLExpression X WHERE RT is CWRType, RDEF %s_permission X, RT name %%(name)s, RDEF relation_type RT' % action |
2903
043c8fcb3819
[migration] drop rqlcursor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
379 |
return self.mh.session.execute(rql, {'name': ertype}) |
0 | 380 |
def _rrqlexpr_entity(self, action, ertype): |
381 |
rset = self._rrqlexpr_rset(action, ertype) |
|
382 |
self.assertEquals(len(rset), 1) |
|
383 |
return rset.get_entity(0, 0) |
|
1787 | 384 |
|
0 | 385 |
def test_set_size_constraint(self): |
386 |
# existing previous value |
|
387 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
388 |
self.mh.cmd_set_size_constraint('CWEType', 'name', 128) |
0 | 389 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
390 |
self.mh.cmd_set_size_constraint('CWEType', 'name', 64) |
0 | 391 |
# non existing previous value |
392 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
393 |
self.mh.cmd_set_size_constraint('CWEType', 'description', 256) |
0 | 394 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
395 |
self.mh.cmd_set_size_constraint('CWEType', 'description', None) |
0 | 396 |
|
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
|
397 |
def test_add_remove_cube_and_deps(self): |
0 | 398 |
cubes = set(self.config.cubes()) |
399 |
schema = self.repo.schema |
|
4100 | 400 |
self.assertEquals(sorted((str(s), str(o)) for s, o in schema['see_also'].rdefs.keys()), |
439 | 401 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
402 |
('Bookmark', 'Bookmark'), ('Bookmark', 'Note'), |
|
403 |
('Note', 'Note'), ('Note', 'Bookmark')])) |
|
0 | 404 |
try: |
439 | 405 |
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
|
406 |
self.mh.cmd_remove_cube('email', removedeps=True) |
439 | 407 |
# 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
|
408 |
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
|
409 |
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
|
410 |
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
|
411 |
self.failIf(self.config.cube_dir('file') in self.config.cubes_path()) |
1787 | 412 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', |
439 | 413 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
414 |
self.failIf(ertype in schema, ertype) |
|
4100 | 415 |
self.assertEquals(sorted(schema['see_also'].rdefs.keys()), |
439 | 416 |
sorted([('Folder', 'Folder'), |
417 |
('Bookmark', 'Bookmark'), |
|
418 |
('Bookmark', 'Note'), |
|
419 |
('Note', 'Note'), |
|
420 |
('Note', 'Bookmark')])) |
|
421 |
self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'Folder', 'Note']) |
|
422 |
self.assertEquals(sorted(schema['see_also'].objects()), ['Bookmark', 'Folder', 'Note']) |
|
423 |
self.assertEquals(self.execute('Any X WHERE X pkey "system.version.email"').rowcount, 0) |
|
424 |
self.assertEquals(self.execute('Any X WHERE X pkey "system.version.file"').rowcount, 0) |
|
425 |
except : |
|
426 |
import traceback |
|
427 |
traceback.print_exc() |
|
428 |
raise |
|
0 | 429 |
finally: |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
430 |
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
|
431 |
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
|
432 |
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
|
433 |
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
|
434 |
self.failUnless(self.config.cube_dir('file') in self.config.cubes_path()) |
1787 | 435 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', |
0 | 436 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
437 |
self.failUnless(ertype in schema, ertype) |
|
4100 | 438 |
self.assertEquals(sorted(schema['see_also'].rdefs.keys()), |
439 | 439 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
440 |
('Bookmark', 'Bookmark'), |
|
441 |
('Bookmark', 'Note'), |
|
442 |
('Note', 'Note'), |
|
443 |
('Note', 'Bookmark')])) |
|
444 |
self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'EmailThread', 'Folder', 'Note']) |
|
445 |
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
|
446 |
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
|
447 |
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
|
448 |
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
|
449 |
email_version) |
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
450 |
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
|
451 |
file_version) |
0 | 452 |
# trick: overwrite self.maxeid to avoid deletion of just reintroduced |
453 |
# types (and their associated tables!) |
|
454 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
|
455 |
# why this commit is necessary is unclear to me (though without it |
|
456 |
# next test may fail complaining of missing tables |
|
1787 | 457 |
self.commit() |
972 | 458 |
|
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
|
459 |
|
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 |
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
|
461 |
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
|
462 |
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
|
463 |
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
|
464 |
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
|
465 |
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
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
'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
|
471 |
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
|
472 |
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
|
473 |
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
|
474 |
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
|
475 |
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
|
476 |
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
|
477 |
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
|
478 |
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
|
479 |
# 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
|
480 |
# 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
|
481 |
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
|
482 |
# 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
|
483 |
# 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
|
484 |
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
|
485 |
|
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
|
486 |
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
|
487 |
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
|
488 |
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
|
489 |
|
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
|
490 |
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
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
['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
|
495 |
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
|
496 |
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
|
497 |
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
|
498 |
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
|
499 |
['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
|
500 |
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
|
501 |
# 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
|
502 |
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
|
503 |
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
|
504 |
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
|
505 |
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
|
506 |
{'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
|
507 |
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
|
508 |
{'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
|
509 |
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
|
510 |
{'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
|
511 |
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
|
512 |
{'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
|
513 |
# 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
|
514 |
# 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
|
515 |
# 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
|
516 |
# 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
|
517 |
# 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
|
518 |
# |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
519 |
# 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
|
520 |
# 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
|
521 |
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
|
522 |
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
|
523 |
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
|
524 |
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
|
525 |
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
|
526 |
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
|
527 |
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
|
528 |
[]) |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
529 |
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
|
530 |
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
|
531 |
|
0 | 532 |
if __name__ == '__main__': |
533 |
unittest_main() |