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

1from fastapi import Depends, FastAPI, Response 1abcde

2from fastapi.testclient import TestClient 1abcde

3 

4app = FastAPI() 1abcde

5 

6 

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

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

9 return {} 1abcde

10 

11 

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

13 return dep 1abcde

14 

15 

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

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

18 return {"dep": dep} 1abcde

19 

20 

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

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

23 return {"dep": dep} 1abcde

24 

25 

26client = TestClient(app) 1abcde

27 

28 

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 )