[config] Test loading of ccplugin modules 3.25
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 29 Mar 2017 10:34:39 +0200
branch3.25
changeset 12118 d7947c3c0eeb
parent 12117 49beb974888f
child 12119 c4ed3f6463f6
[config] Test loading of ccplugin modules to ensure ccplugin modules of cube as package aren't loaded twice, once as `cubicweb_<cube>.ccplugin`, once as `cubes.<cube>.ccplugin`. This test used to fail until fe995d56c949 has been backout. It requires calling `cleanup_sys_module` in `CubicWebConfigurationTC.tearDown` to remove any cube's submodule loaded during tests, so content of `sys.modules` may be tested.
cubicweb/test/data/libpython/cubicweb_mycube/ccplugin.py
cubicweb/test/unittest_cwconfig.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_mycube/ccplugin.py	Wed Mar 29 10:34:39 2017 +0200
@@ -0,0 +1,1 @@
+# simply there to test ccplugin module autoloading
--- a/cubicweb/test/unittest_cwconfig.py	Wed Mar 29 10:34:16 2017 +0200
+++ b/cubicweb/test/unittest_cwconfig.py	Wed Mar 29 10:34:39 2017 +0200
@@ -124,6 +124,7 @@
 
     def tearDown(self):
         ApptestConfiguration.CUBES_PATH = []
+        cleanup_sys_modules([self.datapath('libpython')])
 
     @patch('pkg_resources.iter_entry_points', side_effect=iter_entry_points)
     def test_available_cubes(self, mock_iter_entry_points):
@@ -187,6 +188,15 @@
         self.assertIn(warning_msg, cm.output[0])
         self.assertNotIn('pyramid', self.config._cubes)
 
+    @patch('pkg_resources.iter_entry_points', side_effect=iter_entry_points)
+    def test_ccplugin_modname(self, mock_iter_entry_points):
+        self.config.load_cwctl_plugins()
+        mock_iter_entry_points.assert_called_once_with(
+            group='cubicweb.cubes', name=None)
+        self.assertNotIn('cubes.mycube.ccplugin', sys.modules, sorted(sys.modules))
+        self.assertIn('cubicweb_mycube.ccplugin', sys.modules, sorted(sys.modules))
+
+
 class CubicWebConfigurationWithLegacyCubesTC(CubicWebConfigurationTC):
 
     @classmethod
@@ -274,7 +284,12 @@
             self.assertEqual(self.config['allow-email-login'], result)
         finally:
             del os.environ['CW_ALLOW_EMAIL_LOGIN']
-            
+
+    def test_ccplugin_modname(self):
+        self.config.load_cwctl_plugins()
+        self.assertIn('cubes.mycube.ccplugin', sys.modules, sorted(sys.modules))
+        self.assertNotIn('cubicweb_mycube.ccplugin', sys.modules, sorted(sys.modules))
+
 
 class FindPrefixTC(unittest.TestCase):