"""End-to-end API tests via FastAPI TestClient.""" from __future__ import annotations import io from fastapi.testclient import TestClient from PIL import Image from extractors.app import app client = TestClient(app) def _png() -> bytes: buf = io.BytesIO() Image.new("RGB", (40, 40), (200, 10, 10)).save(buf, format="PNG") return buf.getvalue() def test_health(): r = client.get("/health") assert r.status_code == 200 assert r.json()["status"] == "ok" def test_ready_reports_tooling(): r = client.get("/ready") assert r.status_code == 200 body = r.json() assert "ffprobe" in body and "ffmpeg" in body def test_metadata_image_runs_image_extractors(): r = client.post( "/v1/metadata", files={"file": ("photo.png", _png(), "image/png")}, ) assert r.status_code == 200 body = r.json() assert body["media_type"] == "image" assert set(body["analyses"]) >= {"integrity", "exif", "ela"} assert len(body["sha256"]) == 64 assert body["execution_time_ms"] >= 0 def test_metadata_rejects_empty(): r = client.post( "/v1/metadata", files={"file": ("empty.png", b"", "image/png")} ) assert r.status_code == 400