Files
FabledCurator/tests/test_api_artists_create.py
T
bvandeusen def967a1a8 refactor(dry-S1): hoist app/client test fixtures into conftest
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>
2026-05-28 11:33:05 -04:00

51 lines
1.6 KiB
Python

import pytest
pytestmark = pytest.mark.integration
@pytest.mark.asyncio
async def test_create_artist_returns_201(client):
resp = await client.post("/api/artists", json={"name": "Alice"})
assert resp.status_code == 201
body = await resp.get_json()
assert body["name"] == "Alice"
assert body["slug"] == "alice"
assert body["created"] is True
@pytest.mark.asyncio
async def test_create_artist_idempotent(client):
a = await client.post("/api/artists", json={"name": "Bob"})
b = await client.post("/api/artists", json={"name": "Bob"})
assert (await a.get_json())["created"] is True
body_b = await b.get_json()
assert body_b["created"] is False
assert body_b["id"] == (await a.get_json())["id"]
@pytest.mark.asyncio
async def test_create_artist_rejects_empty(client):
resp = await client.post("/api/artists", json={"name": " "})
assert resp.status_code == 400
@pytest.mark.asyncio
async def test_autocomplete_returns_matches(client):
await client.post("/api/artists", json={"name": "Alice"})
await client.post("/api/artists", json={"name": "Alice Cooper"})
await client.post("/api/artists", json={"name": "Bob"})
resp = await client.get("/api/artists/autocomplete?q=alic")
assert resp.status_code == 200
names = [a["name"] for a in await resp.get_json()]
assert "Alice" in names
assert "Alice Cooper" in names
assert "Bob" not in names
@pytest.mark.asyncio
async def test_autocomplete_empty_query(client):
resp = await client.get("/api/artists/autocomplete?q=")
assert resp.status_code == 200
assert await resp.get_json() == []