Skip to content

Commit ccd9992

Browse files
committed
Update the extra-config tests for the new way that settings behave
The previous approach of reloading the settings module worked ok when the module itself was what was imported & mutated, however with the move to a layered approach that's no longer the case.
1 parent 33554ef commit ccd9992

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tests/test_extra_config.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import importlib
21
from typing import Optional
32
from pathlib import Path
3+
from unittest import mock
44

55
from django.test import SimpleTestCase
66

@@ -27,11 +27,19 @@ def length(self, queue: QueueName) -> int:
2727
class ExtraConfigTests(SimpleTestCase):
2828
def setUp(self) -> None:
2929
get_backend.cache_clear()
30+
31+
self.settings: app_settings.Settings = app_settings.AppSettings([app_settings.Defaults()])
32+
self._settings_patch = mock.patch(
33+
'django_lightweight_queue.utils.app_settings',
34+
new=self.settings,
35+
)
36+
self._settings_patch.start()
37+
3038
super().setUp()
3139

3240
def tearDown(self) -> None:
33-
importlib.reload(app_settings)
3441
get_backend.cache_clear()
42+
self._settings_patch.stop()
3543
super().tearDown()
3644

3745
def test_updates_configuration(self) -> None:
@@ -40,20 +48,20 @@ def test_updates_configuration(self) -> None:
4048
backend = get_backend('test-queue')
4149
self.assertIsInstance(backend, TestBackend)
4250

43-
self.assertEqual('a very bad password', app_settings.REDIS_PASSWORD)
51+
self.assertEqual('a very bad password', self.settings.REDIS_PASSWORD)
4452

4553
def test_warns_about_unexpected_settings(self) -> None:
4654
with self.assertWarnsRegex(Warning, r'Ignoring unexpected setting.+\bNOT_REDIS_PASSWORD\b'):
4755
load_extra_config(str(TESTS_DIR / '_demo_extra_config_unexpected.py'))
4856

49-
self.assertEqual('expected', app_settings.REDIS_PASSWORD)
57+
self.assertEqual('expected', self.settings.REDIS_PASSWORD)
5058

5159
def test_updates_configuration_with_falsey_values(self) -> None:
5260
load_extra_config(str(TESTS_DIR / '_demo_extra_config.py'))
5361
load_extra_config(str(TESTS_DIR / '_demo_extra_config_falsey.py'))
5462

55-
self.assertIsNone(app_settings.REDIS_PASSWORD)
56-
self.assertFalse(app_settings.ATOMIC_JOBS)
63+
self.assertIsNone(self.settings.REDIS_PASSWORD)
64+
self.assertFalse(self.settings.ATOMIC_JOBS)
5765

5866
def test_rejects_missing_file(self) -> None:
5967
with self.assertRaises(FileNotFoundError):

0 commit comments

Comments
 (0)