def test_list(self): """ Additional settings can extend lists in the original module. """ global_conf = {"debug": "yes", "django_settings_module": "tests.fixtures.list_module"} local_conf = {"DA_LIST": (8, 9)} _set_up_settings(global_conf, local_conf) from tests.fixtures import list_module self.assertEqual(os.environ["DJANGO_SETTINGS_MODULE"], "tests.fixtures.list_module") self.assertEqual(list_module.DA_LIST, (1, 2, 3, 8, 9))
def test_name_clash(self): """ Additional settings must not override initial values in settings.py. """ global_conf = {"debug": "yes", "django_settings_module": "tests.fixtures.one_member_module"} local_conf = {"MEMBER": "FOO"} _set_up_settings(global_conf, local_conf) from tests.fixtures import one_member_module self.assertEqual(os.environ["DJANGO_SETTINGS_MODULE"], "tests.fixtures.one_member_module") self.assertEqual(one_member_module.MEMBER, "MEMBER") self.assertTrue(len(self.logs["warning"]), 1) self.assertEqual('"MEMBER" will not be overridden in tests.fixtures.one_member_module', self.logs["warning"][0])
def test_no_additional_settings(self): """ The settings module must be left as is if there are no additional settings. """ global_conf = {"debug": "yes", "django_settings_module": "tests.fixtures.empty_module2"} _set_up_settings(global_conf, {}) from tests.fixtures import empty_module2 self.assertEqual(os.environ["DJANGO_SETTINGS_MODULE"], "tests.fixtures.empty_module2") # Ignoring the built-in members: scope = [value for value in dir(empty_module2) if not value.startswith("__") and value.endswith("__")] self.assertEqual(len(scope), 0)
def test_no_initial_settings(self): """ Additional settings must be added even if there's no initial settings. """ global_conf = {"debug": "yes", "django_settings_module": "tests.fixtures.empty_module"} local_conf = {"setting1": object(), "setting2": object()} _set_up_settings(global_conf, local_conf) from tests.fixtures import empty_module self.assertEqual(os.environ["DJANGO_SETTINGS_MODULE"], "tests.fixtures.empty_module") self.assertTrue(hasattr(empty_module, "setting1")) self.assertTrue(hasattr(empty_module, "setting2")) self.assertEqual(empty_module.setting1, local_conf["setting1"]) self.assertEqual(empty_module.setting2, local_conf["setting2"])
def test_list(self): """ Additional settings can extend lists in the original module. """ global_conf = { 'debug': "yes", 'django_settings_module': "tests.fixtures.list_module", } local_conf = { 'DA_LIST': (8, 9), } _set_up_settings(global_conf, local_conf) from tests.fixtures import list_module eq_(os.environ['DJANGO_SETTINGS_MODULE'], "tests.fixtures.list_module") eq_(list_module.DA_LIST, (1, 2, 3, 8, 9))
def test_no_additional_settings(self): """ The settings module must be left as is if there are no additional settings. """ global_conf = { 'debug': "yes", 'django_settings_module': "tests.fixtures.empty_module2", } _set_up_settings(global_conf, {}) from tests.fixtures import empty_module2 eq_(os.environ['DJANGO_SETTINGS_MODULE'], "tests.fixtures.empty_module2") # Ignoring the built-in members: scope = [value for value in dir(empty_module2) if not value.startswith("__") and value.endswith("__")] eq_(len(scope), 0)
def test_no_initial_settings(self): """ Additional settings must be added even if there's no initial settings. """ global_conf = { 'debug': "yes", 'django_settings_module': "tests.fixtures.empty_module", } local_conf = { 'setting1': object(), 'setting2': object(), } _set_up_settings(global_conf, local_conf) from tests.fixtures import empty_module eq_(os.environ['DJANGO_SETTINGS_MODULE'], "tests.fixtures.empty_module") ok_(hasattr(empty_module, "setting1")) ok_(hasattr(empty_module, "setting2")) eq_(empty_module.setting1, local_conf['setting1']) eq_(empty_module.setting2, local_conf['setting2'])
def test_name_clash(self): """ Additional settings must not override initial values in settings.py. """ global_conf = { 'debug': "yes", 'django_settings_module': "tests.fixtures.one_member_module", } local_conf = { 'MEMBER': "FOO", } _set_up_settings(global_conf, local_conf) from tests.fixtures import one_member_module eq_(os.environ['DJANGO_SETTINGS_MODULE'], "tests.fixtures.one_member_module") eq_(one_member_module.MEMBER, "MEMBER") ok_(len(self.logs['warning']), 1) eq_('"MEMBER" will not be overridden in tests.fixtures.one_member_module', self.logs['warning'][0])