Files

31 lines
907 B
Python

import uuid
from unittest.mock import AsyncMock
import pytest
from faststream.exceptions import RejectMessage
from app import consumer
from app.schemas import PaymentCreatedEvent
async def test_handler_delegates_to_processor(monkeypatch: pytest.MonkeyPatch) -> None:
processor = AsyncMock()
monkeypatch.setattr(consumer, "processor", processor)
event = PaymentCreatedEvent(payment_id=uuid.uuid4())
await consumer.handle_payment(event)
processor.process.assert_awaited_once_with(event)
async def test_handler_rejects_after_processor_failure(
monkeypatch: pytest.MonkeyPatch,
) -> None:
processor = AsyncMock()
processor.process.side_effect = RuntimeError("exhausted")
monkeypatch.setattr(consumer, "processor", processor)
event = PaymentCreatedEvent(payment_id=uuid.uuid4())
with pytest.raises(RejectMessage):
await consumer.handle_payment(event)