Coverage for tests / test_repeated_cookie_headers.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1from fastapi import Depends, FastAPI, Response 1abcd

2from fastapi.testclient import TestClient 1abcd

3 

4app = FastAPI() 1abcd

5 

6 

7def set_cookie(*, response: Response): 1abcd

8 response.set_cookie("cookie-name", "cookie-value") 1efgh

9 return {} 1efgh

10 

11 

12def set_indirect_cookie(*, dep: str = Depends(set_cookie)): 1abcd

13 return dep 1efgh

14 

15 

16@app.get("/directCookie") 1abcd

17def get_direct_cookie(dep: str = Depends(set_cookie)): 1abcd

18 return {"dep": dep} 1efgh

19 

20 

21@app.get("/indirectCookie") 1abcd

22def get_indirect_cookie(dep: str = Depends(set_indirect_cookie)): 1abcd

23 return {"dep": dep} 1efgh

24 

25 

26client = TestClient(app) 1abcd

27 

28 

29def test_cookie_is_set_once(): 1abcd

30 direct_response = client.get("/directCookie") 1efgh

31 indirect_response = client.get("/indirectCookie") 1efgh

32 assert ( 1efg

33 direct_response.headers["set-cookie"] == indirect_response.headers["set-cookie"] 

34 )