author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 11 Oct 2010 12:27:29 +0200 | |
changeset 6440 | 9d85f11983b0 |
parent 6340 | 470d8e828fda |
child 6631 | 26c303c3f1aa |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4021
diff
changeset
|
18 |
"""cubicweb.migration unit tests |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
19 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
20 |
""" |
0 | 21 |
|
22 |
from os.path import abspath |
|
23 |
from logilab.common.testlib import TestCase, unittest_main |
|
24 |
||
25 |
from cubicweb.devtools import TestServerConfiguration |
|
26 |
from cubicweb.cwconfig import CubicWebConfiguration |
|
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3448
diff
changeset
|
27 |
from cubicweb.migration import MigrationHelper, filter_scripts |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
28 |
from cubicweb.server.migractions import ServerMigrationHelper |
0 | 29 |
|
30 |
||
31 |
class Schema(dict): |
|
32 |
def has_entity(self, e_type): |
|
33 |
return self.has_key(e_type) |
|
34 |
||
35 |
SMIGRDIR = abspath('data/server_migration') + '/' |
|
36 |
TMIGRDIR = abspath('data/migration') + '/' |
|
37 |
||
38 |
class MigrTestConfig(TestServerConfiguration): |
|
39 |
verbosity = 0 |
|
40 |
def migration_scripts_dir(cls): |
|
41 |
return SMIGRDIR |
|
42 |
||
43 |
def cube_migration_scripts_dir(cls, cube): |
|
44 |
return TMIGRDIR |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
45 |
|
0 | 46 |
class MigrationToolsTC(TestCase): |
47 |
def setUp(self): |
|
48 |
self.config = MigrTestConfig('data') |
|
49 |
from yams.schema import Schema |
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
54 |
def test_filter_scripts_base(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
55 |
self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,3,0), (2,4,0)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
56 |
[]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
57 |
self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,5,0)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
58 |
[((2, 5, 0), SMIGRDIR+'2.5.0_Any.sql')]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
59 |
self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,6,0)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
60 |
[((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
61 |
self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,6,0)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
62 |
[((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
|
63 |
((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
64 |
self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,5,1)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
65 |
[]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
66 |
self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,10,2)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
67 |
[((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
|
68 |
((2, 10, 2), SMIGRDIR+'2.10.2_Any.sql')]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
69 |
self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,5,1), (2,6,0)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
70 |
[((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
|
71 |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
72 |
self.assertListEqual(filter_scripts(self.config, TMIGRDIR, (0,0,2), (0,0,3)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
73 |
[((0, 0, 3), TMIGRDIR+'0.0.3_Any.py')]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
74 |
self.assertListEqual(filter_scripts(self.config, TMIGRDIR, (0,0,2), (0,0,4)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
75 |
[((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
|
76 |
((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
|
77 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
78 |
def test_filter_scripts_for_mode(self): |
0 | 79 |
config = CubicWebConfiguration('data') |
80 |
config.verbosity = 0 |
|
81 |
self.assert_(not isinstance(config.migration_handler(), ServerMigrationHelper)) |
|
82 |
self.assertIsInstance(config.migration_handler(), MigrationHelper) |
|
83 |
config = self.config |
|
84 |
config.__class__.name = 'twisted' |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
85 |
self.assertListEqual(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)), |
2275
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_web.py')]) |
0 | 88 |
config.__class__.name = 'repository' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
89 |
self.assertListEqual(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
90 |
[((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
|
91 |
((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
|
92 |
((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
|
93 |
config.__class__.name = 'all-in-one' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
94 |
self.assertListEqual(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
95 |
[((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
|
96 |
((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
|
97 |
((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
|
98 |
((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
|
99 |
config.__class__.name = 'repository' |
0 | 100 |
|
101 |
||
102 |
from cubicweb.devtools import ApptestConfiguration, init_test_database, cleanup_sqlite |
|
103 |
||
104 |
class BaseCreationTC(TestCase): |
|
105 |
||
106 |
def test_db_creation(self): |
|
107 |
"""make sure database can be created""" |
|
108 |
config = ApptestConfiguration('data') |
|
109 |
source = config.sources()['system'] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
110 |
self.assertEqual(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
|
111 |
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
|
112 |
init_test_database(config=config) |
0 | 113 |
|
114 |
||
115 |
if __name__ == '__main__': |
|
116 |
unittest_main() |