dav_base: improved tests
This commit is contained in:
@@ -45,6 +45,11 @@ class ModuleMetaTestCase(SimpleTestCase):
|
||||
with self.assertRaises(ImproperlyConfigured):
|
||||
_ = mm.url_conf_pattern
|
||||
|
||||
def test_str(self):
|
||||
app_name = 'dav_base.tests.fake_app1'
|
||||
mm = ModuleMeta(app_name)
|
||||
self.assertEqual(str(mm), '- {}'.format(app_name))
|
||||
|
||||
def test_load_from_dict(self):
|
||||
mm = ModuleMeta('dav_base.tests.fake_app1')
|
||||
dd = {'package': 'dav_base2.foo',
|
||||
@@ -168,19 +173,6 @@ class ModuleConfigTestCase(SimpleTestCase):
|
||||
mc = ModuleConfig(config_file_path=config_file, django_base_dir=self.config_dir)
|
||||
self.assertEqual(list(mc.modules.keys()), ['pkg11', 'pkg22'])
|
||||
|
||||
def test_save_empty(self):
|
||||
self.assertFalse(os.path.exists(self.config_file))
|
||||
with patch('dav_base.config.modules.settings') as mock_settings:
|
||||
mock_settings.BASE_DIR = self.temp_dir
|
||||
mc = ModuleConfig()
|
||||
mc.save()
|
||||
self.assertTrue(os.path.isfile(self.config_file))
|
||||
|
||||
with open(self.config_file, 'r', encoding='ascii') as f:
|
||||
config_data = json.load(f)
|
||||
|
||||
self.assertEqual(config_data, {'modules': []})
|
||||
|
||||
def test_save(self):
|
||||
config_data = {
|
||||
'modules': [
|
||||
@@ -209,3 +201,31 @@ class ModuleConfigTestCase(SimpleTestCase):
|
||||
config_data = json.load(f)
|
||||
|
||||
self.assertEqual(config_data, expected_config_data)
|
||||
|
||||
def test_save_empty(self):
|
||||
self.assertFalse(os.path.exists(self.config_file))
|
||||
with patch('dav_base.config.modules.settings') as mock_settings:
|
||||
mock_settings.BASE_DIR = self.temp_dir
|
||||
mc = ModuleConfig()
|
||||
mc.save()
|
||||
self.assertTrue(os.path.isfile(self.config_file))
|
||||
|
||||
with open(self.config_file, 'r', encoding='ascii') as f:
|
||||
config_data = json.load(f)
|
||||
|
||||
self.assertEqual(config_data, {'modules': []})
|
||||
|
||||
def test_save_overwrite(self):
|
||||
with patch('dav_base.config.modules.settings') as mock_settings:
|
||||
mock_settings.BASE_DIR = self.temp_dir
|
||||
mc = ModuleConfig()
|
||||
mc.save()
|
||||
self.assertTrue(os.path.isfile(self.config_file))
|
||||
mc.modules['mod1'] = ModuleMeta('mod1', load=False)
|
||||
mc.save()
|
||||
|
||||
with open(self.config_file, 'r', encoding='ascii') as f:
|
||||
config_data = json.load(f)
|
||||
|
||||
self.assertEqual(config_data, {'modules': [{'package': 'mod1'}]})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user