Apply reference design to Astro and add screenshot storage
This commit is contained in:
@@ -85,3 +85,12 @@ def test_user_report_requires_moderation_before_activity() -> None:
|
||||
|
||||
def test_admin_requires_token() -> None:
|
||||
assert client.get("/api/v1/admin/catch-reports").status_code == 401
|
||||
|
||||
|
||||
def test_pending_report_accepts_one_validated_screenshot(monkeypatch) -> None:
|
||||
created = client.post("/api/v1/catch-reports", json={"fish_slug": "pike", "waterbody_slug": "test-lake", "x": 91, "y": 92, "weight_g": 4200}).json()
|
||||
monkeypatch.setattr("app.main.upload_screenshot", lambda raw: "reports/test.jpg" if raw == b"image-bytes" else "unexpected")
|
||||
response = client.post(f"/api/v1/catch-reports/{created['id']}/screenshot", files={"screenshot": ("catch.jpg", b"image-bytes", "image/jpeg")})
|
||||
assert response.status_code == 204
|
||||
duplicate = client.post(f"/api/v1/catch-reports/{created['id']}/screenshot", files={"screenshot": ("catch.jpg", b"image-bytes", "image/jpeg")})
|
||||
assert duplicate.status_code == 409
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from app.storage import ScreenshotError, prepare_image
|
||||
|
||||
|
||||
def test_prepare_image_removes_metadata() -> None:
|
||||
source = Image.new("RGB", (32, 24), "#12383b")
|
||||
exif = Image.Exif()
|
||||
exif[0x010E] = "private note"
|
||||
raw = io.BytesIO()
|
||||
source.save(raw, format="JPEG", exif=exif)
|
||||
|
||||
cleaned, extension, mime = prepare_image(raw.getvalue())
|
||||
|
||||
with Image.open(io.BytesIO(cleaned)) as result:
|
||||
assert result.getexif() == {}
|
||||
assert result.size == (32, 24)
|
||||
assert (extension, mime) == ("jpg", "image/jpeg")
|
||||
|
||||
|
||||
def test_prepare_image_rejects_non_image() -> None:
|
||||
with pytest.raises(ScreenshotError, match="valid image"):
|
||||
prepare_image(b"not an image")
|
||||
Reference in New Issue
Block a user