File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments