From 97ba0f4b4b3de2bdcb4ea0c388ad3c34e12dcd61 Mon Sep 17 00:00:00 2001 From: Peter Schutt Date: Wed, 11 Jan 2023 16:35:22 +1000 Subject: [PATCH] test(service): test enqueue with custom job config. --- tests/unit/test_service.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py index 8699616b..e9f4b57d 100644 --- a/tests/unit/test_service.py +++ b/tests/unit/test_service.py @@ -131,6 +131,26 @@ async def test_enqueue_service_callback(monkeypatch: "MonkeyPatch") -> None: } +async def test_enqueue_service_callback_with_custom_job_config(monkeypatch: "MonkeyPatch") -> None: + """Tests that job enqueued with desired arguments.""" + enqueue_mock = AsyncMock() + monkeypatch.setattr(worker.queue, "enqueue", enqueue_mock) + service_instance = domain.authors.Service(session=db.async_session_factory()) + await service_instance.enqueue_background_task( + "receive_callback", job_config=worker.JobConfig(timeout=999), raw_obj={"a": "b"} + ) + enqueue_mock.assert_called_once() + assert isinstance(enqueue_mock.mock_calls[0].args[0], Job) + job = enqueue_mock.mock_calls[0].args[0] + assert job.function == service.make_service_callback.__qualname__ + assert job.timeout == 999 + assert job.kwargs == { + "service_type_id": "tests.utils.domain.authors.Service", + "service_method_name": "receive_callback", + "raw_obj": {"a": "b"}, + } + + async def test_service_new_context_manager() -> None: """Simple test of `Service.new()` context manager behavior.""" async with service.Service[domain.authors.Author].new() as service_obj: