[cwconfig] Strip "cubicweb_" prefix from cube name in available_cubes()
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 08 Feb 2017 17:54:16 +0100
changeset 11966 fe995d56c949
parent 11965 fb03a4113979
child 11967 83739be20fab
[cwconfig] Strip "cubicweb_" prefix from cube name in available_cubes() Closes #17054738.
cubicweb/cwconfig.py
cubicweb/test/unittest_cwconfig.py
--- a/cubicweb/cwconfig.py	Tue Feb 21 10:12:47 2017 +0100
+++ b/cubicweb/cwconfig.py	Wed Feb 08 17:54:16 2017 +0100
@@ -503,6 +503,7 @@
     @classmethod
     def available_cubes(cls):
         cubes = set()
+        prefix = 'cubicweb_'
         for entry_point in pkg_resources.iter_entry_points(
                 group='cubicweb.cubes', name=None):
             try:
@@ -511,11 +512,11 @@
                 continue
             else:
                 modname = module.__name__
-                if not modname.startswith('cubicweb_'):
+                if not modname.startswith(prefix):
                     cls.warning('entry point %s does not appear to be a cube',
                                 entry_point)
                     continue
-                cubes.add(modname)
+                cubes.add(modname[len(prefix):])
         # Legacy cubes.
         for directory in cls.cubes_search_path():
             if not exists(directory):
--- a/cubicweb/test/unittest_cwconfig.py	Tue Feb 21 10:12:47 2017 +0100
+++ b/cubicweb/test/unittest_cwconfig.py	Wed Feb 08 17:54:16 2017 +0100
@@ -127,9 +127,9 @@
     @patch('pkg_resources.iter_entry_points', side_effect=iter_entry_points)
     def test_available_cubes(self, mock_iter_entry_points):
         expected_cubes = [
-            'card', 'comment', 'cubicweb_comment', 'cubicweb_email', 'file',
-            'cubicweb_file', 'cubicweb_forge', 'localperms',
-            'cubicweb_mycube', 'tag',
+            'card', 'comment', 'email', 'file',
+            'forge', 'localperms',
+            'mycube', 'tag',
         ]
         self._test_available_cubes(expected_cubes)
         mock_iter_entry_points.assert_called_once_with(