fix tests

This commit is contained in:
John Lyu
2024-05-09 14:51:58 +08:00
parent 6ef59f0eb3
commit 74e827d3de
3 changed files with 18 additions and 11 deletions

View File

@@ -99,10 +99,10 @@ def test_pydantic_model() -> None:
def test_non_get() -> None:
with TestClient(app) as client:
response = client.put("/uncached_put")
response = client.put("/cached_put")
assert "X-FastAPI-Cache" not in response.headers
assert response.json() == {"value": 1}
response = client.put("/uncached_put")
response = client.put("/cached_put")
assert "X-FastAPI-Cache" not in response.headers
assert response.json() == {"value": 2}
@@ -115,25 +115,23 @@ def test_alternate_injected_namespace() -> None:
def test_cache_control() -> None:
with TestClient(app) as client:
response = client.put("/uncached_put")
assert "X-FastAPI-Cache" not in response.headers
response = client.get("/cached_put")
assert response.json() == {"value": 1}
# HIT
response = client.put("/uncached_put")
assert response.headers.get("X-FastAPI-Cache") == "HIT"
response = client.get("/cached_put")
assert response.json() == {"value": 1}
# no-cache
response = client.put("/uncached_put", headers={"Cache-Control": "no-cache"})
response = client.get("/cached_put", headers={"Cache-Control": "no-cache"})
assert response.json() == {"value": 2}
response = client.put("/uncached_put")
response = client.get("/cached_put")
assert response.json() == {"value": 2}
# no-store
response = client.put("/uncached_put", headers={"Cache-Control": "no-store"})
response = client.get("/cached_put", headers={"Cache-Control": "no-store"})
assert response.json() == {"value": 3}
response = client.put("/uncached_put")
response = client.get("/cached_put")
assert response.json() == {"value": 2}