author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 18 Aug 2009 09:25:26 +0200 | |
changeset 2901 | 8f4d495c94c2 |
parent 2773 | b2530e3e0afb |
child 3448 | 495862266785 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
1 |
"""cubicweb.common.migration unit tests |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
""" |
0 | 8 |
|
9 |
from os.path import abspath |
|
10 |
from logilab.common.testlib import TestCase, unittest_main |
|
11 |
||
12 |
from cubicweb.devtools import TestServerConfiguration |
|
13 |
from cubicweb.cwconfig import CubicWebConfiguration |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
14 |
from cubicweb.common.migration import MigrationHelper, filter_scripts |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
15 |
from cubicweb.server.migractions import ServerMigrationHelper |
0 | 16 |
|
17 |
||
18 |
class Schema(dict): |
|
19 |
def has_entity(self, e_type): |
|
20 |
return self.has_key(e_type) |
|
21 |
||
22 |
SMIGRDIR = abspath('data/server_migration') + '/' |
|
23 |
TMIGRDIR = abspath('data/migration') + '/' |
|
24 |
||
25 |
class MigrTestConfig(TestServerConfiguration): |
|
26 |
verbosity = 0 |
|
27 |
def migration_scripts_dir(cls): |
|
28 |
return SMIGRDIR |
|
29 |
||
30 |
def cube_migration_scripts_dir(cls, cube): |
|
31 |
return TMIGRDIR |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
32 |
|
0 | 33 |
class MigrationToolsTC(TestCase): |
34 |
def setUp(self): |
|
35 |
self.config = MigrTestConfig('data') |
|
36 |
from yams.schema import Schema |
|
37 |
self.config.load_schema = lambda expand_cubes=False: Schema('test') |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2275
diff
changeset
|
38 |
self.config.__class__.cubicweb_appobject_path = frozenset() |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2275
diff
changeset
|
39 |
self.config.__class__.cube_appobject_path = frozenset() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
40 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
41 |
def test_filter_scripts_base(self): |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
42 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,3,0), (2,4,0)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
43 |
[]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
44 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,5,0)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
45 |
[((2, 5, 0), SMIGRDIR+'2.5.0_Any.sql')]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
46 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,6,0)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
47 |
[((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
48 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,6,0)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
49 |
[((2, 5, 0), SMIGRDIR+'2.5.0_Any.sql'), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
50 |
((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
51 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,5,1)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
52 |
[]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
53 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,10,2)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
54 |
[((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql'), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
55 |
((2, 10, 2), SMIGRDIR+'2.10.2_Any.sql')]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
56 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,1), (2,6,0)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
57 |
[((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
58 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
59 |
self.assertListEquals(filter_scripts(self.config, TMIGRDIR, (0,0,2), (0,0,3)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
60 |
[((0, 0, 3), TMIGRDIR+'0.0.3_Any.py')]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
61 |
self.assertListEquals(filter_scripts(self.config, TMIGRDIR, (0,0,2), (0,0,4)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
62 |
[((0, 0, 3), TMIGRDIR+'0.0.3_Any.py'), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
63 |
((0, 0, 4), TMIGRDIR+'0.0.4_Any.py')]) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
64 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
65 |
def test_filter_scripts_for_mode(self): |
0 | 66 |
self.assertIsInstance(self.config.migration_handler(), ServerMigrationHelper) |
67 |
config = CubicWebConfiguration('data') |
|
68 |
config.verbosity = 0 |
|
69 |
self.assert_(not isinstance(config.migration_handler(), ServerMigrationHelper)) |
|
70 |
self.assertIsInstance(config.migration_handler(), MigrationHelper) |
|
71 |
config = self.config |
|
72 |
config.__class__.name = 'twisted' |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
73 |
self.assertListEquals(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
74 |
[((0, 1 ,0), TMIGRDIR+'0.1.0_common.py'), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
75 |
((0, 1 ,0), TMIGRDIR+'0.1.0_web.py')]) |
0 | 76 |
config.__class__.name = 'repository' |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
77 |
self.assertListEquals(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
78 |
[((0, 1 ,0), TMIGRDIR+'0.1.0_Any.py'), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
79 |
((0, 1 ,0), TMIGRDIR+'0.1.0_common.py'), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
80 |
((0, 1 ,0), TMIGRDIR+'0.1.0_repository.py')]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
81 |
config.__class__.name = 'all-in-one' |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
82 |
self.assertListEquals(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
83 |
[((0, 1 ,0), TMIGRDIR+'0.1.0_Any.py'), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
84 |
((0, 1 ,0), TMIGRDIR+'0.1.0_common.py'), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
85 |
((0, 1 ,0), TMIGRDIR+'0.1.0_repository.py'), |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
86 |
((0, 1 ,0), TMIGRDIR+'0.1.0_web.py')]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
87 |
config.__class__.name = 'repository' |
0 | 88 |
|
89 |
||
90 |
from cubicweb.devtools import ApptestConfiguration, init_test_database, cleanup_sqlite |
|
91 |
||
92 |
class BaseCreationTC(TestCase): |
|
93 |
||
94 |
def test_db_creation(self): |
|
95 |
"""make sure database can be created""" |
|
96 |
config = ApptestConfiguration('data') |
|
97 |
source = config.sources()['system'] |
|
98 |
self.assertEquals(source['db-driver'], 'sqlite') |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
99 |
cleanup_sqlite(source['db-name'], removetemplate=True) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
100 |
init_test_database(config=config) |
0 | 101 |
|
102 |
||
103 |
if __name__ == '__main__': |
|
104 |
unittest_main() |