Coverage for tests/test_repeated_cookie_headers.py: 100%
19 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
7def set_cookie(*, response: Response): 1abcde
8 response.set_cookie("cookie-name", "cookie-value") 1abcde
9 return {} 1abcde
12def set_indirect_cookie(*, dep: str = Depends(set_cookie)): 1abcde
13 return dep 1abcde
16@app.get("/directCookie") 1abcde
17def get_direct_cookie(dep: str = Depends(set_cookie)): 1abcde
18 return {"dep": dep} 1abcde
21@app.get("/indirectCookie") 1abcde
22def get_indirect_cookie(dep: str = Depends(set_indirect_cookie)): 1abcde
23 return {"dep": dep} 1abcde
26client = TestClient(app) 1abcde
29def test_cookie_is_set_once(): 1abcde
30 direct_response = client.get("/directCookie") 1abcde
31 indirect_response = client.get("/indirectCookie") 1abcde
32 assert ( 1abcde
33 direct_response.headers["set-cookie"] == indirect_response.headers["set-cookie"]
34 )