feat(fc2c-i): artist overview + paged images endpoints

This commit is contained in:
2026-05-15 15:52:02 -04:00
parent 8484cb9aaa
commit e43c2a0dd0
5 changed files with 352 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import pytest
from backend.app import create_app
from backend.app.models import Artist
pytestmark = pytest.mark.integration
@pytest.fixture
async def client():
app = create_app()
async with app.test_client() as c:
yield c
@pytest.mark.asyncio
async def test_artist_404(client):
resp = await client.get("/api/artist/nope")
assert resp.status_code == 404
@pytest.mark.asyncio
async def test_artist_overview_ok(client, db):
db.add(Artist(name="Mira", slug="mira"))
await db.flush()
await db.commit()
resp = await client.get("/api/artist/mira")
assert resp.status_code == 200
body = await resp.get_json()
assert body["name"] == "Mira"
assert body["image_count"] == 0
@pytest.mark.asyncio
async def test_artist_images_404(client):
resp = await client.get("/api/artist/nope/images")
assert resp.status_code == 404
+78
View File
@@ -0,0 +1,78 @@
from datetime import UTC, datetime
import pytest
from backend.app.models import (
Artist, ImageProvenance, ImageRecord, Post, Source, Tag, TagKind,
)
from backend.app.models.tag import image_tag
from backend.app.services.artist_service import ArtistService
pytestmark = pytest.mark.integration
async def _fixture(db):
artist = Artist(name="Nadia", slug="nadia")
db.add(artist)
await db.flush()
src = Source(artist_id=artist.id, platform="web", url="http://x")
db.add(src)
await db.flush()
post = Post(
source_id=src.id, external_post_id="p1",
post_date=datetime(2026, 3, 1, tzinfo=UTC),
)
db.add(post)
await db.flush()
img = ImageRecord(
path="/images/a/1.jpg", sha256="a" + "0" * 63,
size_bytes=1, mime="image/jpeg", width=4, height=8,
origin="downloaded", integrity_status="unknown",
)
db.add(img)
await db.flush()
db.add(ImageProvenance(
image_record_id=img.id, post_id=post.id, source_id=src.id))
tag = Tag(name="forest", kind=TagKind.general)
db.add(tag)
await db.flush()
await db.execute(image_tag.insert().values(
image_record_id=img.id, tag_id=tag.id, source="manual"))
await db.flush()
return artist, src, img
@pytest.mark.asyncio
async def test_overview_aggregates(db):
artist, src, img = await _fixture(db)
svc = ArtistService(db)
ov = await svc.overview("nadia")
assert ov["name"] == "Nadia"
assert ov["image_count"] == 1
assert ov["date_range"]["min"].startswith("2026-03-01")
assert ov["date_range"]["max"].startswith("2026-03-01")
assert any(t["name"] == "forest" for t in ov["cooccurring_tags"])
assert ov["sources"][0]["image_count"] == 1
assert ov["activity"][0]["count"] == 1
@pytest.mark.asyncio
async def test_overview_unknown_slug_returns_none(db):
svc = ArtistService(db)
assert await svc.overview("ghost") is None
@pytest.mark.asyncio
async def test_paged_images(db):
artist, src, img = await _fixture(db)
svc = ArtistService(db)
page = await svc.images("nadia", cursor=None, limit=10)
assert page is not None
assert len(page.images) == 1
assert page.images[0]["thumbnail_url"].startswith("/images/thumbs/")
@pytest.mark.asyncio
async def test_paged_images_unknown_slug_none(db):
svc = ArtistService(db)
assert await svc.images("ghost", cursor=None, limit=10) is None