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

1import pytest 

2import pytest_asyncio 

3from fastapi.exceptions import RequestValidationError 

4 

5from faststream.rabbit import TestRabbitBroker 

6 

7from .app import handler, publisher, router 

8 

9 

10@pytest_asyncio.fixture 

11async def broker(): 

12 async with TestRabbitBroker(router.broker) as br: 

13 yield br 

14 

15 

16@pytest.mark.asyncio() 

17async def test_incorrect(broker): 

18 with pytest.raises(RequestValidationError): 

19 await broker.publish("user-id", "test-q") 

20 

21 

22@pytest.mark.asyncio() 

23async def test_handler(broker): 

24 user_id = 1 

25 

26 await broker.publish(user_id, "test-q") 

27 

28 handler.mock.assert_called_once_with(user_id) 

29 publisher.mock.assert_called_once_with(f"{user_id} created")