Coverage for examples / fastapi_integration / testing.py: 86%
14 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-08 01:48 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-08 01:48 +0000
1import pytest
2import pytest_asyncio
3from fastapi.exceptions import RequestValidationError
5from faststream.rabbit import TestRabbitBroker
7from .app import handler, publisher, router
10@pytest_asyncio.fixture
11async def broker():
12 async with TestRabbitBroker(router.broker) as br:
13 yield br
16@pytest.mark.asyncio()
17async def test_incorrect(broker):
18 with pytest.raises(RequestValidationError):
19 await broker.publish("user-id", "test-q")
22@pytest.mark.asyncio()
23async def test_handler(broker):
24 user_id = 1
26 await broker.publish(user_id, "test-q")
28 handler.mock.assert_called_once_with(user_id)
29 publisher.mock.assert_called_once_with(f"{user_id} created")