diff --git a/examples/miniapps/fastapi-simple/fastapi_di_example.py b/examples/miniapps/fastapi-simple/fastapi_di_example.py index d6c3b1f1..9f3d3f83 100644 --- a/examples/miniapps/fastapi-simple/fastapi_di_example.py +++ b/examples/miniapps/fastapi-simple/fastapi_di_example.py @@ -1,13 +1,11 @@ -import sys - from fastapi import FastAPI, Depends from dependency_injector import containers, providers -from dependency_injector.wiring import inject, Provide +from dependency_injector.wiring import Provide, inject class Service: async def process(self) -> str: - return 'Ok' + return "OK" class Container(containers.DeclarativeContainer): @@ -18,12 +16,12 @@ class Container(containers.DeclarativeContainer): app = FastAPI() -@app.api_route('/') +@app.api_route("/") @inject async def index(service: Service = Depends(Provide[Container.service])): result = await service.process() - return {'result': result} + return {"result": result} container = Container() -container.wire(modules=[sys.modules[__name__]]) +container.wire(modules=[__name__]) diff --git a/examples/miniapps/fastapi-simple/tests.py b/examples/miniapps/fastapi-simple/tests.py index dc4f6203..d7bd7d1f 100644 --- a/examples/miniapps/fastapi-simple/tests.py +++ b/examples/miniapps/fastapi-simple/tests.py @@ -8,7 +8,7 @@ from fastapi_di_example import app, container, Service @pytest.fixture def client(event_loop): - client = AsyncClient(app=app, base_url='http://test') + client = AsyncClient(app=app, base_url="http://test") yield client event_loop.run_until_complete(client.aclose()) @@ -16,10 +16,10 @@ def client(event_loop): @pytest.mark.asyncio async def test_index(client): service_mock = mock.AsyncMock(spec=Service) - service_mock.process.return_value = 'Foo' + service_mock.process.return_value = "Foo" with container.service.override(service_mock): - response = await client.get('/') + response = await client.get("/") assert response.status_code == 200 - assert response.json() == {'result': 'Foo'} + assert response.json() == {"result": "Foo"}