2e8d7c960c
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
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
|
|
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, external_post_id="p1"))
|
|
db.add(Post(source_id=s.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
|