Coverage for tests/test_response_change_status_code.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from fastapi import Depends, FastAPI, Response 1abcde
2from fastapi.testclient import TestClient 1abcde
4app = FastAPI() 1abcde
7async def response_status_setter(response: Response): 1abcde
8 response.status_code = 201 1abcde
11async def parent_dep(result=Depends(response_status_setter)): 1abcde
12 return result 1abcde
15@app.get("/", dependencies=[Depends(parent_dep)]) 1abcde
16async def get_main(): 1abcde
17 return {"msg": "Hello World"} 1abcde
20client = TestClient(app) 1abcde
23def test_dependency_set_status_code(): 1abcde
24 response = client.get("/") 1abcde
25 assert response.status_code == 201, response.text 1abcde
26 assert response.json() == {"msg": "Hello World"} 1abcde