RandomZ / app /tests /test_export_photo_paths.py
StormShadow308's picture
feat: async pipeline, job queue, generation hardening, and docs
732b14f
Raw
History Blame Contribute Delete
1.89 kB
"""Export / photo path resolution."""
from __future__ import annotations
from pathlib import Path
import pytest
from app.storage.photo_paths import report_photo_relpath, resolve_report_photo_path
def test_report_photo_relpath() -> None:
rel = report_photo_relpath("tenant_a", "rep-1", "E1", "pid-1", "jpg")
assert rel == "tenant_a/report_photos/rep-1/E1/pid-1.jpg"
def test_resolve_photo_path_absolute(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("app.storage.photo_paths.settings.upload_dir", tmp_path / "uploads")
img = tmp_path / "photo.jpg"
img.write_bytes(b"fake")
assert resolve_report_photo_path(str(img)) == str(img.resolve())
def test_resolve_photo_path_under_upload_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
upload = tmp_path / "uploads"
monkeypatch.setattr("app.storage.photo_paths.settings.upload_dir", upload)
rel = report_photo_relpath("tenant", "r1", "E1", "x", "jpg")
img = upload / rel
img.parent.mkdir(parents=True)
img.write_bytes(b"fake")
assert resolve_report_photo_path(rel) == str(img.resolve())
def test_resolve_photo_path_by_photo_id(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
upload = tmp_path / "uploads"
monkeypatch.setattr("app.storage.photo_paths.settings.upload_dir", upload)
rel = report_photo_relpath("tenant", "r1", "E1", "photo-uuid", "png")
img = upload / rel
img.parent.mkdir(parents=True)
img.write_bytes(b"fake")
assert (
resolve_report_photo_path(
"/old/container/abs/path.png",
tenant_id="tenant",
report_id="r1",
section_code="E1",
photo_id="photo-uuid",
)
== str(img.resolve())
)
def test_resolve_photo_path_missing() -> None:
assert resolve_report_photo_path("/nonexistent/photo.jpg") is None