mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-27 12:04:00 +03:00
fe01ad41d9
* 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
25 lines
595 B
Python
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"}
|