summaryrefslogtreecommitdiff
path: root/tests/settings_tests
diff options
context:
space:
mode:
authorAnton Samarchyan <desecho@gmail.com>2017-07-26 20:00:28 -0400
committerTim Graham <timograham@gmail.com>2017-07-26 20:00:28 -0400
commitc91dcd36fc46ad562af054bc0cad2f0055b0f7eb (patch)
tree71dddee025c2b212ff4ad52ce48c593d542f627f /tests/settings_tests
parent0eefda493b293c129d5bf52b5606c6b1a85e197f (diff)
downloaddjango-c91dcd36fc46ad562af054bc0cad2f0055b0f7eb.tar.gz
Improved test coverage for django.conf.
Diffstat (limited to 'tests/settings_tests')
-rw-r--r--tests/settings_tests/tests.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py
index edcb2dabc8..1ab08cbd14 100644
--- a/tests/settings_tests/tests.py
+++ b/tests/settings_tests/tests.py
@@ -3,6 +3,7 @@ import sys
import unittest
import warnings
from types import ModuleType
+from unittest import mock
from django.conf import ENVIRONMENT_VARIABLE, LazySettings, Settings, settings
from django.core.exceptions import ImproperlyConfigured
@@ -11,6 +12,7 @@ from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, modify_settings,
override_settings, signals,
)
+from django.test.utils import requires_tz_support
@modify_settings(ITEMS={
@@ -286,6 +288,42 @@ class SettingsTests(SimpleTestCase):
with self.assertRaises(AttributeError):
getattr(settings, 'TEST2')
+ def test_no_secret_key(self):
+ settings_module = ModuleType('fake_settings_module')
+ sys.modules['fake_settings_module'] = settings_module
+ msg = 'The SECRET_KEY setting must not be empty.'
+ try:
+ with self.assertRaisesMessage(ImproperlyConfigured, msg):
+ Settings('fake_settings_module')
+ finally:
+ del sys.modules['fake_settings_module']
+
+ def test_no_settings_module(self):
+ msg = (
+ 'Requested setting%s, but settings are not configured. You '
+ 'must either define the environment variable DJANGO_SETTINGS_MODULE '
+ 'or call settings.configure() before accessing settings.'
+ )
+ orig_settings = os.environ[ENVIRONMENT_VARIABLE]
+ os.environ[ENVIRONMENT_VARIABLE] = ''
+ try:
+ with self.assertRaisesMessage(ImproperlyConfigured, msg % 's'):
+ settings._setup()
+ with self.assertRaisesMessage(ImproperlyConfigured, msg % ' TEST'):
+ settings._setup('TEST')
+ finally:
+ os.environ[ENVIRONMENT_VARIABLE] = orig_settings
+
+ def test_already_configured(self):
+ with self.assertRaisesMessage(RuntimeError, 'Settings already configured.'):
+ settings.configure()
+
+ @requires_tz_support
+ @mock.patch('django.conf.global_settings.TIME_ZONE', 'test')
+ def test_incorrect_timezone(self):
+ with self.assertRaisesMessage(ValueError, 'Incorrect timezone setting: test'):
+ settings._setup()
+
class TestComplexSettingOverride(SimpleTestCase):
def setUp(self):