Coverage for docs_src/app_testing/tutorial003.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import FastAPI 1abcde

2from fastapi.testclient import TestClient 1abcde

3 

4app = FastAPI() 1abcde

5 

6items = {} 1abcde

7 

8 

9@app.on_event("startup") 1abcde

10async def startup_event(): 1abcde

11 items["foo"] = {"name": "Fighters"} 1abcde

12 items["bar"] = {"name": "Tenders"} 1abcde

13 

14 

15@app.get("/items/{item_id}") 1abcde

16async def read_items(item_id: str): 1abcde

17 return items[item_id] 1abcde

18 

19 

20def test_read_items(): 1abcde

21 with TestClient(app) as client: 1abcde

22 response = client.get("/items/foo") 1abcde

23 assert response.status_code == 200 1abcde

24 assert response.json() == {"name": "Fighters"} 1abcde