author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Mon, 18 May 2009 14:08:21 +0200 | |
branch | stable |
changeset 1841 | d629a6fc33e5 |
parent 1802 | d628defebc17 |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
"""cubicweb.common.migration unit tests""" |
2 |
||
3 |
from os.path import abspath |
|
4 |
from logilab.common.testlib import TestCase, unittest_main |
|
5 |
||
6 |
from cubicweb.devtools import TestServerConfiguration |
|
7 |
from cubicweb.devtools.apptest import TestEnvironment |
|
8 |
||
9 |
from cubicweb.cwconfig import CubicWebConfiguration |
|
10 |
from cubicweb.common.migration import migration_files, filter_scripts |
|
11 |
||
12 |
||
13 |
class Schema(dict): |
|
14 |
def has_entity(self, e_type): |
|
15 |
return self.has_key(e_type) |
|
16 |
||
17 |
SMIGRDIR = abspath('data/server_migration') + '/' |
|
18 |
TMIGRDIR = abspath('data/migration') + '/' |
|
19 |
||
20 |
class MigrTestConfig(TestServerConfiguration): |
|
21 |
verbosity = 0 |
|
22 |
def migration_scripts_dir(cls): |
|
23 |
return SMIGRDIR |
|
24 |
||
25 |
def cube_migration_scripts_dir(cls, cube): |
|
26 |
return TMIGRDIR |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
27 |
|
0 | 28 |
class MigrationToolsTC(TestCase): |
29 |
def setUp(self): |
|
30 |
self.config = MigrTestConfig('data') |
|
31 |
from yams.schema import Schema |
|
32 |
self.config.load_schema = lambda expand_cubes=False: Schema('test') |
|
755 | 33 |
self.config.__class__.cubicweb_vobject_path = frozenset() |
34 |
self.config.__class__.cube_vobject_path = frozenset() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
35 |
|
0 | 36 |
def test_migration_files_base(self): |
37 |
self.assertListEquals(migration_files(self.config, [('cubicweb', (2,3,0), (2,4,0)), |
|
38 |
('TEMPLATE', (0,0,2), (0,0,3))]), |
|
39 |
[SMIGRDIR+'bootstrapmigration_repository.py', |
|
40 |
TMIGRDIR+'0.0.3_Any.py']) |
|
41 |
self.assertListEquals(migration_files(self.config, [('cubicweb', (2,4,0), (2,5,0)), |
|
42 |
('TEMPLATE', (0,0,2), (0,0,3))]), |
|
43 |
[SMIGRDIR+'bootstrapmigration_repository.py', |
|
44 |
SMIGRDIR+'2.5.0_Any.sql', |
|
45 |
TMIGRDIR+'0.0.3_Any.py']) |
|
46 |
self.assertListEquals(migration_files(self.config, [('cubicweb', (2,5,0), (2,6,0)), |
|
47 |
('TEMPLATE', (0,0,3), (0,0,4))]), |
|
48 |
[SMIGRDIR+'bootstrapmigration_repository.py', |
|
49 |
SMIGRDIR+'2.6.0_Any.sql', |
|
50 |
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
|
51 |
|
0 | 52 |
## def test_migration_files_overlap(self): |
53 |
## self.assertListEquals(migration_files(self.config, (2,4,0), (2,10,2), |
|
54 |
## (0,0,2), (0,1,2)), |
|
55 |
## [SMIGRDIR+'bootstrapmigration_repository.py', |
|
56 |
## TMIGRDIR+'0.0.3_Any.py', |
|
57 |
## TMIGRDIR+'0.0.4_Any.py', |
|
58 |
## SMIGRDIR+'2.4.0_2.5.0_Any.sql', |
|
59 |
## SMIGRDIR+'2.5.1_2.6.0_Any.sql', |
|
60 |
## TMIGRDIR+'0.1.0_Any.py', |
|
61 |
## TMIGRDIR+'0.1.0_common.py', |
|
62 |
## TMIGRDIR+'0.1.0_repository.py', |
|
63 |
## TMIGRDIR+'0.1.2_Any.py', |
|
64 |
## SMIGRDIR+'2.10.1_2.10.2_Any.sql']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
65 |
|
0 | 66 |
def test_migration_files_for_mode(self): |
67 |
from cubicweb.server.migractions import ServerMigrationHelper |
|
68 |
self.assertIsInstance(self.config.migration_handler(), ServerMigrationHelper) |
|
69 |
from cubicweb.common.migration import MigrationHelper |
|
70 |
config = CubicWebConfiguration('data') |
|
71 |
config.verbosity = 0 |
|
72 |
self.assert_(not isinstance(config.migration_handler(), ServerMigrationHelper)) |
|
73 |
self.assertIsInstance(config.migration_handler(), MigrationHelper) |
|
74 |
config = self.config |
|
75 |
config.__class__.name = 'twisted' |
|
76 |
self.assertListEquals(migration_files(config, [('TEMPLATE', (0,0,4), (0,1,0))]), |
|
77 |
[TMIGRDIR+'0.1.0_common.py', |
|
78 |
TMIGRDIR+'0.1.0_web.py']) |
|
79 |
config.__class__.name = 'repository' |
|
80 |
self.assertListEquals(migration_files(config, [('TEMPLATE', (0,0,4), (0,1,0))]), |
|
81 |
[SMIGRDIR+'bootstrapmigration_repository.py', |
|
82 |
TMIGRDIR+'0.1.0_Any.py', |
|
83 |
TMIGRDIR+'0.1.0_common.py', |
|
84 |
TMIGRDIR+'0.1.0_repository.py']) |
|
85 |
config.__class__.name = 'all-in-one' |
|
86 |
self.assertListEquals(migration_files(config, [('TEMPLATE', (0,0,4), (0,1,0))]), |
|
87 |
[SMIGRDIR+'bootstrapmigration_repository.py', |
|
88 |
TMIGRDIR+'0.1.0_Any.py', |
|
89 |
TMIGRDIR+'0.1.0_common.py', |
|
90 |
TMIGRDIR+'0.1.0_repository.py', |
|
91 |
TMIGRDIR+'0.1.0_web.py']) |
|
92 |
config.__class__.name = 'repository' |
|
93 |
||
94 |
def test_filter_scripts(self): |
|
95 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,5,0)), |
|
96 |
[((2, 5, 0), SMIGRDIR+'2.5.0_Any.sql')]) |
|
97 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,6,0)), |
|
98 |
[((2, 5, 0), SMIGRDIR+'2.5.0_Any.sql'), |
|
99 |
((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
|
100 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,5,1)), |
|
101 |
[]) |
|
102 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,6,0)), |
|
103 |
[((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
|
104 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,10,2)), |
|
105 |
[((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql'), |
|
106 |
((2, 10, 2), SMIGRDIR+'2.10.2_Any.sql')]) |
|
107 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,1), (2,6,0)), |
|
108 |
[((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
|
109 |
self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,1), (2,10,2)), |
|
110 |
[((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql'), |
|
111 |
((2, 10, 2), SMIGRDIR+'2.10.2_Any.sql')]) |
|
112 |
||
113 |
||
114 |
from cubicweb.devtools import ApptestConfiguration, init_test_database, cleanup_sqlite |
|
115 |
||
116 |
class BaseCreationTC(TestCase): |
|
117 |
||
118 |
def test_db_creation(self): |
|
119 |
"""make sure database can be created""" |
|
120 |
config = ApptestConfiguration('data') |
|
121 |
source = config.sources()['system'] |
|
122 |
self.assertEquals(source['db-driver'], 'sqlite') |
|
123 |
cleanup_sqlite(source['db-name'], removecube=True) |
|
124 |
init_test_database(driver=source['db-driver'], config=config) |
|
125 |
||
126 |
||
127 |
if __name__ == '__main__': |
|
128 |
unittest_main() |