b4e0d680f1
Ruff lint surfaced 23 violations across three rules; all addressed: UP017 (Use datetime.UTC alias): Replaced 13 sites of datetime.now(timezone.utc) with datetime.now(UTC), also adjusted from-imports accordingly. UTC is a Python 3.11+ alias for timezone.utc that ruff's pyupgrade rules prefer. UP042 (StrEnum): Replaced `class TagKind(str, Enum)` and `class SkipReason(str, Enum)` with `class Foo(StrEnum)`. StrEnum was added in Python 3.11 stdlib and is the modern idiom. Behavior is equivalent for our usage (the .value attribute, str(member) semantics). I001 (Import sorting): Added `known-first-party = ["backend"]` to ruff.toml's [lint.isort] so ruff groups `backend.*` imports correctly. Without it, ruff treated them as third-party and demanded a different grouping. The existing import order is stdlib → third-party → first-party → local relative, which ruff now accepts. 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 UTC, datetime, timedelta
|
|
|
|
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(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
|