fix #424, no-cache should store the result to cache

This commit is contained in:
John Lyu
2024-05-09 14:32:02 +08:00
parent 91ba6d7552
commit e4a0df62dd
2 changed files with 28 additions and 3 deletions

View File

@@ -112,3 +112,28 @@ def test_alternate_injected_namespace() -> None:
response = client.get("/namespaced_injection")
assert response.headers.get("X-FastAPI-Cache") == "MISS"
assert response.json() == {"__fastapi_cache_request": 42, "__fastapi_cache_response": 17}
def test_cache_control() -> None:
with TestClient(app) as client:
response = client.get("/uncached_put")
assert "X-FastAPI-Cache" not in response.headers
assert response.json() == {"value": 1}
# HIT
response = client.get("/uncached_put")
assert response.headers.get("X-FastAPI-Cache") == "HIT"
assert response.json() == {"value": 1}
# no-cache
response = client.get("/uncached_put", headers={"Cache-Control": "no-cache"})
assert response.json() == {"value": 2}
response = client.get("/uncached_put")
assert response.json() == {"value": 2}
# no-store
response = client.get("/uncached_put", headers={"Cache-Control": "no-store"})
assert response.json() == {"value": 3}
response = client.get("/uncached_put")
assert response.json() == {"value": 2}