Browse Source
* Added test for repeating cookies in response headers * update `response` headers, status code to match `sub_response` in `solve_dependencies` only if necessary; fix formatting of scottsmith2gmail's test * restore code coverage, remove dead code from `solve_dependencies` Co-authored-by: Scott Smith <[email protected]>pull/1576/head
committed by
GitHub
2 changed files with 35 additions and 5 deletions
@ -0,0 +1,34 @@ |
|||||
|
from fastapi import Depends, FastAPI, Response |
||||
|
from fastapi.testclient import TestClient |
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
|
||||
|
def set_cookie(*, response: Response): |
||||
|
response.set_cookie("cookie-name", "cookie-value") |
||||
|
return {} |
||||
|
|
||||
|
|
||||
|
def set_indirect_cookie(*, dep: str = Depends(set_cookie)): |
||||
|
return dep |
||||
|
|
||||
|
|
||||
|
@app.get("/directCookie") |
||||
|
def get_direct_cookie(dep: str = Depends(set_cookie)): |
||||
|
return {"dep": dep} |
||||
|
|
||||
|
|
||||
|
@app.get("/indirectCookie") |
||||
|
def get_indirect_cookie(dep: str = Depends(set_indirect_cookie)): |
||||
|
return {"dep": dep} |
||||
|
|
||||
|
|
||||
|
client = TestClient(app) |
||||
|
|
||||
|
|
||||
|
def test_cookie_is_set_once(): |
||||
|
direct_response = client.get("/directCookie") |
||||
|
indirect_response = client.get("/indirectCookie") |
||||
|
assert ( |
||||
|
direct_response.headers["set-cookie"] == indirect_response.headers["set-cookie"] |
||||
|
) |
Loading…
Reference in new issue