-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_debug_web_backend.py
More file actions
45 lines (32 loc) · 1.3 KB
/
test_debug_web_backend.py
File metadata and controls
45 lines (32 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import io
import unittest
import contextlib
import urllib.parse
from unittest import mock
from django.http import QueryDict
from django.urls import resolve
from django_lightweight_queue import task
from django_lightweight_queue.job import Job
from django_lightweight_queue.types import QueueName
from django_lightweight_queue.backends.debug_web import DebugWebBackend
@task()
def demo_task() -> None:
pass
class DebugWebBackendTests(unittest.TestCase):
def test_enqueue_prints_valid_url(self) -> None:
backend = DebugWebBackend()
job = Job('tests.test_debug_web_backend.demo_task', ('positional',), {'keyword': '&arg='})
with mock.patch('tests.test_debug_web_backend.demo_task') as demo_task_mock:
with contextlib.redirect_stdout(io.StringIO()) as mock_stdout:
backend.enqueue(job, QueueName('test-queue'))
url = mock_stdout.getvalue().strip()
parse_result = urllib.parse.urlparse(url)
match = resolve(parse_result.path)
self.assertIsNotNone(match, f"Failed to match {parse_result.path}")
query = QueryDict(parse_result.query)
self.assertEqual(
{'job': [job.to_json()]},
dict(query),
"Wrong query arguments printed",
)
demo_task_mock.assert_not_called()