feat: fix tests and add FastAPICache init in tests.

This commit is contained in:
Ivan Moiseev
2022-10-22 21:12:04 +04:00
parent e842d6408e
commit c6bd8483a4
2 changed files with 28 additions and 5 deletions

View File

@@ -34,6 +34,16 @@ class FastAPICache:
cls._key_builder = key_builder
cls._enable = enable
@classmethod
def reset(cls) -> None:
cls._init = False
cls._backend = None
cls._prefix = None
cls._expire = None
cls._coder = None
cls._key_builder = None
cls._enable = True
@classmethod
def get_backend(cls) -> Backend:
assert cls._backend, "You must call init first!" # nosec: B101
@@ -41,7 +51,7 @@ class FastAPICache:
@classmethod
def get_prefix(cls) -> str:
assert cls._prefix, "You must call init first!" # nosec: B101
assert cls._prefix is not None, "You must call init first!" # nosec: B101
return cls._prefix
@classmethod
@@ -64,6 +74,6 @@ class FastAPICache:
@classmethod
async def clear(cls, namespace: Optional[str] = None, key: Optional[str] = None) -> int:
assert cls._backend and cls._prefix, "You must call init first!" # nosec: B101
assert cls._backend and cls._prefix is not None, "You must call init first!" # nosec: B101
namespace = cls._prefix + (":" + namespace if namespace else "")
return await cls._backend.clear(namespace, key)