From 2c0fda7f206f2057df642939e51358944b313483 Mon Sep 17 00:00:00 2001 From: orlnub123 Date: Fri, 22 Feb 2019 21:36:11 +0300 Subject: [PATCH] Refs #30057 -- Added more diffsettings tests. The test in 573f44d62fe1e87e2c20a74eba5e20ca9ff0ed85 doesn't act as a regression test. --- .../configured_dynamic_settings_manage.py | 20 +++++++++++++++++++ tests/admin_scripts/tests.py | 18 +++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/admin_scripts/configured_dynamic_settings_manage.py diff --git a/tests/admin_scripts/configured_dynamic_settings_manage.py b/tests/admin_scripts/configured_dynamic_settings_manage.py new file mode 100644 index 0000000000..b4a9cf83fb --- /dev/null +++ b/tests/admin_scripts/configured_dynamic_settings_manage.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +import sys + +from django.conf import global_settings, settings +from django.core.management import execute_from_command_line + + +class Settings: + def __getattr__(self, name): + if name == 'FOO': + return 'bar' + return getattr(global_settings, name) + + def __dir__(self): + return super().__dir__() + dir(global_settings) + ['FOO'] + + +if __name__ == '__main__': + settings.configure(Settings()) + execute_from_command_line(sys.argv) diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index d48a0c8071..32233cf258 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -129,10 +129,10 @@ class AdminScriptTestCase(SimpleTestCase): script_dir = os.path.abspath(os.path.join(os.path.dirname(django.__file__), 'bin')) return self.run_test(os.path.join(script_dir, 'django-admin.py'), args, settings_file) - def run_manage(self, args, settings_file=None, configured_settings=False): + def run_manage(self, args, settings_file=None, manage_py=None): template_manage_py = ( - os.path.join(os.path.dirname(__file__), 'configured_settings_manage.py') - if configured_settings else + os.path.join(os.path.dirname(__file__), manage_py) + if manage_py else os.path.join(os.path.dirname(conf.__file__), 'project_template', 'manage.py-tpl') ) test_manage_py = os.path.join(self.test_dir, 'manage.py') @@ -2139,11 +2139,21 @@ class DiffSettings(AdminScriptTestCase): out, err = self.run_manage(args) self.assertNoOutput(err) self.assertOutput(out, "FOO = 'bar' ###") + # Attributes from django.conf.Settings don't appear. + self.assertNotInOutput(out, 'is_overridden = ') def test_settings_configured(self): - out, err = self.run_manage(['diffsettings'], configured_settings=True) + out, err = self.run_manage(['diffsettings'], manage_py='configured_settings_manage.py') self.assertNoOutput(err) self.assertOutput(out, 'CUSTOM = 1 ###\nDEBUG = True') + # Attributes from django.conf.UserSettingsHolder don't appear. + self.assertNotInOutput(out, 'default_settings = ') + + def test_dynamic_settings_configured(self): + # Custom default settings appear. + out, err = self.run_manage(['diffsettings'], manage_py='configured_dynamic_settings_manage.py') + self.assertNoOutput(err) + self.assertOutput(out, "FOO = 'bar' ###") def test_all(self): """The all option also shows settings with the default value."""