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