Add tests for sync and disabled cache

This commit is contained in:
Charl P. Botha
2022-10-14 21:59:33 +02:00
parent ceb70426f3
commit 630b175766
2 changed files with 32 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import time
import pendulum
from fastapi_cache import FastAPICache
from starlette.testclient import TestClient
from examples.in_memory.main import app
@@ -21,3 +22,26 @@ def test_datetime():
now = pendulum.parse(now).replace(microsecond=0)
assert now != now_
assert now == pendulum.now().replace(microsecond=0)
def test_date():
"""Test path function without request or response arguments."""
with TestClient(app) as client:
response = client.get("/date")
assert pendulum.parse(response.json()) == pendulum.today()
# do it again to test cache
response = client.get("/date")
assert pendulum.parse(response.json()) == pendulum.today()
# now test with cache disabled, as that's a separate code path
FastAPICache._enable = False
response = client.get("/date")
assert pendulum.parse(response.json()) == pendulum.today()
FastAPICache._enable = True
def test_sync():
"""Ensure that sync function support works."""
with TestClient(app) as client:
response = client.get("/sync-me")
assert response.json() == 42