def967a1a8
Removed the app/client fixtures duplicated across 36 test files (two variants: separate app + client(app), and a self-contained client() that called create_app inline) and the now-unused create_app imports. Both fixtures now live once in conftest.py. test_suggestions_bulk keeps its import (builds the app inline in two tests); test_health drops its local client + unused pytest_asyncio. Net -415 lines. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
from datetime import UTC, datetime, timedelta
|
|
|
|
import pytest
|
|
|
|
from backend.app.models import ImageRecord
|
|
|
|
pytestmark = pytest.mark.integration
|
|
|
|
|
|
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
|