Files
reactbin/api/tests/integration/test_serving.py
agatha 8bf6ef443a [Spec Kit] Implementation progress
Implements all 88 tasks for the Reaction Image Board (specs/001-reaction-image-board):

- docker-compose.yml: postgres, minio, minio-init, api, ui services with healthchecks
- api/: FastAPI app with SQLAlchemy 2.x async, Alembic migrations, S3/MinIO storage,
  full integration + unit test suite (pytest + pytest-asyncio)
- ui/: Angular 19 standalone app (Library, Upload, Detail, NotFound components)
- .env.example: all required environment variables
- .gitignore: Python, Node, Docker, IDE, .env patterns

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 16:13:23 +00:00

42 lines
1.2 KiB
Python

"""
T055 — GET /api/v1/images/{id}/file → 302 with Location header
T056 — /file for unknown ID → 404 image_not_found
"""
import io
import uuid
import pytest
def _minimal_webp() -> bytes:
# Minimal VP8L WebP
return (
b"RIFF$\x00\x00\x00WEBPVP8L\x18\x00\x00\x00"
b"/\x00\x00\x00\x00\x18\xf0\x1f\xfe\xff\x02\xfe\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
)
@pytest.mark.asyncio
async def test_file_redirect_returns_302(client):
data = _minimal_webp()
upload = await client.post(
"/api/v1/images",
files={"file": ("img.webp", io.BytesIO(data), "image/webp")},
)
assert upload.status_code in (200, 201)
image_id = upload.json()["id"]
# Don't follow redirects
response = await client.get(f"/api/v1/images/{image_id}/file", follow_redirects=False)
assert response.status_code == 302
assert "Location" in response.headers
assert response.headers["Location"] # must not be empty
@pytest.mark.asyncio
async def test_file_unknown_id_returns_404(client):
response = await client.get(f"/api/v1/images/{uuid.uuid4()}/file")
assert response.status_code == 404
body = response.json()
assert body["code"] == "image_not_found"