Files
Random-image-api/backend/tests/test_job_dispatch.py
T
2026-02-22 18:58:55 +08:00

33 lines
859 B
Python

from __future__ import annotations
import asyncio
import pytest
from app.jobs.dispatch import JobDispatcher
def test_job_dispatch_calls_registered_handler() -> None:
dispatcher = JobDispatcher()
called: list[int] = []
async def _handler(job):
called.append(int(job["id"]))
dispatcher.register("noop", _handler)
asyncio.run(dispatcher.dispatch({"id": 1, "type": "noop"}))
assert called == [1]
def test_job_dispatch_unknown_type_rejected() -> None:
dispatcher = JobDispatcher()
with pytest.raises(ValueError, match="Unknown job type"):
asyncio.run(dispatcher.dispatch({"id": 1, "type": "unknown"}))
def test_job_dispatch_missing_type_rejected() -> None:
dispatcher = JobDispatcher()
with pytest.raises(ValueError, match="Unknown job type"):
asyncio.run(dispatcher.dispatch({"id": 1}))