Added and refactored tests

This commit is contained in:
Mawoka
2022-04-03 15:59:34 +02:00
parent ce75b28397
commit cfb5dbcb66
13 changed files with 283 additions and 110 deletions
+11 -5
View File
@@ -1,22 +1,28 @@
from .deta_storage import DetaStorage
from .local_storage import LocalStorage
from io import BytesIO
from typing import Optional
class Storage:
def __init__(self, backend: str, deta_key: str | None, deta_id: str | None, storage_path: str | None):
def __init__(self, backend: str, deta_key: Optional[str], deta_id: Optional[str], storage_path: Optional[str]):
self.backend = backend
self.deta_key = deta_key
self.deta_id = deta_id
self.deta_key: str | None = deta_key
self.deta_id: str | None = deta_id
self.deta_base_url = f"https://drive.deta.sh/v1/{deta_id}/classquiz1"
self.deta_instance = DetaStorage(deta_base_url=self.deta_base_url, deta_key=self.deta_key, deta_id=self.deta_id)
self.local_instance = LocalStorage(base_path=storage_path)
if backend == "deta":
if deta_key is None or deta_id is None:
raise ValueError("deta_key and deta_id must be provided")
else:
self.deta_instance = DetaStorage(deta_base_url=self.deta_base_url, deta_key=self.deta_key,
deta_id=self.deta_id)
elif backend == "local":
if storage_path is None:
raise ValueError("storage_path must be provided")
else:
self.local_instance = LocalStorage(base_path=storage_path)
else:
raise NotImplementedError(f"Backend {backend} not implemented")