cubicweb/test/unittest_cwconfig.py
changeset 12518 12e8b65146d9
parent 12517 34c4157b1071
child 12547 a11119d327e4
equal deleted inserted replaced
12517:34c4157b1071 12518:12e8b65146d9
    82             del sys.modules[module]
    82             del sys.modules[module]
    83 
    83 
    84 
    84 
    85 def iter_entry_points(group, name):
    85 def iter_entry_points(group, name):
    86     """Mock pkg_resources.iter_entry_points to yield EntryPoint from
    86     """Mock pkg_resources.iter_entry_points to yield EntryPoint from
    87     packages found in test/data/libpython even though these are not
    87     packages found in test/data even though these are not
    88     installed.
    88     installed.
    89     """
    89     """
    90     libpython = CubicWebConfigurationTC.datapath('libpython')
    90     libpython = CubicWebConfigurationTC.datapath()
    91     prefix = 'cubicweb_'
    91     prefix = 'cubicweb_'
    92     for pkgname in os.listdir(libpython):
    92     for pkgname in os.listdir(libpython):
    93         if not pkgname.startswith(prefix):
    93         if not pkgname.startswith(prefix):
    94             continue
    94             continue
    95         location = join(libpython, pkgname)
    95         location = join(libpython, pkgname)
    99 
    99 
   100 class CubicWebConfigurationTC(BaseTestCase):
   100 class CubicWebConfigurationTC(BaseTestCase):
   101 
   101 
   102     @classmethod
   102     @classmethod
   103     def setUpClass(cls):
   103     def setUpClass(cls):
   104         sys.path.append(cls.datapath('libpython'))
   104         sys.path.append(cls.datapath())
   105 
   105 
   106     @classmethod
   106     @classmethod
   107     def tearDownClass(cls):
   107     def tearDownClass(cls):
   108         sys.path.remove(cls.datapath('libpython'))
   108         sys.path.remove(cls.datapath())
   109 
   109 
   110     def setUp(self):
   110     def setUp(self):
   111         self.config = ApptestConfiguration('data', __file__)
   111         self.config = ApptestConfiguration('data', __file__)
   112         self.config._cubes = ('email', 'file')
   112         self.config._cubes = ('email', 'file')
   113 
   113 
   114     def tearDown(self):
   114     def tearDown(self):
   115         ApptestConfiguration.CUBES_PATH = []
   115         ApptestConfiguration.CUBES_PATH = []
   116         cleanup_sys_modules([self.datapath('libpython')])
   116         cleanup_sys_modules([self.datapath()])
   117 
   117 
   118     def test_migration_scripts_dir(self):
   118     def test_migration_scripts_dir(self):
   119         mscripts = os.listdir(self.config.migration_scripts_dir())
   119         mscripts = os.listdir(self.config.migration_scripts_dir())
   120         self.assertIn('bootstrapmigration_repository.py', mscripts)
   120         self.assertIn('bootstrapmigration_repository.py', mscripts)
   121         self.assertIn('postcreate.py', mscripts)
   121         self.assertIn('postcreate.py', mscripts)
   122         self.assertIn('3.24.0_Any.py', mscripts)
   122         self.assertIn('3.24.0_Any.py', mscripts)
   123 
   123 
   124     @patch('pkg_resources.iter_entry_points', side_effect=iter_entry_points)
   124     @patch('pkg_resources.iter_entry_points', side_effect=iter_entry_points)
   125     def test_available_cubes(self, mock_iter_entry_points):
   125     def test_available_cubes(self, mock_iter_entry_points):
   126         expected_cubes = [
   126         expected_cubes = [
   127             'card', 'comment', 'cubicweb_comment', 'cubicweb_email', 'file',
   127             'cubicweb_card',
   128             'cubicweb_file', 'cubicweb_forge',
   128             'cubicweb_comment',
   129             'cubicweb_mycube', 'tag',
   129             'cubicweb_email',
       
   130             'cubicweb_file',
       
   131             'cubicweb_forge',
       
   132             'cubicweb_localperms',
       
   133             'cubicweb_mycube',
       
   134             'cubicweb_tag',
   130         ]
   135         ]
   131         self.assertEqual(self.config.available_cubes(), expected_cubes)
   136         self.assertEqual(self.config.available_cubes(), expected_cubes)
   132         mock_iter_entry_points.assert_called_once_with(
   137         mock_iter_entry_points.assert_called_once_with(
   133             group='cubicweb.cubes', name=None)
   138             group='cubicweb.cubes', name=None)
   134 
   139