1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #30057 -- Added more diffsettings tests.

The test in 573f44d62f doesn't act as a
regression test.
This commit is contained in:
orlnub123 2019-02-22 21:36:11 +03:00 committed by Tim Graham
parent 65ef5f467b
commit 2c0fda7f20
2 changed files with 34 additions and 4 deletions

View File

@ -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)

View File

@ -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."""