author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 05 May 2010 18:54:04 +0200 | |
branch | oldstable |
changeset 5484 | 95f2384b4495 |
parent 5424 | 8ecbcbff9777 |
child 5426 | 0d4853a6e5ee |
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
18 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
19 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
20 |
""" |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
21 |
import sys |
0 | 22 |
import os |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
23 |
from os.path import dirname, join, abspath |
0 | 24 |
|
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4681
diff
changeset
|
25 |
from logilab.common.modutils import cleanup_sys_modules |
0 | 26 |
from logilab.common.testlib import TestCase, unittest_main |
27 |
from logilab.common.changelog import Version |
|
28 |
||
29 |
from cubicweb.devtools import ApptestConfiguration |
|
30 |
||
31 |
def unabsolutize(path): |
|
32 |
parts = path.split(os.sep) |
|
515
92d95b86263e
search in reverted order else in case of installed cubes (eg in cubicweb/cubes) we do not remove all expected parts
sylvain.thenault@logilab.fr
parents:
13
diff
changeset
|
33 |
for i, part in reversed(tuple(enumerate(parts))): |
1341 | 34 |
if part.startswith('cubicweb') or part == 'cubes': |
0 | 35 |
return '/'.join(parts[i+1:]) |
36 |
raise Exception('duh? %s' % path) |
|
1640 | 37 |
|
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
38 |
CUSTOM_CUBES_DIR = abspath(join(dirname(__file__), 'data', 'cubes')) |
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
39 |
|
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
40 |
|
0 | 41 |
class CubicWebConfigurationTC(TestCase): |
42 |
def setUp(self): |
|
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4681
diff
changeset
|
43 |
cleanup_sys_modules([CUSTOM_CUBES_DIR, ApptestConfiguration.CUBES_DIR]) |
0 | 44 |
self.config = ApptestConfiguration('data') |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
45 |
self.config._cubes = ('email', 'file') |
0 | 46 |
|
1341 | 47 |
def tearDown(self): |
48 |
os.environ.pop('CW_CUBES_PATH', None) |
|
49 |
||
0 | 50 |
def test_reorder_cubes(self): |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
51 |
# jpl depends on email and file and comment |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
52 |
# email depends on file |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
53 |
self.assertEquals(self.config.reorder_cubes(['file', 'email', 'forge']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
54 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
55 |
self.assertEquals(self.config.reorder_cubes(['email', 'file', 'forge']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
56 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
57 |
self.assertEquals(self.config.reorder_cubes(['email', 'forge', 'file']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
58 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
59 |
self.assertEquals(self.config.reorder_cubes(['file', 'forge', 'email']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
60 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
61 |
self.assertEquals(self.config.reorder_cubes(['forge', 'file', 'email']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
62 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
63 |
self.assertEquals(self.config.reorder_cubes(('forge', 'email', 'file')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
64 |
('forge', 'email', 'file')) |
1640 | 65 |
|
0 | 66 |
def test_reorder_cubes_recommends(self): |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
67 |
from cubes.comment import __pkginfo__ as comment_pkginfo |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
68 |
comment_pkginfo.__recommend__ = ('file',) |
0 | 69 |
try: |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
70 |
# email recommends comment |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
71 |
# comment recommends file |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
72 |
self.assertEquals(self.config.reorder_cubes(('forge', 'email', 'file', 'comment')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
73 |
('forge', 'email', 'comment', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
74 |
self.assertEquals(self.config.reorder_cubes(('forge', 'email', 'comment', 'file')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
75 |
('forge', 'email', 'comment', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
76 |
self.assertEquals(self.config.reorder_cubes(('forge', 'comment', 'email', 'file')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
77 |
('forge', 'email', 'comment', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
78 |
self.assertEquals(self.config.reorder_cubes(('comment', 'forge', 'email', 'file')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
79 |
('forge', 'email', 'comment', 'file')) |
0 | 80 |
finally: |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
81 |
comment_pkginfo.__use__ = () |
1640 | 82 |
|
83 |
||
0 | 84 |
# def test_vc_config(self): |
85 |
# vcconf = self.config.vc_config() |
|
86 |
# self.assertIsInstance(vcconf['EEMAIL'], Version) |
|
87 |
# self.assertEquals(vcconf['EEMAIL'], (0, 3, 1)) |
|
88 |
# self.assertEquals(vcconf['CW'], (2, 31, 2)) |
|
89 |
# self.assertRaises(KeyError, vcconf.__getitem__, 'CW_VERSION') |
|
90 |
# self.assertRaises(KeyError, vcconf.__getitem__, 'CRM') |
|
1640 | 91 |
|
0 | 92 |
def test_expand_cubes(self): |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
93 |
self.assertEquals(self.config.expand_cubes(('email', 'blog')), |
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
94 |
['email', 'blog', 'file']) |
0 | 95 |
|
96 |
def test_vregistry_path(self): |
|
97 |
self.assertEquals([unabsolutize(p) for p in self.config.vregistry_path()], |
|
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2446
diff
changeset
|
98 |
['entities', 'web/views', 'sobjects', 'hooks', |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
99 |
'file/entities.py', 'file/views', 'file/hooks.py', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
100 |
'email/entities.py', 'email/views', 'email/hooks.py', |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
101 |
'test/data/entities.py', 'test/data/views.py']) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
102 |
|
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
103 |
def test_cubes_path(self): |
1023
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
104 |
# make sure we don't import the email cube, but the stdlib email package |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
105 |
import email |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
106 |
self.assertNotEquals(dirname(email.__file__), self.config.CUBES_DIR) |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
107 |
os.environ['CW_CUBES_PATH'] = CUSTOM_CUBES_DIR |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
108 |
self.assertEquals(self.config.cubes_search_path(), |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
109 |
[CUSTOM_CUBES_DIR, self.config.CUBES_DIR]) |
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
110 |
os.environ['CW_CUBES_PATH'] = os.pathsep.join([ |
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
111 |
CUSTOM_CUBES_DIR, self.config.CUBES_DIR, 'unexistant']) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
112 |
# filter out unexistant and duplicates |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
113 |
self.assertEquals(self.config.cubes_search_path(), |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
114 |
[CUSTOM_CUBES_DIR, |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
115 |
self.config.CUBES_DIR]) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
116 |
self.failUnless('mycube' in self.config.available_cubes()) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
117 |
# test cubes python path |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
118 |
self.config.adjust_sys_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
119 |
import cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
120 |
self.assertEquals(cubes.__path__, self.config.cubes_search_path()) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
121 |
# this import should succeed once path is adjusted |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
122 |
from cubes import mycube |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
123 |
self.assertEquals(mycube.__path__, [join(CUSTOM_CUBES_DIR, 'mycube')]) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
124 |
# file cube should be overriden by the one found in data/cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
125 |
sys.modules.pop('cubes.file', None) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
126 |
del cubes.file |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
127 |
from cubes import file |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
128 |
self.assertEquals(file.__path__, [join(CUSTOM_CUBES_DIR, 'file')]) |
1640 | 129 |
|
130 |
||
0 | 131 |
if __name__ == '__main__': |
132 |
unittest_main() |