mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
fix tests
This commit is contained in:
@@ -107,6 +107,15 @@ async def uncached_put():
|
|||||||
put_ret = put_ret + 1
|
put_ret = put_ret + 1
|
||||||
return {"value": put_ret}
|
return {"value": put_ret}
|
||||||
|
|
||||||
|
put_ret2 = 0
|
||||||
|
|
||||||
|
@app.get("/cached_put")
|
||||||
|
@cache(namespace="test", expire=5)
|
||||||
|
async def cached_put():
|
||||||
|
global put_ret2
|
||||||
|
put_ret2 = put_ret2 + 1
|
||||||
|
return {"value": put_ret2}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/namespaced_injection")
|
@app.get("/namespaced_injection")
|
||||||
@cache(namespace="test", expire=5, injected_dependency_namespace="monty_python")
|
@cache(namespace="test", expire=5, injected_dependency_namespace="monty_python")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "fastapi-cache2"
|
name = "fastapi-cache2"
|
||||||
version = "0.2.3"
|
version = "0.2.1"
|
||||||
description = "Cache for FastAPI"
|
description = "Cache for FastAPI"
|
||||||
authors = ["long2ice <long2ice@gmail.com>"]
|
authors = ["long2ice <long2ice@gmail.com>"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
@@ -99,10 +99,10 @@ def test_pydantic_model() -> None:
|
|||||||
|
|
||||||
def test_non_get() -> None:
|
def test_non_get() -> None:
|
||||||
with TestClient(app) as client:
|
with TestClient(app) as client:
|
||||||
response = client.put("/uncached_put")
|
response = client.put("/cached_put")
|
||||||
assert "X-FastAPI-Cache" not in response.headers
|
assert "X-FastAPI-Cache" not in response.headers
|
||||||
assert response.json() == {"value": 1}
|
assert response.json() == {"value": 1}
|
||||||
response = client.put("/uncached_put")
|
response = client.put("/cached_put")
|
||||||
assert "X-FastAPI-Cache" not in response.headers
|
assert "X-FastAPI-Cache" not in response.headers
|
||||||
assert response.json() == {"value": 2}
|
assert response.json() == {"value": 2}
|
||||||
|
|
||||||
@@ -115,25 +115,23 @@ def test_alternate_injected_namespace() -> None:
|
|||||||
|
|
||||||
def test_cache_control() -> None:
|
def test_cache_control() -> None:
|
||||||
with TestClient(app) as client:
|
with TestClient(app) as client:
|
||||||
response = client.put("/uncached_put")
|
response = client.get("/cached_put")
|
||||||
assert "X-FastAPI-Cache" not in response.headers
|
|
||||||
assert response.json() == {"value": 1}
|
assert response.json() == {"value": 1}
|
||||||
|
|
||||||
# HIT
|
# HIT
|
||||||
response = client.put("/uncached_put")
|
response = client.get("/cached_put")
|
||||||
assert response.headers.get("X-FastAPI-Cache") == "HIT"
|
|
||||||
assert response.json() == {"value": 1}
|
assert response.json() == {"value": 1}
|
||||||
|
|
||||||
# no-cache
|
# 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}
|
assert response.json() == {"value": 2}
|
||||||
|
|
||||||
response = client.put("/uncached_put")
|
response = client.get("/cached_put")
|
||||||
assert response.json() == {"value": 2}
|
assert response.json() == {"value": 2}
|
||||||
|
|
||||||
# no-store
|
# 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}
|
assert response.json() == {"value": 3}
|
||||||
|
|
||||||
response = client.put("/uncached_put")
|
response = client.get("/cached_put")
|
||||||
assert response.json() == {"value": 2}
|
assert response.json() == {"value": 2}
|
||||||
|
|||||||
Reference in New Issue
Block a user