Files
FabledCurator/tests/test_api_artists_directory.py
bvandeusen 3162cff96b
CI / lint (push) Successful in 2s
CI / frontend-build (push) Successful in 27s
CI / backend-lint-and-test (push) Successful in 27s
CI / intimp (push) Successful in 3m29s
CI / intapi (push) Successful in 7m20s
CI / intcore (push) Successful in 8m4s
fix(artist): ruff UP017 + test_directory_card_shape pin
Two CI bounces on b65e956:
1. ruff UP017 — Python 3.14's preferred form is `datetime.UTC`, not
   `timezone.utc`. Switch the test's two TZ literals.
2. test_directory_card_shape pinned the card key set to the pre-feature
   shape; `unseen_count` was added to the API payload but the pin
   wasn't updated. Same shape as the recurring 'plan-grep-pinned-tests'
   trap — should have grepped tests/ for card.keys() before pushing.
2026-06-03 15:45:59 -04:00

94 lines
3.0 KiB
Python

"""FC-3f: /api/artists/directory API tests."""
import pytest
from backend.app.models import Artist, ImageRecord, Source
pytestmark = pytest.mark.integration
@pytest.fixture
async def seeded(db):
alice = Artist(name="alice-api", slug="alice-api", is_subscription=True)
bob = Artist(name="bob-api", slug="bob-api", is_subscription=False)
db.add(alice)
db.add(bob)
await db.flush()
db.add(Source(
artist_id=alice.id, platform="patreon",
url="https://p/alice-api", enabled=True,
))
db.add(ImageRecord(
path="/images/api/alice.jpg",
sha256=("a" * 60) + "0001",
size_bytes=10, mime="image/jpeg", width=10, height=10,
origin="downloaded", artist_id=alice.id,
))
await db.commit()
return alice, bob
@pytest.mark.asyncio
async def test_directory_returns_cards_and_cursor_keys(client, seeded):
resp = await client.get("/api/artists/directory")
assert resp.status_code == 200
body = await resp.get_json()
assert set(body.keys()) == {"cards", "next_cursor"}
assert isinstance(body["cards"], list)
@pytest.mark.asyncio
async def test_directory_card_shape(client, seeded):
resp = await client.get("/api/artists/directory?q=alice-api")
body = await resp.get_json()
card = next(c for c in body["cards"] if c["name"] == "alice-api")
assert set(card.keys()) == {
"id", "name", "slug", "is_subscription", "image_count",
"unseen_count", "preview_thumbnails",
}
assert card["is_subscription"] is True
assert card["image_count"] == 1
assert len(card["preview_thumbnails"]) == 1
@pytest.mark.asyncio
async def test_directory_rejects_malformed_cursor(client):
resp = await client.get("/api/artists/directory?cursor=garbage!!!")
assert resp.status_code == 400
body = await resp.get_json()
assert body["error"] == "invalid_cursor"
@pytest.mark.asyncio
async def test_directory_rejects_unknown_platform(client):
resp = await client.get("/api/artists/directory?platform=myspace")
assert resp.status_code == 400
body = await resp.get_json()
assert body["error"] == "unknown_platform"
@pytest.mark.asyncio
async def test_directory_rejects_limit_out_of_range(client):
resp = await client.get("/api/artists/directory?limit=0")
assert resp.status_code == 400
resp = await client.get("/api/artists/directory?limit=500")
assert resp.status_code == 400
@pytest.mark.asyncio
async def test_directory_q_propagates(client, seeded):
resp = await client.get("/api/artists/directory?q=alice-api")
body = await resp.get_json()
names = [c["name"] for c in body["cards"]]
assert "alice-api" in names
assert "bob-api" not in names
@pytest.mark.asyncio
async def test_directory_platform_propagates(client, seeded):
resp = await client.get("/api/artists/directory?platform=patreon")
body = await resp.get_json()
names = [c["name"] for c in body["cards"]]
assert "alice-api" in names
assert "bob-api" not in names # no patreon source