fd8cf83003
Thin Quart blueprint that delegates to GalleryService. Cursor-based scroll returns images + a date_groups summary so the SPA can render year-month headers without re-grouping client-side. Timeline returns year-month buckets for the sidebar jump nav. Jump returns a cursor positioned at a specific year-month so the gallery can scroll to historical periods. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
from datetime import datetime, timedelta, timezone
|
|
|
|
import pytest
|
|
|
|
from backend.app import create_app
|
|
from backend.app.models import ImageRecord
|
|
|
|
|
|
@pytest.fixture
|
|
async def app():
|
|
return create_app()
|
|
|
|
|
|
@pytest.fixture
|
|
async def client(app):
|
|
async with app.test_client() as c:
|
|
yield c
|
|
|
|
|
|
async def _seed(db, count: int = 3):
|
|
base = datetime.now(timezone.utc)
|
|
for i in range(count):
|
|
r = ImageRecord(
|
|
path=f"/images/x/{i}.jpg",
|
|
sha256=f"x{i:063d}",
|
|
size_bytes=1, mime="image/jpeg", width=1, height=1,
|
|
origin="imported_filesystem", integrity_status="unknown",
|
|
)
|
|
r.created_at = base - timedelta(minutes=i)
|
|
db.add(r)
|
|
await db.flush()
|
|
await db.commit()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_scroll_returns_images(client, db):
|
|
await _seed(db)
|
|
resp = await client.get("/api/gallery/scroll?limit=10")
|
|
assert resp.status_code == 200
|
|
body = await resp.get_json()
|
|
assert len(body["images"]) == 3
|
|
assert "next_cursor" in body
|
|
assert "date_groups" in body
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_scroll_rejects_bad_limit(client):
|
|
resp = await client.get("/api/gallery/scroll?limit=notanumber")
|
|
assert resp.status_code == 400
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_timeline_endpoint(client, db):
|
|
await _seed(db)
|
|
resp = await client.get("/api/gallery/timeline")
|
|
assert resp.status_code == 200
|
|
body = await resp.get_json()
|
|
assert sum(b["count"] for b in body) == 3
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_jump_requires_year_month(client):
|
|
resp = await client.get("/api/gallery/jump")
|
|
assert resp.status_code == 400
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_image_detail_404_when_missing(client):
|
|
resp = await client.get("/api/gallery/image/99999")
|
|
assert resp.status_code == 404
|