mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
feat: fix tests and add FastAPICache init in tests.
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
import time
|
||||
from typing import Generator
|
||||
|
||||
import pendulum
|
||||
import pytest
|
||||
|
||||
from fastapi_cache import FastAPICache
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
from examples.in_memory.main import app
|
||||
from fastapi_cache.backends.inmemory import InMemoryBackend
|
||||
|
||||
|
||||
def test_datetime():
|
||||
@pytest.fixture(autouse=True)
|
||||
def init_cache() -> Generator:
|
||||
FastAPICache.init(InMemoryBackend())
|
||||
yield
|
||||
FastAPICache.reset()
|
||||
|
||||
|
||||
def test_datetime() -> None:
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/datetime")
|
||||
now = response.json().get("now")
|
||||
@@ -23,7 +34,8 @@ def test_datetime():
|
||||
assert now != now_
|
||||
assert now == pendulum.now().replace(microsecond=0)
|
||||
|
||||
def test_date():
|
||||
|
||||
def test_date() -> None:
|
||||
"""Test path function without request or response arguments."""
|
||||
with TestClient(app) as client:
|
||||
|
||||
@@ -40,7 +52,8 @@ def test_date():
|
||||
assert pendulum.parse(response.json()) == pendulum.today()
|
||||
FastAPICache._enable = True
|
||||
|
||||
def test_sync():
|
||||
|
||||
def test_sync() -> None:
|
||||
"""Ensure that sync function support works."""
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/sync-me")
|
||||
|
||||
Reference in New Issue
Block a user