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 00000000000..b4a9cf83fba --- /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 d48a0c8071c..32233cf2589 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."""