1 """cubicweb.common.migration unit tests |
|
2 |
|
3 :organization: Logilab |
|
4 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
|
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
|
7 """ |
|
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 MigrationHelper, filter_scripts |
|
17 from cubicweb.server.migractions import ServerMigrationHelper |
|
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 |
|
34 |
|
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') |
|
40 self.config.__class__.cubicweb_appobject_path = frozenset() |
|
41 self.config.__class__.cube_appobject_path = frozenset() |
|
42 |
|
43 def test_filter_scripts_base(self): |
|
44 self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,3,0), (2,4,0)), |
|
45 []) |
|
46 self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,5,0)), |
|
47 [((2, 5, 0), SMIGRDIR+'2.5.0_Any.sql')]) |
|
48 self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,6,0)), |
|
49 [((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
|
50 self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,6,0)), |
|
51 [((2, 5, 0), SMIGRDIR+'2.5.0_Any.sql'), |
|
52 ((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
|
53 self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,5,1)), |
|
54 []) |
|
55 self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,10,2)), |
|
56 [((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql'), |
|
57 ((2, 10, 2), SMIGRDIR+'2.10.2_Any.sql')]) |
|
58 self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,5,1), (2,6,0)), |
|
59 [((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
|
60 |
|
61 self.assertListEquals(filter_scripts(self.config, TMIGRDIR, (0,0,2), (0,0,3)), |
|
62 [((0, 0, 3), TMIGRDIR+'0.0.3_Any.py')]) |
|
63 self.assertListEquals(filter_scripts(self.config, TMIGRDIR, (0,0,2), (0,0,4)), |
|
64 [((0, 0, 3), TMIGRDIR+'0.0.3_Any.py'), |
|
65 ((0, 0, 4), TMIGRDIR+'0.0.4_Any.py')]) |
|
66 |
|
67 def test_filter_scripts_for_mode(self): |
|
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' |
|
75 self.assertListEquals(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)), |
|
76 [((0, 1 ,0), TMIGRDIR+'0.1.0_common.py'), |
|
77 ((0, 1 ,0), TMIGRDIR+'0.1.0_web.py')]) |
|
78 config.__class__.name = 'repository' |
|
79 self.assertListEquals(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)), |
|
80 [((0, 1 ,0), TMIGRDIR+'0.1.0_Any.py'), |
|
81 ((0, 1 ,0), TMIGRDIR+'0.1.0_common.py'), |
|
82 ((0, 1 ,0), TMIGRDIR+'0.1.0_repository.py')]) |
|
83 config.__class__.name = 'all-in-one' |
|
84 self.assertListEquals(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)), |
|
85 [((0, 1 ,0), TMIGRDIR+'0.1.0_Any.py'), |
|
86 ((0, 1 ,0), TMIGRDIR+'0.1.0_common.py'), |
|
87 ((0, 1 ,0), TMIGRDIR+'0.1.0_repository.py'), |
|
88 ((0, 1 ,0), TMIGRDIR+'0.1.0_web.py')]) |
|
89 config.__class__.name = 'repository' |
|
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() |
|