Skip to content

Commit 5debc66

Browse files
committed
ruff
1 parent 681d377 commit 5debc66

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

docs/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Refactor the code to make it more organized and easier to maintain. This includes:
66
- All types are under `types`.
7-
-
7+
- A
88

99
## v4.0.0b2 🌈
1010

scheduler/settings.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.conf import settings
55
from django.core.exceptions import ImproperlyConfigured
66

7-
from scheduler.types import SchedulerConfiguration, Broker, QueueConfiguration
7+
from scheduler.types import SchedulerConfiguration, QueueConfiguration
88

99
logger = logging.getLogger("scheduler")
1010
logging.basicConfig(level=logging.DEBUG)
@@ -22,8 +22,8 @@ def conf_settings():
2222
global SCHEDULER_CONFIG
2323

2424
app_queues = getattr(settings, "SCHEDULER_QUEUES", None)
25-
if app_queues is None:
26-
raise ImproperlyConfigured("You have to define SCHEDULER_QUEUES in settings.py")
25+
if app_queues is None or not isinstance(app_queues, dict):
26+
raise ImproperlyConfigured("You have to define SCHEDULER_QUEUES in settings.py as dict")
2727

2828
for queue_name, queue_config in app_queues.items():
2929
if isinstance(queue_config, QueueConfiguration):
@@ -38,10 +38,6 @@ def conf_settings():
3838
return
3939
if not isinstance(user_settings, dict):
4040
raise ImproperlyConfigured("SCHEDULER_CONFIG should be a SchedulerConfiguration or dict")
41-
if "FAKEREDIS" in user_settings:
42-
logger.warning("Configuration using FAKEREDIS is deprecated. Use BROKER='fakeredis' instead")
43-
user_settings["BROKER"] = Broker.FAKEREDIS if user_settings["FAKEREDIS"] else Broker.REDIS
44-
user_settings.pop("FAKEREDIS")
4541
for k in user_settings:
4642
if k not in SCHEDULER_CONFIG.__annotations__:
4743
raise ImproperlyConfigured(f"Unknown setting {k} in SCHEDULER_CONFIG")

scheduler/tests/test_internals.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from datetime import timedelta
22

3+
from django.core.exceptions import ImproperlyConfigured
4+
from django.test import override_settings
35
from django.utils import timezone
46

57
from scheduler.helpers.callback import Callback, CallbackSetupError
@@ -37,3 +39,41 @@ def test_callback_bad_arguments(self):
3739
with self.assertRaises(CallbackSetupError) as cm:
3840
Callback(1)
3941
self.assertEqual(str(cm.exception), "Callback `func` must be a string or function, received 1")
42+
43+
44+
class TestConfSettings(SchedulerBaseCase):
45+
@override_settings(SCHEDULER_CONFIG=[])
46+
def test_conf_settings__bad_scheduler_config(self):
47+
from scheduler import settings
48+
49+
with self.assertRaises(ImproperlyConfigured) as cm:
50+
settings.conf_settings()
51+
52+
self.assertEqual(str(cm.exception), "SCHEDULER_CONFIG should be a SchedulerConfiguration or dict")
53+
54+
@override_settings(SCHEDULER_QUEUES=[])
55+
def test_conf_settings__bad_scheduler_queues_config(self):
56+
from scheduler import settings
57+
58+
with self.assertRaises(ImproperlyConfigured) as cm:
59+
settings.conf_settings()
60+
61+
self.assertEqual(str(cm.exception), "You have to define SCHEDULER_QUEUES in settings.py as dict")
62+
63+
@override_settings(SCHEDULER_QUEUES={"default": []})
64+
def test_conf_settings__bad_queue_config(self):
65+
from scheduler import settings
66+
67+
with self.assertRaises(ImproperlyConfigured) as cm:
68+
settings.conf_settings()
69+
70+
self.assertEqual(str(cm.exception), "Queue default configuration should be a QueueConfiguration or dict")
71+
72+
@override_settings(SCHEDULER_CONFIG={"UNKNOWN_SETTING": 10})
73+
def test_conf_settings__unknown_setting(self):
74+
from scheduler import settings
75+
76+
with self.assertRaises(ImproperlyConfigured) as cm:
77+
settings.conf_settings()
78+
79+
self.assertEqual(str(cm.exception), "Unknown setting UNKNOWN_SETTING in SCHEDULER_CONFIG")

0 commit comments

Comments
 (0)