19 |
19 |
20 import sys |
20 import sys |
21 import os |
21 import os |
22 import tempfile |
22 import tempfile |
23 from os.path import dirname, join, abspath |
23 from os.path import dirname, join, abspath |
|
24 from pkg_resources import EntryPoint, Distribution |
24 import unittest |
25 import unittest |
25 |
26 |
|
27 from mock import patch |
26 from six import PY3 |
28 from six import PY3 |
27 |
29 |
28 from logilab.common.modutils import cleanup_sys_modules |
30 from logilab.common.modutils import cleanup_sys_modules |
29 from logilab.common.testlib import with_tempdir |
31 from logilab.common.testlib import with_tempdir |
30 from logilab.common.changelog import Version |
32 from logilab.common.changelog import Version |
57 self.config = ApptestConfiguration('data', __file__) |
59 self.config = ApptestConfiguration('data', __file__) |
58 self.config._cubes = ('email', 'file') |
60 self.config._cubes = ('email', 'file') |
59 |
61 |
60 def tearDown(self): |
62 def tearDown(self): |
61 ApptestConfiguration.CUBES_PATH = [] |
63 ApptestConfiguration.CUBES_PATH = [] |
|
64 |
|
65 def iter_entry_points(group, name): |
|
66 """Mock pkg_resources.iter_entry_points to yield EntryPoint from |
|
67 packages found in test/data/libpython even though these are not |
|
68 installed. |
|
69 """ |
|
70 libpython = CubicWebConfigurationTC.datapath('libpython') |
|
71 prefix = 'cubicweb_' |
|
72 for pkgname in os.listdir(libpython): |
|
73 if not pkgname.startswith(prefix): |
|
74 continue |
|
75 location = join(libpython, pkgname) |
|
76 yield EntryPoint(pkgname[len(prefix):], pkgname, |
|
77 dist=Distribution(location)) |
|
78 |
|
79 @patch('pkg_resources.iter_entry_points', side_effect=iter_entry_points) |
|
80 def test_available_cubes(self, mock_iter_entry_points): |
|
81 expected_cubes = [ |
|
82 'card', 'cubicweb_comment', 'cubicweb_email', 'file', |
|
83 'cubicweb_file', 'cubicweb_forge', 'localperms', |
|
84 'cubicweb_mycube', 'tag', |
|
85 ] |
|
86 self._test_available_cubes(expected_cubes) |
|
87 mock_iter_entry_points.assert_called_once_with( |
|
88 group='cubicweb.cubes', name=None) |
|
89 |
|
90 def _test_available_cubes(self, expected_cubes): |
|
91 self.assertEqual(self.config.available_cubes(), expected_cubes) |
62 |
92 |
63 def test_reorder_cubes(self): |
93 def test_reorder_cubes(self): |
64 # forge depends on email and file and comment |
94 # forge depends on email and file and comment |
65 # email depends on file |
95 # email depends on file |
66 self.assertEqual(self.config.reorder_cubes(['file', 'email', 'forge']), |
96 self.assertEqual(self.config.reorder_cubes(['file', 'email', 'forge']), |
130 self.config.__class__.CUBES_PATH = [self.custom_cubes_dir] |
160 self.config.__class__.CUBES_PATH = [self.custom_cubes_dir] |
131 self.config.adjust_sys_path() |
161 self.config.adjust_sys_path() |
132 |
162 |
133 def tearDown(self): |
163 def tearDown(self): |
134 ApptestConfiguration.CUBES_PATH = [] |
164 ApptestConfiguration.CUBES_PATH = [] |
|
165 |
|
166 def test_available_cubes(self): |
|
167 expected_cubes = sorted(set([ |
|
168 # local cubes |
|
169 'comment', 'email', 'file', 'forge', 'mycube', |
|
170 # test dependencies |
|
171 'card', 'file', 'localperms', 'tag', |
|
172 ])) |
|
173 self._test_available_cubes(expected_cubes) |
135 |
174 |
136 def test_reorder_cubes_recommends(self): |
175 def test_reorder_cubes_recommends(self): |
137 from cubes.comment import __pkginfo__ as comment_pkginfo |
176 from cubes.comment import __pkginfo__ as comment_pkginfo |
138 self._test_reorder_cubes_recommends(comment_pkginfo) |
177 self._test_reorder_cubes_recommends(comment_pkginfo) |
139 |
178 |
157 self.assertEqual(cubes.__path__, self.config.cubes_search_path()) |
196 self.assertEqual(cubes.__path__, self.config.cubes_search_path()) |
158 # this import should succeed once path is adjusted |
197 # this import should succeed once path is adjusted |
159 from cubes import mycube |
198 from cubes import mycube |
160 self.assertEqual(mycube.__path__, [join(self.custom_cubes_dir, 'mycube')]) |
199 self.assertEqual(mycube.__path__, [join(self.custom_cubes_dir, 'mycube')]) |
161 # file cube should be overriden by the one found in data/cubes |
200 # file cube should be overriden by the one found in data/cubes |
162 sys.modules.pop('cubes.file', None) |
201 if sys.modules.pop('cubes.file', None) and PY3: |
163 if PY3: |
|
164 del cubes.file |
202 del cubes.file |
165 from cubes import file |
203 from cubes import file |
166 self.assertEqual(file.__path__, [join(self.custom_cubes_dir, 'file')]) |
204 self.assertEqual(file.__path__, [join(self.custom_cubes_dir, 'file')]) |
167 |
205 |
168 |
206 |