talos-access / backend /tests /storage /test_local_disk.py
Greg
Claude Sonnet 4.6
feat(ta-01): add PhotoStorage abstraction with Local/InMemory/Supabase adapters
9e5f651
Raw History Blame Contribute Delete
1.16 kB
from pathlib import Path
import pytest
from app.storage.local_disk import LocalDiskStorage
@pytest.fixture
def storage(tmp_path: Path) -> LocalDiskStorage:
return LocalDiskStorage(root=str(tmp_path), url_prefix="/api/v1/photos")
def test_upload_creates_file(storage: LocalDiskStorage, tmp_path: Path):
path = storage.upload(account_id=2, user_id=20, content=b"abc", ext="webp")
assert path.startswith("2/20/") and path.endswith(".webp")
full = tmp_path / path
assert full.read_bytes() == b"abc"
def test_upload_creates_parent_dirs(storage: LocalDiskStorage, tmp_path: Path):
path = storage.upload(99, 999, b"x", "webp")
assert (tmp_path / path).exists()
def test_get_url_prepends_prefix(storage: LocalDiskStorage):
path = storage.upload(1, 1, b"x", "webp")
assert storage.get_url(path) == f"/api/v1/photos/{path}"
def test_delete_removes_file(storage: LocalDiskStorage, tmp_path: Path):
path = storage.upload(1, 1, b"x", "webp")
storage.delete(path)
assert not (tmp_path / path).exists()
def test_delete_missing_file_does_not_raise(storage: LocalDiskStorage):
storage.delete("nope/nope.webp")