author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 07 Jul 2011 18:33:21 +0200 | |
changeset 7637 | a8a3fcdb1f6e |
parent 7398 | 26695dd703d8 |
child 7791 | 31bb51ea5485 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6595
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
18 |
"""unit tests for module cubicweb.server.migractions""" |
0 | 19 |
|
6292
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
20 |
from __future__ import with_statement |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
21 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
22 |
from copy import deepcopy |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
23 |
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
|
24 |
from os.path import join |
0 | 25 |
|
7073
4ce9e536dd66
[test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6816
diff
changeset
|
26 |
from logilab.common.testlib import TestCase, unittest_main, Tags, tag |
0 | 27 |
|
6292
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
28 |
from yams.constraints import UniqueConstraint |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
29 |
|
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
30 |
from cubicweb import ConfigurationError, ValidationError |
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
|
31 |
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
|
32 |
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
|
33 |
from cubicweb.server.sqlutils import SQL_PREFIX |
0 | 34 |
from cubicweb.server.migractions import * |
35 |
||
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
|
36 |
migrschema = None |
6781
5062d86d6ffe
[unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6635
diff
changeset
|
37 |
def tearDownModule(*args): |
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
|
38 |
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
|
39 |
del migrschema |
7073
4ce9e536dd66
[test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6816
diff
changeset
|
40 |
if hasattr(MigrationCommandsTC, 'origschema'): |
4ce9e536dd66
[test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6816
diff
changeset
|
41 |
del MigrationCommandsTC.origschema |
1787 | 42 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
43 |
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
|
44 |
|
7073
4ce9e536dd66
[test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6816
diff
changeset
|
45 |
tags = CubicWebTC.tags | Tags(('server', 'migration', 'migractions')) |
4ce9e536dd66
[test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6816
diff
changeset
|
46 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
47 |
@classmethod |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7073
diff
changeset
|
48 |
def _init_repo(cls): |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7073
diff
changeset
|
49 |
super(MigrationCommandsTC, cls)._init_repo() |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4635
diff
changeset
|
50 |
# we have to read schema from the database to get eid for schema entities |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7073
diff
changeset
|
51 |
config = cls.config |
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 |
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
|
53 |
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
|
54 |
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
|
55 |
# 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
|
56 |
config.appid = join('data', 'migratedapp') |
6595
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
57 |
config._apphome = cls.datapath('migratedapp') |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
config.appid = 'data' |
6595
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
61 |
config._apphome = cls.datadir |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
62 |
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
|
63 |
|
0 | 64 |
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
|
65 |
CubicWebTC.setUp(self) |
0 | 66 |
self.mh = ServerMigrationHelper(self.repo.config, migrschema, |
67 |
repo=self.repo, cnx=self.cnx, |
|
68 |
interactive=False) |
|
972 | 69 |
assert self.cnx is self.mh._cnx |
70 |
assert self.session is self.mh.session, (self.session.id, self.mh.session.id) |
|
1787 | 71 |
|
6795
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6790
diff
changeset
|
72 |
def tearDown(self): |
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6790
diff
changeset
|
73 |
CubicWebTC.tearDown(self) |
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6790
diff
changeset
|
74 |
self.repo.vreg['etypes'].clear_caches() |
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6790
diff
changeset
|
75 |
|
0 | 76 |
def test_add_attribute_int(self): |
77 |
self.failIf('whatever' in self.schema) |
|
4100 | 78 |
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
|
79 |
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
|
80 |
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
|
81 |
'RDEF relation_type RT, RDEF ordernum O, RT name RTN')) |
0 | 82 |
self.mh.cmd_add_attribute('Note', 'whatever') |
83 |
self.failUnless('whatever' in self.schema) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
84 |
self.assertEqual(self.schema['whatever'].subjects(), ('Note',)) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
85 |
self.assertEqual(self.schema['whatever'].objects(), ('Int',)) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
86 |
self.assertEqual(self.schema['Note'].default('whatever'), 2) |
6795
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6790
diff
changeset
|
87 |
# test default value set on existing entities |
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
|
88 |
note = self.execute('Note X').get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
89 |
self.assertEqual(note.whatever, 2) |
6795
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6790
diff
changeset
|
90 |
# test default value set for next entities |
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6790
diff
changeset
|
91 |
self.assertEqual(self.request().create_entity('Note').whatever, 2) |
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6790
diff
changeset
|
92 |
# test attribute order |
3134
3cda74b5534c
update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3126
diff
changeset
|
93 |
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
|
94 |
'RDEF relation_type RT, RDEF ordernum O, RT name RTN')) |
4100 | 95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
orderdict['whatever'] = whateverorder |
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
100 |
self.assertDictEqual(orderdict, orderdict2) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
101 |
#self.assertEqual([r.type for r in self.schema['Note'].ordered_relations()], |
0 | 102 |
# ['modification_date', 'creation_date', 'owned_by', |
103 |
# '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
|
104 |
# 'whatever', 'date', 'in_basket']) |
0 | 105 |
# NB: commit instead of rollback make following test fail with py2.5 |
106 |
# this sounds like a pysqlite/2.5 bug (the same eid is affected to |
|
107 |
# two different entities) |
|
108 |
self.mh.rollback() |
|
109 |
||
110 |
def test_add_attribute_varchar(self): |
|
6795
f29d24c3d687
[server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6790
diff
changeset
|
111 |
self.failIf('whatever' in self.schema) |
6790
f4f67ea5436a
[schema migration] add a test to ensure default value are considered
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
112 |
self.request().create_entity('Note') |
f4f67ea5436a
[schema migration] add a test to ensure default value are considered
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
113 |
self.commit() |
0 | 114 |
self.failIf('shortpara' in self.schema) |
115 |
self.mh.cmd_add_attribute('Note', 'shortpara') |
|
116 |
self.failUnless('shortpara' in self.schema) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
117 |
self.assertEqual(self.schema['shortpara'].subjects(), ('Note', )) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
118 |
self.assertEqual(self.schema['shortpara'].objects(), ('String', )) |
0 | 119 |
# 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
|
120 |
notesql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' and name='%sNote'" % SQL_PREFIX)[0][0] |
0 | 121 |
fields = dict(x.strip().split()[:2] for x in notesql.split('(', 1)[1].rsplit(')', 1)[0].split(',')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
122 |
self.assertEqual(fields['%sshortpara' % SQL_PREFIX], 'varchar(64)') |
6790
f4f67ea5436a
[schema migration] add a test to ensure default value are considered
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
123 |
req = self.request() |
f4f67ea5436a
[schema migration] add a test to ensure default value are considered
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
124 |
# test default value set on existing entities |
f4f67ea5436a
[schema migration] add a test to ensure default value are considered
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
125 |
self.assertEqual(req.execute('Note X').get_entity(0, 0).shortpara, 'hop') |
f4f67ea5436a
[schema migration] add a test to ensure default value are considered
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
126 |
# test default value set for next entities |
f4f67ea5436a
[schema migration] add a test to ensure default value are considered
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
127 |
self.assertEqual(req.create_entity('Note').shortpara, 'hop') |
0 | 128 |
self.mh.rollback() |
1787 | 129 |
|
0 | 130 |
def test_add_datetime_with_default_value_attribute(self): |
131 |
self.failIf('mydate' in self.schema) |
|
2642 | 132 |
self.failIf('shortpara' in self.schema) |
0 | 133 |
self.mh.cmd_add_attribute('Note', 'mydate') |
134 |
self.failUnless('mydate' in self.schema) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
135 |
self.assertEqual(self.schema['mydate'].subjects(), ('Note', )) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
136 |
self.assertEqual(self.schema['mydate'].objects(), ('Date', )) |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
972
diff
changeset
|
137 |
testdate = date(2005, 12, 13) |
0 | 138 |
eid1 = self.mh.rqlexec('INSERT Note N')[0][0] |
139 |
eid2 = self.mh.rqlexec('INSERT Note N: N mydate %(mydate)s', {'mydate' : testdate})[0][0] |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
140 |
d1 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid1})[0][0] |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
141 |
d2 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid2})[0][0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
142 |
self.assertEqual(d1, date.today()) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
143 |
self.assertEqual(d2, testdate) |
0 | 144 |
self.mh.rollback() |
1787 | 145 |
|
6292
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
146 |
def test_drop_chosen_constraints_ctxmanager(self): |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
147 |
with self.mh.cmd_dropped_constraints('Note', 'unique_id', UniqueConstraint): |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
148 |
self.mh.cmd_add_attribute('Note', 'unique_id') |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
149 |
# make sure the maxsize constraint is not dropped |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
150 |
self.assertRaises(ValidationError, |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
151 |
self.mh.rqlexec, |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
152 |
'INSERT Note N: N unique_id "xyz"') |
6417
d2361abe8505
[test] fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6370
diff
changeset
|
153 |
self.mh.rollback() |
6292
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
154 |
# make sure the unique constraint is dropped |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
155 |
self.mh.rqlexec('INSERT Note N: N unique_id "x"') |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
156 |
self.mh.rqlexec('INSERT Note N: N unique_id "x"') |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
157 |
self.mh.rqlexec('DELETE Note N') |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
158 |
self.mh.rollback() |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
159 |
|
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
160 |
def test_drop_required_ctxmanager(self): |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
161 |
with self.mh.cmd_dropped_constraints('Note', 'unique_id', cstrtype=None, |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
162 |
droprequired=True): |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
163 |
self.mh.cmd_add_attribute('Note', 'unique_id') |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
164 |
self.mh.rqlexec('INSERT Note N') |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
165 |
# make sure the required=True was restored |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
166 |
self.assertRaises(ValidationError, self.mh.rqlexec, 'INSERT Note N') |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
167 |
self.mh.rollback() |
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
168 |
|
0 | 169 |
def test_rename_attribute(self): |
170 |
self.failIf('civility' in self.schema) |
|
171 |
eid1 = self.mh.rqlexec('INSERT Personne X: X nom "lui", X sexe "M"')[0][0] |
|
172 |
eid2 = self.mh.rqlexec('INSERT Personne X: X nom "l\'autre", X sexe NULL')[0][0] |
|
173 |
self.mh.cmd_rename_attribute('Personne', 'sexe', 'civility') |
|
174 |
self.failIf('sexe' in self.schema) |
|
175 |
self.failUnless('civility' in self.schema) |
|
176 |
# test data has been backported |
|
177 |
c1 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid1)[0][0] |
|
178 |
self.failUnlessEqual(c1, 'M') |
|
179 |
c2 = self.mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid2)[0][0] |
|
180 |
self.failUnlessEqual(c2, None) |
|
181 |
||
182 |
||
183 |
def test_workflow_actions(self): |
|
6816
f61de39cd396
[wf migration] allow to deactivate assertion on wfable entity to quick-fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6815
diff
changeset
|
184 |
wf = self.mh.cmd_add_workflow(u'foo', ('Personne', 'Email'), |
f61de39cd396
[wf migration] allow to deactivate assertion on wfable entity to quick-fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6815
diff
changeset
|
185 |
ensure_workflowable=False) |
0 | 186 |
for etype in ('Personne', 'Email'): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
187 |
s1 = self.mh.rqlexec('Any N WHERE WF workflow_of ET, ET name "%s", WF name N' % |
0 | 188 |
etype)[0][0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
189 |
self.assertEqual(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
|
190 |
s1 = self.mh.rqlexec('Any N WHERE ET default_workflow WF, ET name "%s", WF name N' % |
0 | 191 |
etype)[0][0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
192 |
self.assertEqual(s1, "foo") |
1787 | 193 |
|
0 | 194 |
def test_add_entity_type(self): |
195 |
self.failIf('Folder2' in self.schema) |
|
196 |
self.failIf('filed_under2' in self.schema) |
|
197 |
self.mh.cmd_add_entity_type('Folder2') |
|
198 |
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
|
199 |
self.failUnless(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 200 |
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
|
201 |
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
|
202 |
self.schema.rebuild_infered_relations() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
203 |
self.assertEqual(sorted(str(rs) for rs in self.schema['Folder2'].subject_relations()), |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6417
diff
changeset
|
204 |
['created_by', 'creation_date', 'cw_source', 'cwuri', |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
205 |
'description', 'description_format', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
206 |
'eid', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
207 |
'filed_under2', 'has_text', |
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
208 |
'identity', 'in_basket', 'is', 'is_instance_of', |
0 | 209 |
'modification_date', 'name', 'owned_by']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
210 |
self.assertEqual([str(rs) for rs in self.schema['Folder2'].object_relations()], |
0 | 211 |
['filed_under2', 'identity']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
212 |
self.assertEqual(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
|
213 |
sorted(str(e) for e in self.schema.entities() if not e.final)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
214 |
self.assertEqual(self.schema['filed_under2'].objects(), ('Folder2',)) |
0 | 215 |
eschema = self.schema.eschema('Folder2') |
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
216 |
for cstr in eschema.rdef('name').constraints: |
0 | 217 |
self.failUnless(hasattr(cstr, 'eid')) |
218 |
||
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
219 |
def test_add_drop_entity_type(self): |
0 | 220 |
self.mh.cmd_add_entity_type('Folder2') |
6816
f61de39cd396
[wf migration] allow to deactivate assertion on wfable entity to quick-fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6815
diff
changeset
|
221 |
wf = self.mh.cmd_add_workflow(u'folder2 wf', 'Folder2', |
f61de39cd396
[wf migration] allow to deactivate assertion on wfable entity to quick-fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6815
diff
changeset
|
222 |
ensure_workflowable=False) |
3252
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
223 |
todo = wf.add_state(u'todo', initial=True) |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
224 |
done = wf.add_state(u'done') |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
225 |
wf.add_transition(u'redoit', done, todo) |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
226 |
wf.add_transition(u'markasdone', todo, done) |
0 | 227 |
self.commit() |
228 |
eschema = self.schema.eschema('Folder2') |
|
229 |
self.mh.cmd_drop_entity_type('Folder2') |
|
230 |
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
|
231 |
self.failIf(self.execute('CWEType X WHERE X name "Folder2"')) |
0 | 232 |
# test automatic workflow deletion |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
233 |
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
|
234 |
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
|
235 |
self.failIf(self.execute('Transition X WHERE NOT X transition_of WF')) |
0 | 236 |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
237 |
def test_add_drop_relation_type(self): |
0 | 238 |
self.mh.cmd_add_entity_type('Folder2', auto=False) |
239 |
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
|
240 |
self.schema.rebuild_infered_relations() |
0 | 241 |
self.failUnless('filed_under2' in self.schema) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
242 |
self.assertEqual(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
|
243 |
sorted(str(e) for e in self.schema.entities() if not e.final)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
244 |
self.assertEqual(self.schema['filed_under2'].objects(), ('Folder2',)) |
0 | 245 |
self.mh.cmd_drop_relation_type('filed_under2') |
246 |
self.failIf('filed_under2' in self.schema) |
|
247 |
||
248 |
def test_add_relation_definition_nortype(self): |
|
249 |
self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
250 |
self.assertEqual(self.schema['concerne2'].subjects(), |
0 | 251 |
('Personne',)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
252 |
self.assertEqual(self.schema['concerne2'].objects(), |
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
|
253 |
('Affaire', )) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
254 |
self.assertEqual(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
|
255 |
'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
|
256 |
self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Note') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
257 |
self.assertEqual(sorted(self.schema['concerne2'].objects()), ['Affaire', 'Note']) |
3252
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
258 |
self.mh.create_entity('Personne', nom=u'tot') |
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
self.failIf('concerne2' in self.schema) |
0 | 266 |
|
2251
799ff50ddfe8
fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2124
diff
changeset
|
267 |
def test_drop_relation_definition_existant_rtype(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
268 |
self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
269 |
['Affaire', 'Personne']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
270 |
self.assertEqual(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
|
271 |
['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
0 | 272 |
self.mh.cmd_drop_relation_definition('Personne', 'concerne', 'Affaire') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
273 |
self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
274 |
['Affaire']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
275 |
self.assertEqual(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
|
276 |
['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
|
277 |
self.mh.cmd_add_relation_definition('Personne', 'concerne', 'Affaire') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
278 |
self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
279 |
['Affaire', 'Personne']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
280 |
self.assertEqual(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
|
281 |
['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
|
282 |
# 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
|
283 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
1787 | 284 |
|
0 | 285 |
def test_drop_relation_definition_with_specialization(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
286 |
self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
287 |
['Affaire', 'Personne']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
288 |
self.assertEqual(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
|
289 |
['Affaire', 'Division', 'Note', 'Societe', 'SubDivision']) |
0 | 290 |
self.mh.cmd_drop_relation_definition('Affaire', 'concerne', 'Societe') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
291 |
self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
292 |
['Affaire', 'Personne']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
293 |
self.assertEqual(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
|
294 |
['Affaire', 'Division', 'Note', 'SubDivision']) |
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
295 |
self.schema.rebuild_infered_relations() # need to be explicitly called once everything is in place |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
296 |
self.assertEqual(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
|
297 |
['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
|
298 |
self.mh.cmd_add_relation_definition('Affaire', 'concerne', 'Societe') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
299 |
self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()), |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
300 |
['Affaire', 'Personne']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
301 |
self.assertEqual(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
|
302 |
['Affaire', 'Note', 'Societe']) |
38ffdb284689
we must now explicitly call rebuild_infered_relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
303 |
self.schema.rebuild_infered_relations() # need to be explicitly called once everything is in place |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
304 |
self.assertEqual(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
|
305 |
['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
|
306 |
# 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
|
307 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
0 | 308 |
|
309 |
def test_rename_relation(self): |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
310 |
self.skipTest('implement me') |
0 | 311 |
|
312 |
def test_change_relation_props_non_final(self): |
|
313 |
rschema = self.schema['concerne'] |
|
4100 | 314 |
card = rschema.rdef('Affaire', 'Societe').cardinality |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
315 |
self.assertEqual(card, '**') |
0 | 316 |
try: |
317 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
318 |
cardinality='?*') |
|
4100 | 319 |
card = rschema.rdef('Affaire', 'Societe').cardinality |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
320 |
self.assertEqual(card, '?*') |
0 | 321 |
finally: |
322 |
self.mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe', |
|
323 |
cardinality='**') |
|
1787 | 324 |
|
0 | 325 |
def test_change_relation_props_final(self): |
326 |
rschema = self.schema['adel'] |
|
4100 | 327 |
card = rschema.rdef('Personne', 'String').fulltextindexed |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
328 |
self.assertEqual(card, False) |
0 | 329 |
try: |
330 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
331 |
fulltextindexed=True) |
|
4100 | 332 |
card = rschema.rdef('Personne', 'String').fulltextindexed |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
333 |
self.assertEqual(card, True) |
0 | 334 |
finally: |
335 |
self.mh.cmd_change_relation_props('Personne', 'adel', 'String', |
|
336 |
fulltextindexed=False) |
|
337 |
||
7073
4ce9e536dd66
[test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6816
diff
changeset
|
338 |
@tag('longrun') |
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
339 |
def test_sync_schema_props_perms(self): |
2903
043c8fcb3819
[migration] drop rqlcursor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2745
diff
changeset
|
340 |
cursor = self.mh.session |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7242
diff
changeset
|
341 |
cursor.set_cnxset() |
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
342 |
nbrqlexpr_start = cursor.execute('Any COUNT(X) WHERE X is RQLExpression')[0][0] |
4100 | 343 |
migrschema['titre'].rdefs[('Personne', 'String')].order = 7 |
344 |
migrschema['adel'].rdefs[('Personne', 'String')].order = 6 |
|
345 |
migrschema['ass'].rdefs[('Personne', 'String')].order = 5 |
|
0 | 346 |
migrschema['Personne'].description = 'blabla bla' |
1787 | 347 |
migrschema['titre'].description = 'usually a title' |
4103
dc04bede3502
yams api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4100
diff
changeset
|
348 |
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
|
349 |
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
|
350 |
add_concerne_rqlexpr = self._rrqlexpr_rset('add', 'concerne') |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6417
diff
changeset
|
351 |
|
1787 | 352 |
self.mh.cmd_sync_schema_props_perms(commit=False) |
353 |
||
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
354 |
self.assertEqual(cursor.execute('Any D WHERE X name "Personne", X description D')[0][0], |
0 | 355 |
'blabla bla') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
356 |
self.assertEqual(cursor.execute('Any D WHERE X name "titre", X description D')[0][0], |
0 | 357 |
'usually a title') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
358 |
self.assertEqual(cursor.execute('Any D WHERE X relation_type RT, RT name "titre",' |
0 | 359 |
'X from_entity FE, FE name "Personne",' |
360 |
'X description D')[0][0], |
|
361 |
'title for this person') |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
362 |
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
|
363 |
'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
|
364 |
'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
|
365 |
'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
|
366 |
expected = [u'nom', u'prenom', u'sexe', u'promo', u'ass', u'adel', u'titre', |
7242
7c1937215db9
fix failing test_migration test caused by schema change
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7078
diff
changeset
|
367 |
u'web', u'tel', u'fax', u'datenaiss', u'tzdatenaiss', u'test', |
7c1937215db9
fix failing test_migration test caused by schema change
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7078
diff
changeset
|
368 |
u'description', u'firstname', |
7c1937215db9
fix failing test_migration test caused by schema change
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7078
diff
changeset
|
369 |
u'creation_date', u'cwuri', u'modification_date'] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
370 |
self.assertEqual(rinorder, expected) |
0 | 371 |
|
372 |
# test permissions synchronization #################################### |
|
373 |
# new rql expr to add note entity |
|
374 |
eexpr = self._erqlexpr_entity('add', 'Note') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
375 |
self.assertEqual(eexpr.expression, |
0 | 376 |
'X ecrit_part PE, U in_group G, ' |
377 |
'PE require_permission P, P name "add_note", P require_group G') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
378 |
self.assertEqual([et.name for et in eexpr.reverse_add_permission], ['Note']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
379 |
self.assertEqual(eexpr.reverse_read_permission, ()) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
380 |
self.assertEqual(eexpr.reverse_delete_permission, ()) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
381 |
self.assertEqual(eexpr.reverse_update_permission, ()) |
0 | 382 |
# no more rqlexpr to delete and add para attribute |
383 |
self.failIf(self._rrqlexpr_rset('add', 'para')) |
|
384 |
self.failIf(self._rrqlexpr_rset('delete', 'para')) |
|
1787 | 385 |
# new rql expr to add ecrit_par relation |
0 | 386 |
rexpr = self._rrqlexpr_entity('add', 'ecrit_par') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
387 |
self.assertEqual(rexpr.expression, |
0 | 388 |
'O require_permission P, P name "add_note", ' |
389 |
'U in_group G, P require_group G') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
390 |
self.assertEqual([rdef.rtype.name for rdef in rexpr.reverse_add_permission], ['ecrit_par']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
391 |
self.assertEqual(rexpr.reverse_read_permission, ()) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
392 |
self.assertEqual(rexpr.reverse_delete_permission, ()) |
0 | 393 |
# no more rqlexpr to delete and add travaille relation |
394 |
self.failIf(self._rrqlexpr_rset('add', 'travaille')) |
|
395 |
self.failIf(self._rrqlexpr_rset('delete', 'travaille')) |
|
396 |
# no more rqlexpr to delete and update Societe entity |
|
397 |
self.failIf(self._erqlexpr_rset('update', 'Societe')) |
|
398 |
self.failIf(self._erqlexpr_rset('delete', 'Societe')) |
|
399 |
# no more rqlexpr to read Affaire entity |
|
400 |
self.failIf(self._erqlexpr_rset('read', 'Affaire')) |
|
401 |
# rqlexpr to update Affaire entity has been updated |
|
402 |
eexpr = self._erqlexpr_entity('update', 'Affaire') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
403 |
self.assertEqual(eexpr.expression, 'X concerne S, S owned_by U') |
0 | 404 |
# no change for rqlexpr to add and delete Affaire entity |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
405 |
self.assertEqual(len(self._erqlexpr_rset('delete', 'Affaire')), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
406 |
self.assertEqual(len(self._erqlexpr_rset('add', 'Affaire')), 1) |
0 | 407 |
# no change for rqlexpr to add and delete concerne relation |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
408 |
self.assertEqual(len(self._rrqlexpr_rset('delete', 'concerne')), len(delete_concerne_rqlexpr)) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
409 |
self.assertEqual(len(self._rrqlexpr_rset('add', 'concerne')), len(add_concerne_rqlexpr)) |
0 | 410 |
# * migrschema involve: |
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
411 |
# * 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
|
412 |
# in para attribute) |
0 | 413 |
# * 1 update (Affaire update) |
414 |
# * 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
|
415 |
# * 2 implicit new for attributes update_permission (Note.para, Personne.test) |
0 | 416 |
# remaining orphan rql expr which should be deleted at commit (composite relation) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
417 |
self.assertEqual(cursor.execute('Any COUNT(X) WHERE X is RQLExpression, ' |
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
418 |
'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
|
419 |
'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
|
420 |
7+1) |
0 | 421 |
# finally |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
422 |
self.assertEqual(cursor.execute('Any COUNT(X) WHERE X is RQLExpression')[0][0], |
4635
44a883148ab4
fix sync_schema_props_perms test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
423 |
nbrqlexpr_start + 1 + 2 + 2) |
6208
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6163
diff
changeset
|
424 |
self.mh.commit() |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6163
diff
changeset
|
425 |
# unique_together test |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6163
diff
changeset
|
426 |
self.assertEqual(len(self.schema.eschema('Personne')._unique_together), 1) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
427 |
self.assertItemsEqual(self.schema.eschema('Personne')._unique_together[0], |
6208
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6163
diff
changeset
|
428 |
('nom', 'prenom', 'datenaiss')) |
6635
4e560631f36d
[test] repair test: we now have another unique constraint on CWSourceHostConfig
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6632
diff
changeset
|
429 |
rset = cursor.execute('Any C WHERE C is CWUniqueTogetherConstraint, C constraint_of ET, ET name "Personne"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
430 |
self.assertEqual(len(rset), 1) |
6815
a84190d4e78c
[schema] fix pb with ambiguous relation used within UniqueTogetherConstraint by having CWUniqueTogetherConstraint.relation targeting CWRType instead of CWAttribute/CWRelation. This fixes 3.10.7 migration.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
431 |
relations = [r.name for r in rset.get_entity(0, 0).relations] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
432 |
self.assertItemsEqual(relations, ('nom', 'prenom', 'datenaiss')) |
0 | 433 |
|
434 |
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
|
435 |
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
|
436 |
return self.mh.session.execute(rql, {'name': ertype}) |
0 | 437 |
def _erqlexpr_entity(self, action, ertype): |
438 |
rset = self._erqlexpr_rset(action, ertype) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
439 |
self.assertEqual(len(rset), 1) |
0 | 440 |
return rset.get_entity(0, 0) |
441 |
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
|
442 |
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
|
443 |
return self.mh.session.execute(rql, {'name': ertype}) |
0 | 444 |
def _rrqlexpr_entity(self, action, ertype): |
445 |
rset = self._rrqlexpr_rset(action, ertype) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
446 |
self.assertEqual(len(rset), 1) |
0 | 447 |
return rset.get_entity(0, 0) |
1787 | 448 |
|
0 | 449 |
def test_set_size_constraint(self): |
450 |
# existing previous value |
|
451 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
452 |
self.mh.cmd_set_size_constraint('CWEType', 'name', 128) |
0 | 453 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
454 |
self.mh.cmd_set_size_constraint('CWEType', 'name', 64) |
0 | 455 |
# non existing previous value |
456 |
try: |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
457 |
self.mh.cmd_set_size_constraint('CWEType', 'description', 256) |
0 | 458 |
finally: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
459 |
self.mh.cmd_set_size_constraint('CWEType', 'description', None) |
0 | 460 |
|
7073
4ce9e536dd66
[test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6816
diff
changeset
|
461 |
@tag('longrun') |
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
|
462 |
def test_add_remove_cube_and_deps(self): |
0 | 463 |
cubes = set(self.config.cubes()) |
464 |
schema = self.repo.schema |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
465 |
self.assertEqual(sorted((str(s), str(o)) for s, o in schema['see_also'].rdefs.keys()), |
439 | 466 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
467 |
('Bookmark', 'Bookmark'), ('Bookmark', 'Note'), |
|
468 |
('Note', 'Note'), ('Note', 'Bookmark')])) |
|
0 | 469 |
try: |
439 | 470 |
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
|
471 |
self.mh.cmd_remove_cube('email', removedeps=True) |
439 | 472 |
# 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
|
473 |
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
|
474 |
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
|
475 |
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
|
476 |
self.failIf(self.config.cube_dir('file') in self.config.cubes_path()) |
5575
8a531340c3ef
no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
477 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', |
439 | 478 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
479 |
self.failIf(ertype in schema, ertype) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
480 |
self.assertEqual(sorted(schema['see_also'].rdefs.keys()), |
439 | 481 |
sorted([('Folder', 'Folder'), |
482 |
('Bookmark', 'Bookmark'), |
|
483 |
('Bookmark', 'Note'), |
|
484 |
('Note', 'Note'), |
|
485 |
('Note', 'Bookmark')])) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
486 |
self.assertEqual(sorted(schema['see_also'].subjects()), ['Bookmark', 'Folder', 'Note']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
487 |
self.assertEqual(sorted(schema['see_also'].objects()), ['Bookmark', 'Folder', 'Note']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
488 |
self.assertEqual(self.execute('Any X WHERE X pkey "system.version.email"').rowcount, 0) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
489 |
self.assertEqual(self.execute('Any X WHERE X pkey "system.version.file"').rowcount, 0) |
439 | 490 |
except : |
491 |
import traceback |
|
492 |
traceback.print_exc() |
|
493 |
raise |
|
0 | 494 |
finally: |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
495 |
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
|
496 |
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
|
497 |
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
|
498 |
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
|
499 |
self.failUnless(self.config.cube_dir('file') in self.config.cubes_path()) |
5575
8a531340c3ef
no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
500 |
for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', |
0 | 501 |
'sender', 'in_thread', 'reply_to', 'data_format'): |
502 |
self.failUnless(ertype in schema, ertype) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
503 |
self.assertEqual(sorted(schema['see_also'].rdefs.keys()), |
439 | 504 |
sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), |
505 |
('Bookmark', 'Bookmark'), |
|
506 |
('Bookmark', 'Note'), |
|
507 |
('Note', 'Note'), |
|
508 |
('Note', 'Bookmark')])) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
509 |
self.assertEqual(sorted(schema['see_also'].subjects()), ['Bookmark', 'EmailThread', 'Folder', 'Note']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
510 |
self.assertEqual(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
|
511 |
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
|
512 |
from cubes.file.__pkginfo__ import version as file_version |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
513 |
self.assertEqual(self.execute('Any V WHERE X value V, X pkey "system.version.email"')[0][0], |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
514 |
email_version) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
515 |
self.assertEqual(self.execute('Any V WHERE X value V, X pkey "system.version.file"')[0][0], |
47
54087a269bdd
fix tests (some where broken after ECache was added)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
0
diff
changeset
|
516 |
file_version) |
0 | 517 |
# trick: overwrite self.maxeid to avoid deletion of just reintroduced |
518 |
# types (and their associated tables!) |
|
519 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
|
520 |
# why this commit is necessary is unclear to me (though without it |
|
521 |
# next test may fail complaining of missing tables |
|
1787 | 522 |
self.commit() |
972 | 523 |
|
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
|
524 |
|
7073
4ce9e536dd66
[test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6816
diff
changeset
|
525 |
@tag('longrun') |
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
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
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
|
530 |
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
|
531 |
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
|
532 |
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
|
533 |
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
|
534 |
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
|
535 |
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
|
536 |
'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
|
537 |
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
|
538 |
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
|
539 |
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
|
540 |
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
|
541 |
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
|
542 |
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
|
543 |
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
|
544 |
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
|
545 |
# 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
|
546 |
# 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
|
547 |
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
|
548 |
# 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
|
549 |
# 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
|
550 |
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
|
551 |
|
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
|
552 |
def test_remove_dep_cube(self): |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
553 |
with self.assertRaises(ConfigurationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
554 |
self.mh.cmd_remove_cube('file') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6795
diff
changeset
|
555 |
self.assertEqual(str(cm.exception), "can't remove cube file, used as a dependency") |
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
|
556 |
|
7073
4ce9e536dd66
[test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6816
diff
changeset
|
557 |
@tag('longrun') |
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
|
558 |
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
|
559 |
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
|
560 |
self.mh.repo.schema.rebuild_infered_relations() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
561 |
self.assertEqual(sorted(et.type for et in self.schema['Para'].specialized_by()), |
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
|
562 |
['Note']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
563 |
self.assertEqual(self.schema['Note'].specializes().type, 'Para') |
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
|
564 |
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
|
565 |
self.mh.repo.schema.rebuild_infered_relations() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
566 |
self.assertEqual(sorted(et.type for et in self.schema['Para'].specialized_by()), |
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
|
567 |
['Note', 'Text']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
568 |
self.assertEqual(self.schema['Text'].specializes().type, 'Para') |
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
|
569 |
# 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
|
570 |
text = self.execute('INSERT Text X: X para "hip", X summary "hop", X newattr "momo"').get_entity(0, 0) |
6292
054fa36060d5
[migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6208
diff
changeset
|
571 |
note = self.execute('INSERT Note X: X para "hip", X shortpara "hop", X newattr "momo", X unique_id "x"').get_entity(0, 0) |
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
|
572 |
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
|
573 |
self.failUnless(self.execute('SET X newnotinlined Y WHERE X eid %(x)s, Y eid %(y)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
574 |
{'x': text.eid, 'y': aff.eid})) |
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
|
575 |
self.failUnless(self.execute('SET X newnotinlined Y WHERE X eid %(x)s, Y eid %(y)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
576 |
{'x': note.eid, 'y': aff.eid})) |
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
|
577 |
self.failUnless(self.execute('SET X newinlined Y WHERE X eid %(x)s, Y eid %(y)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
578 |
{'x': text.eid, 'y': aff.eid})) |
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
|
579 |
self.failUnless(self.execute('SET X newinlined Y WHERE X eid %(x)s, Y eid %(y)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4774
diff
changeset
|
580 |
{'x': note.eid, 'y': aff.eid})) |
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
|
581 |
# 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
|
582 |
# 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
|
583 |
# 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
|
584 |
# 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
|
585 |
# 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
|
586 |
# |
12ad88615a12
test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
587 |
# 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
|
588 |
# 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
|
589 |
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
|
590 |
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
|
591 |
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
|
592 |
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
|
593 |
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
|
594 |
self.session.data['rebuild-infered'] = False |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
595 |
self.assertEqual(sorted(et.type for et in self.schema['Para'].specialized_by()), |
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
|
596 |
[]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
597 |
self.assertEqual(self.schema['Note'].specializes(), None) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
598 |
self.assertEqual(self.schema['Text'].specializes(), None) |
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
|
599 |
|
6163
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
600 |
|
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
601 |
def test_add_symmetric_relation_type(self): |
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
602 |
same_as_sql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' " |
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
603 |
"and name='same_as_relation'") |
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
604 |
self.failIf(same_as_sql) |
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
605 |
self.mh.cmd_add_relation_type('same_as') |
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
606 |
same_as_sql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' " |
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
607 |
"and name='same_as_relation'") |
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
608 |
self.failUnless(same_as_sql) |
407f54345687
[migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5575
diff
changeset
|
609 |
|
0 | 610 |
if __name__ == '__main__': |
611 |
unittest_main() |