Skip to content

Commit 74e827d

Browse files
author
John Lyu
committed
fix tests
1 parent 6ef59f0 commit 74e827d

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

examples/in_memory/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ async def uncached_put():
107107
put_ret = put_ret + 1
108108
return {"value": put_ret}
109109

110+
put_ret2 = 0
111+
112+
@app.get("/cached_put")
113+
@cache(namespace="test", expire=5)
114+
async def cached_put():
115+
global put_ret2
116+
put_ret2 = put_ret2 + 1
117+
return {"value": put_ret2}
118+
110119

111120
@app.get("/namespaced_injection")
112121
@cache(namespace="test", expire=5, injected_dependency_namespace="monty_python")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fastapi-cache2"
3-
version = "0.2.3"
3+
version = "0.2.1"
44
description = "Cache for FastAPI"
55
authors = ["long2ice <[email protected]>"]
66
license = "Apache-2.0"

tests/test_decorator.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ def test_pydantic_model() -> None:
9999

100100
def test_non_get() -> None:
101101
with TestClient(app) as client:
102-
response = client.put("/uncached_put")
102+
response = client.put("/cached_put")
103103
assert "X-FastAPI-Cache" not in response.headers
104104
assert response.json() == {"value": 1}
105-
response = client.put("/uncached_put")
105+
response = client.put("/cached_put")
106106
assert "X-FastAPI-Cache" not in response.headers
107107
assert response.json() == {"value": 2}
108108

@@ -115,25 +115,23 @@ def test_alternate_injected_namespace() -> None:
115115

116116
def test_cache_control() -> None:
117117
with TestClient(app) as client:
118-
response = client.put("/uncached_put")
119-
assert "X-FastAPI-Cache" not in response.headers
118+
response = client.get("/cached_put")
120119
assert response.json() == {"value": 1}
121120

122121
# HIT
123-
response = client.put("/uncached_put")
124-
assert response.headers.get("X-FastAPI-Cache") == "HIT"
122+
response = client.get("/cached_put")
125123
assert response.json() == {"value": 1}
126124

127125
# no-cache
128-
response = client.put("/uncached_put", headers={"Cache-Control": "no-cache"})
126+
response = client.get("/cached_put", headers={"Cache-Control": "no-cache"})
129127
assert response.json() == {"value": 2}
130128

131-
response = client.put("/uncached_put")
129+
response = client.get("/cached_put")
132130
assert response.json() == {"value": 2}
133131

134132
# no-store
135-
response = client.put("/uncached_put", headers={"Cache-Control": "no-store"})
133+
response = client.get("/cached_put", headers={"Cache-Control": "no-store"})
136134
assert response.json() == {"value": 3}
137135

138-
response = client.put("/uncached_put")
136+
response = client.get("/cached_put")
139137
assert response.json() == {"value": 2}

0 commit comments

Comments
 (0)