feat(artist): editable display name + rename surface; drop name-uniqueness (#130 step 1)
First step of decoupling artist identity/storage/display. migration 0077 drops uq_artist_name so the display name is free text (two genuinely different creators can share a name); the slug stays the immutable, unique storage/identity key (the on-disk path component — untouched, so nothing moves). ArtistService.rename + PATCH /api/artists/<id> change the name ONLY. Frontend: inline pencil-edit on the artist header (mirrors TagCard), slug/route unaffected so no navigation. Fixes the operator's 'no surface to rename an artist' + the name-collision fragility. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CDgx8bQS5YrGRK76v8HUnM
This commit is contained in:
@@ -47,3 +47,28 @@ 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() == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_patch_renames_display_name_only(client):
|
||||
# #130: PATCH renames the display name; slug unchanged (paths safe).
|
||||
created = await (await client.post("/api/artists", json={"name": "12345678"})).get_json()
|
||||
resp = await client.patch(
|
||||
f"/api/artists/{created['id']}", json={"name": "Kurotsuchi Machi"}
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
body = await resp.get_json()
|
||||
assert body["name"] == "Kurotsuchi Machi"
|
||||
assert body["slug"] == created["slug"] # slug frozen
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_patch_rename_validation(client):
|
||||
created = await (await client.post("/api/artists", json={"name": "Nn"})).get_json()
|
||||
assert (await client.patch(
|
||||
f"/api/artists/{created['id']}", json={"name": " "}
|
||||
)).status_code == 400
|
||||
assert (await client.patch(
|
||||
f"/api/artists/{created['id']}", json={})).status_code == 400
|
||||
assert (await client.patch(
|
||||
"/api/artists/999999", json={"name": "Ghost"})).status_code == 404
|
||||
|
||||
@@ -54,3 +54,40 @@ async def test_autocomplete_ranks_exact_prefix_substring(db):
|
||||
async def test_autocomplete_empty_query_returns_empty(db):
|
||||
svc = ArtistService(db)
|
||||
assert await svc.autocomplete("") == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rename_changes_name_not_slug(db):
|
||||
# #130: rename touches the display name ONLY — the slug (and every on-disk
|
||||
# path keyed off it) is immutable.
|
||||
svc = ArtistService(db)
|
||||
artist, _ = await svc.find_or_create("12345678")
|
||||
orig_slug = artist.slug
|
||||
renamed = await svc.rename(artist.id, "Kurotsuchi Machi")
|
||||
assert renamed.name == "Kurotsuchi Machi"
|
||||
assert renamed.slug == orig_slug # slug frozen
|
||||
fresh = await db.get(Artist, artist.id)
|
||||
assert fresh.name == "Kurotsuchi Machi"
|
||||
assert fresh.slug == orig_slug
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rename_rejects_empty_and_missing(db):
|
||||
svc = ArtistService(db)
|
||||
artist, _ = await svc.find_or_create("Someone")
|
||||
with pytest.raises(ValueError):
|
||||
await svc.rename(artist.id, " ")
|
||||
assert await svc.rename(999999, "Ghost") is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_two_artists_can_share_a_display_name(db):
|
||||
# #130: name is non-unique now (two genuinely different creators can share a
|
||||
# display name); the immutable slug keeps them distinct.
|
||||
a = Artist(name="Same Name", slug="same-name")
|
||||
b = Artist(name="Same Name", slug="same-name-2")
|
||||
db.add_all([a, b])
|
||||
await db.flush()
|
||||
assert a.id != b.id
|
||||
assert a.name == b.name
|
||||
assert a.slug != b.slug
|
||||
|
||||
Reference in New Issue
Block a user