import pytest from backend.app.models import Artist pytestmark = pytest.mark.integration @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 assert body["post_count"] == 0 @pytest.mark.asyncio async def test_artist_overview_post_count(client, db): from backend.app.models import Post, Source a = Artist(name="Lyra", slug="lyra") db.add(a) await db.flush() s = Source( artist_id=a.id, platform="patreon", url="https://patreon.com/cw/lyra", enabled=True, ) db.add(s) await db.flush() db.add(Post(source_id=s.id, artist_id=a.id, external_post_id="p1")) db.add(Post(source_id=s.id, artist_id=a.id, external_post_id="p2")) await db.flush() await db.commit() resp = await client.get("/api/artist/lyra") assert resp.status_code == 200 body = await resp.get_json() assert body["post_count"] == 2 @pytest.mark.asyncio async def test_artist_images_404(client): resp = await client.get("/api/artist/nope/images") assert resp.status_code == 404