author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 11 Jun 2014 14:47:50 +0200 | |
changeset 10361 | 46d72f33c428 |
parent 9723 | 46ad7d474d3d |
child 10567 | c316e0049b9c |
permissions | -rw-r--r-- |
9460
a2a0bc984863
[config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9251
diff
changeset
|
1 |
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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
|
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/>. |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
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 |
|
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
20 |
from os.path import abspath, dirname, join |
0 | 21 |
from logilab.common.testlib import TestCase, unittest_main |
22 |
||
23 |
from cubicweb.devtools import TestServerConfiguration |
|
24 |
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
|
25 |
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
|
26 |
from cubicweb.server.migractions import ServerMigrationHelper |
0 | 27 |
|
28 |
||
29 |
class Schema(dict): |
|
30 |
def has_entity(self, e_type): |
|
8697
574bb05e40a4
[toward py3k] rewrite has_key() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8558
diff
changeset
|
31 |
return e_type in self |
0 | 32 |
|
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
33 |
SMIGRDIR = join(dirname(__file__), 'data', 'server_migration') + '/' |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
34 |
TMIGRDIR = join(dirname(__file__), 'data', 'migration') + '/' |
0 | 35 |
|
36 |
class MigrTestConfig(TestServerConfiguration): |
|
37 |
verbosity = 0 |
|
38 |
def migration_scripts_dir(cls): |
|
39 |
return SMIGRDIR |
|
40 |
||
41 |
def cube_migration_scripts_dir(cls, cube): |
|
42 |
return TMIGRDIR |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
755
diff
changeset
|
43 |
|
0 | 44 |
class MigrationToolsTC(TestCase): |
45 |
def setUp(self): |
|
46 |
self.config = MigrTestConfig('data') |
|
47 |
from yams.schema import Schema |
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
[]) |
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,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
|
56 |
[((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
|
57 |
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
|
58 |
[((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
|
59 |
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
|
60 |
[((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
|
61 |
((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
|
62 |
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
|
63 |
[]) |
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,10,2)), |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
65 |
[((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
|
66 |
((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
|
67 |
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
|
68 |
[((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
|
69 |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
70 |
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
|
71 |
[((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
|
72 |
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
|
73 |
[((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
|
74 |
((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
|
75 |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
76 |
def test_filter_scripts_for_mode(self): |
0 | 77 |
config = CubicWebConfiguration('data') |
78 |
config.verbosity = 0 |
|
9723
46ad7d474d3d
[test] use assertNotIsInstance instead of assert_(not isinstance(...))
Julien Cristau <julien.cristau@logilab.fr>
parents:
9576
diff
changeset
|
79 |
self.assertNotIsInstance(config.migration_handler(), ServerMigrationHelper) |
0 | 80 |
self.assertIsInstance(config.migration_handler(), MigrationHelper) |
81 |
config = self.config |
|
82 |
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
|
83 |
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
|
84 |
[((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
|
85 |
((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
|
86 |
((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
|
87 |
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
|
88 |
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
|
89 |
[((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
|
90 |
((0, 1 ,0), TMIGRDIR+'0.1.0_common.py'), |
9251
e4d753c8b1c4
remove "twisted" configuration (closes #2919310)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8697
diff
changeset
|
91 |
((0, 1 ,0), TMIGRDIR+'0.1.0_repository.py')]) |
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
92 |
config.__class__.name = 'repository' |
0 | 93 |
|
94 |
||
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6631
diff
changeset
|
95 |
from cubicweb.devtools import ApptestConfiguration, get_test_db_handler |
0 | 96 |
|
97 |
class BaseCreationTC(TestCase): |
|
98 |
||
99 |
def test_db_creation(self): |
|
100 |
"""make sure database can be created""" |
|
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
101 |
config = ApptestConfiguration('data', apphome=self.datadir) |
9460
a2a0bc984863
[config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9251
diff
changeset
|
102 |
source = config.system_source_config |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
103 |
self.assertEqual(source['db-driver'], 'sqlite') |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6631
diff
changeset
|
104 |
handler = get_test_db_handler(config) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6631
diff
changeset
|
105 |
handler.init_test_database() |
8558
133101245cac
[db creation test] more testing of db initialization: call build_db_cache and ensure admin user exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
106 |
handler.build_db_cache() |
133101245cac
[db creation test] more testing of db initialization: call build_db_cache and ensure admin user exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
107 |
repo, cnx = handler.get_repo_and_cnx() |
9576
5d4f662f5e31
[devtools] make get_repo_and_cnx return a repoapi ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9460
diff
changeset
|
108 |
with cnx: |
5d4f662f5e31
[devtools] make get_repo_and_cnx return a repoapi ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9460
diff
changeset
|
109 |
self.assertEqual(cnx.execute('Any SN WHERE X is CWUser, X login "admin", X in_state S, S name SN').rows, |
5d4f662f5e31
[devtools] make get_repo_and_cnx return a repoapi ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9460
diff
changeset
|
110 |
[['activated']]) |
8558
133101245cac
[db creation test] more testing of db initialization: call build_db_cache and ensure admin user exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8544
diff
changeset
|
111 |
repo.shutdown() |
0 | 112 |
|
113 |
if __name__ == '__main__': |
|
114 |
unittest_main() |