Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
test(service): test enqueue with custom job config.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterschutt committed Jan 11, 2023
1 parent b209a23 commit 97ba0f4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/unit/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 97ba0f4

Please sign in to comment.