author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 16 Oct 2009 15:17:28 +0200 | |
branch | stable |
changeset 3704 | ddb10568f5f8 |
parent 2657 | de974465d381 |
child 2773 | b2530e3e0afb |
child 4212 | ab6573088b4a |
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 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
16 |
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
|
17 |
from cubicweb.server.migractions import ServerMigrationHelper |
0 | 18 |
|
19 |
||
20 |
class Schema(dict): |
|
21 |
def has_entity(self, e_type): |
|
22 |
return self.has_key(e_type) |
|
23 |
||
24 |
SMIGRDIR = abspath('data/server_migration') + '/' |
|
25 |
TMIGRDIR = abspath('data/migration') + '/' |
|
26 |
||
27 |
class MigrTestConfig(TestServerConfiguration): |
|
28 |
verbosity = 0 |
|
29 |
def migration_scripts_dir(cls): |
|
30 |
return SMIGRDIR |
|
31 |
||
32 |
def cube_migration_scripts_dir(cls, cube): |
|
33 |
return TMIGRDIR |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
34 |
|
0 | 35 |
class MigrationToolsTC(TestCase): |
36 |
def setUp(self): |
|
37 |
self.config = MigrTestConfig('data') |
|
38 |
from yams.schema import Schema |
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
[]) |
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,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
|
47 |
[((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
|
48 |
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
|
49 |
[((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
|
50 |
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
|
51 |
[((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
|
52 |
((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
|
53 |
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
|
54 |
[]) |
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
55 |
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
|
56 |
[((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
|
57 |
((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
|
58 |
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
|
59 |
[((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
|
60 |
|
2275
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,3)), |
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 |
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
|
64 |
[((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
|
65 |
((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
|
66 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
67 |
def test_filter_scripts_for_mode(self): |
0 | 68 |
self.assertIsInstance(self.config.migration_handler(), ServerMigrationHelper) |
69 |
config = CubicWebConfiguration('data') |
|
70 |
config.verbosity = 0 |
|
71 |
self.assert_(not isinstance(config.migration_handler(), ServerMigrationHelper)) |
|
72 |
self.assertIsInstance(config.migration_handler(), MigrationHelper) |
|
73 |
config = self.config |
|
74 |
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
|
75 |
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
|
76 |
[((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
|
77 |
((0, 1 ,0), TMIGRDIR+'0.1.0_web.py')]) |
0 | 78 |
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
|
79 |
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
|
80 |
[((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
|
81 |
((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
|
82 |
((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
|
83 |
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
|
84 |
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
|
85 |
[((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
|
86 |
((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
|
87 |
((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
|
88 |
((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
|
89 |
config.__class__.name = 'repository' |
0 | 90 |
|
91 |
||
92 |
from cubicweb.devtools import ApptestConfiguration, init_test_database, cleanup_sqlite |
|
93 |
||
94 |
class BaseCreationTC(TestCase): |
|
95 |
||
96 |
def test_db_creation(self): |
|
97 |
"""make sure database can be created""" |
|
98 |
config = ApptestConfiguration('data') |
|
99 |
source = config.sources()['system'] |
|
100 |
self.assertEquals(source['db-driver'], 'sqlite') |
|
101 |
cleanup_sqlite(source['db-name'], removecube=True) |
|
102 |
init_test_database(driver=source['db-driver'], config=config) |
|
103 |
||
104 |
||
105 |
if __name__ == '__main__': |
|
106 |
unittest_main() |