test #459: fix failing datetime and date logic tests; fix failing non GET tests which called unimplemented example endpoints

This commit is contained in:
Gary Gale
2024-11-09 22:25:40 +00:00
parent 3402cd20c9
commit e57db36253

View File

@@ -1,4 +1,5 @@
import time import time
from http import HTTPStatus
from typing import Any, Generator from typing import Any, Generator
import pendulum import pendulum
@@ -22,19 +23,17 @@ def test_datetime() -> None:
response = client.get("/datetime") response = client.get("/datetime")
assert response.headers.get("X-FastAPI-Cache") == "MISS" assert response.headers.get("X-FastAPI-Cache") == "MISS"
now = response.json().get("now") now = response.json().get("now")
now_ = pendulum.now() now_ = pendulum.parse(now)
assert pendulum.parse(now) == now_
response = client.get("/datetime") response = client.get("/datetime")
assert response.headers.get("X-FastAPI-Cache") == "HIT" assert response.headers.get("X-FastAPI-Cache") == "HIT"
now = response.json().get("now") now = response.json().get("now")
assert pendulum.parse(now) == now_ assert pendulum.parse(now) == now_
time.sleep(3) time.sleep(3)
response = client.get("/datetime") response = client.get("/datetime")
now = response.json().get("now")
assert response.headers.get("X-FastAPI-Cache") == "MISS" assert response.headers.get("X-FastAPI-Cache") == "MISS"
now = response.json().get("now")
now = pendulum.parse(now) now = pendulum.parse(now)
assert now != now_ assert now != now_
assert now == pendulum.now()
def test_date() -> None: def test_date() -> None:
@@ -100,11 +99,13 @@ 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("/cached_put") response = client.put("/cached_put")
assert response.status_code == HTTPStatus.METHOD_NOT_ALLOWED
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("/cached_put") response = client.put("/cached_put")
assert response.status_code == HTTPStatus.METHOD_NOT_ALLOWED
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}
def test_alternate_injected_namespace() -> None: def test_alternate_injected_namespace() -> None: