python-dependency-injector/examples/miniapps/fastapi-simple/tests.py
Roman Mogylatov fe01ad41d9
Update examples to use config __init__ args (#527)
* Update application-single-container example

* Update application-multiple-containers example

* Update decoupled-packages example

* Update movie lister example

* Update CLI tutorial

* Update sanic example

* Update sanic example with wiring_config

* Update fastapi example

* Update fastapi-simple example

* Update fastapi-sqlalchemy example

* Update flask-blueprints example

* Update flask example and tutorial

* Update aiohttp example and tutorial

* Update asyncio-daemon example and tutorial
2021-10-31 20:31:39 -04:00

25 lines
595 B
Python

from unittest import mock
import pytest
from httpx import AsyncClient
from fastapi_di_example import app, container, Service
@pytest.fixture
async def client(event_loop):
async with AsyncClient(app=app, base_url="http://test") as client:
yield client
@pytest.mark.asyncio
async def test_index(client):
service_mock = mock.AsyncMock(spec=Service)
service_mock.process.return_value = "Foo"
with container.service.override(service_mock):
response = await client.get("/")
assert response.status_code == 200
assert response.json() == {"result": "Foo"}