def test_reset(self): MultiListPartRegistry.loaded = True MultiListPartRegistry.lists = {'type': []} MultiListPartRegistry.reset() self.assertFalse(MultiListPartRegistry.loaded) self.assertDictEqual(MultiListPartRegistry.lists, {})
def test_load(self): lock_mock = MagicMock() MultiListPartRegistry.lock = lock_mock # no part_class defined self.assertRaisesMessage( ImproperlyConfigured, 'Please specify a base class for the parts that are to be loaded', MultiListPartRegistry.load ) MultiListPartRegistry.part_class = object # no subpath defined self.assertRaisesMessage( ImproperlyConfigured, 'Please specify a python sub path for the function that is to be called', MultiListPartRegistry.load ) MultiListPartRegistry.call_function_subpath = 'subpath.load' with patch('django_appregistration.MultiListPartRegistry._checked_apps') as _checked_apps: # should not find the module and therefore raise an import error _checked_apps.return_value=['non_existent'] MultiListPartRegistry.load() self.assertTrue(MultiListPartRegistry.loaded) self.assertDictEqual(MultiListPartRegistry.lists, {}) _checked_apps.assert_called_once_with() _checked_apps.reset_mock() MultiListPartRegistry.reset() # should find the module but does not have the function _checked_apps.return_value=['django_appregistration.tests'] MultiListPartRegistry.load() self.assertTrue(MultiListPartRegistry.loaded) self.assertDictEqual(MultiListPartRegistry.lists, {}) _checked_apps.assert_called_once_with() _checked_apps.reset_mock() MultiListPartRegistry.reset() with patch('django_appregistration.tests.subpath') as subpath: # finds the module but load is not callable subpath.load = object() MultiListPartRegistry.load() self.assertTrue(MultiListPartRegistry.loaded) self.assertDictEqual(MultiListPartRegistry.lists, {}) _checked_apps.assert_called_once_with() _checked_apps.reset_mock() MultiListPartRegistry.reset() subpath.load = MagicMock() MultiListPartRegistry.load() self.assertTrue(MultiListPartRegistry.loaded) self.assertDictEqual(MultiListPartRegistry.lists, {}) subpath.load.assert_called_once_with(MultiListPartRegistry) _checked_apps.assert_called_once_with() _checked_apps.reset_mock() MultiListPartRegistry.reset() # already loaded MultiListPartRegistry.loaded=True MultiListPartRegistry.load() self.assertDictEqual(MultiListPartRegistry.lists, {}) self.assertEqual(_checked_apps.call_count, 0) _checked_apps.reset_mock()
def tearDown(self): MultiListPartRegistry.reset() MultiListPartRegistry.part_class = None MultiListPartRegistry.ignore_django_namespace = True MultiListPartRegistry.call_function_subpath = None