mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 01:47:36 +03:00 
			
		
		
		
	Update fastapi example
This commit is contained in:
		
							parent
							
								
									04faec5b00
								
							
						
					
					
						commit
						14744e4b70
					
				| 
						 | 
				
			
			@ -101,21 +101,21 @@ The output should be something like:
 | 
			
		|||
 | 
			
		||||
.. code-block::
 | 
			
		||||
 | 
			
		||||
   platform darwin -- Python 3.9, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
 | 
			
		||||
   plugins: cov-2.10.0, asyncio-0.14.0
 | 
			
		||||
   platform darwin -- Python 3.10.0, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
 | 
			
		||||
   plugins: asyncio-0.16.0, cov-3.0.0
 | 
			
		||||
   collected 3 items
 | 
			
		||||
 | 
			
		||||
   giphynavigator/tests.py ...                                     [100%]
 | 
			
		||||
 | 
			
		||||
   ---------- coverage: platform darwin, python 3.9 -----------
 | 
			
		||||
   ---------- coverage: platform darwin, python 3.10.0-final-0 ----------
 | 
			
		||||
   Name                            Stmts   Miss  Cover
 | 
			
		||||
   ---------------------------------------------------
 | 
			
		||||
   giphynavigator/__init__.py          0      0   100%
 | 
			
		||||
   giphynavigator/application.py      13      0   100%
 | 
			
		||||
   giphynavigator/containers.py        6      0   100%
 | 
			
		||||
   giphynavigator/application.py      11      0   100%
 | 
			
		||||
   giphynavigator/containers.py        7      0   100%
 | 
			
		||||
   giphynavigator/endpoints.py        20      0   100%
 | 
			
		||||
   giphynavigator/giphy.py            14      9    36%
 | 
			
		||||
   giphynavigator/services.py          9      1    89%
 | 
			
		||||
   giphynavigator/tests.py            38      0   100%
 | 
			
		||||
   giphynavigator/tests.py            37      0   100%
 | 
			
		||||
   ---------------------------------------------------
 | 
			
		||||
   TOTAL                             100     10    90%
 | 
			
		||||
   TOTAL                              98     10    90%
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,9 +8,7 @@ from . import endpoints
 | 
			
		|||
 | 
			
		||||
def create_app() -> FastAPI:
 | 
			
		||||
    container = Container()
 | 
			
		||||
    container.config.from_yaml("config.yml")
 | 
			
		||||
    container.config.giphy.api_key.from_env("GIPHY_API_KEY")
 | 
			
		||||
    container.wire(modules=[endpoints])
 | 
			
		||||
 | 
			
		||||
    app = FastAPI()
 | 
			
		||||
    app.container = container
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,9 @@ from . import giphy, services
 | 
			
		|||
 | 
			
		||||
class Container(containers.DeclarativeContainer):
 | 
			
		||||
 | 
			
		||||
    config = providers.Configuration()
 | 
			
		||||
    wiring_config = containers.WiringConfiguration(modules=[".endpoints"])
 | 
			
		||||
 | 
			
		||||
    config = providers.Configuration(yaml_files=["config.yml"])
 | 
			
		||||
 | 
			
		||||
    giphy_client = providers.Factory(
 | 
			
		||||
        giphy.GiphyClient,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,10 +10,9 @@ from giphynavigator.giphy import GiphyClient
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
@pytest.fixture
 | 
			
		||||
def client(event_loop):
 | 
			
		||||
    client = AsyncClient(app=app, base_url="http://test")
 | 
			
		||||
async def client():
 | 
			
		||||
    async with AsyncClient(app=app, base_url="http://test") as client:
 | 
			
		||||
        yield client
 | 
			
		||||
    event_loop.run_until_complete(client.aclose())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.mark.asyncio
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user