Skip to content

Commit 4edc550

Browse files
committed
Add test for enqueuing async task on incompatible backend
1 parent 31a2ef4 commit 4edc550

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/tests/test_custom_backend.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from typing import Any
2+
from unittest import mock
3+
4+
from django.test import SimpleTestCase, override_settings
5+
6+
from django_tasks import default_task_backend, tasks
7+
from django_tasks.backends.base import BaseTaskBackend
8+
from django_tasks.exceptions import InvalidTaskError
9+
from django_tasks.utils import get_module_path
10+
from tests import tasks as test_tasks
11+
12+
13+
class CustomBackend(BaseTaskBackend):
14+
def enqueue(self, *args: Any, **kwargs: Any) -> Any:
15+
pass
16+
17+
18+
@override_settings(
19+
TASKS={
20+
"default": {
21+
"BACKEND": get_module_path(CustomBackend),
22+
"ENQUEUE_ON_COMMIT": False,
23+
}
24+
}
25+
)
26+
class CustomBackendTestCase(SimpleTestCase):
27+
def test_using_correct_backend(self) -> None:
28+
self.assertEqual(default_task_backend, tasks["default"])
29+
self.assertIsInstance(tasks["default"], CustomBackend)
30+
31+
@mock.patch.multiple(CustomBackend, supports_async_task=False)
32+
def test_enqueue_async_task_on_non_async_backend(self) -> None:
33+
with self.assertRaisesMessage(
34+
InvalidTaskError, "Backend does not support async tasks"
35+
):
36+
default_task_backend.validate_task(test_tasks.noop_task_async)

0 commit comments

Comments
 (0)