soulsync/tests/test_artist_db_record_endpoint.py
BoulderBadgeDad 123eb6139f Artist detail: "DB Record" inspector — everything the DB knows about an artist
A small glowing button at the bottom-right of the artist hero (library artists
only) opens a programmer-style modal showing the COMPLETE artists DB row — every
source id + match status, cached bios / tags / similar / urls, soul_id, timestamps,
the lot (62 columns) — plus owned album/track counts.

- Backend: GET /api/artist/<id>/record returns the full row with JSON-text columns
  (genres, aliases, lastfm_tags/similar, discogs_urls, …) decoded into real
  arrays/objects, + album/track counts. 404 for non-library artists.
- Frontend: editor-themed modal (Tokyo-night tokens) with a Fields tab (copyable,
  filterable key/value rows) and a syntax-highlighted JSON tab. Copy-all-as-JSON,
  per-value copy (HTTP/Docker clipboard fallback), and Save .json. Esc / click-out
  to close. Helpers namespaced (_arecEsc) so they can't clobber the shared globals.

Tests: endpoint returns the full row with decoded JSON + counts; 404 for a missing
artist. 64 script-split integrity tests still green; ruff clean.
2026-06-11 16:57:48 -07:00

59 lines
1.8 KiB
Python

"""GET /api/artist/<id>/record — the artist-detail "DB Record" inspector source.
Returns the full artists row (JSON text columns decoded) + owned counts, 404 if
the artist isn't in the library."""
from __future__ import annotations
import os
import sqlite3
import tempfile
import pytest
_TMP = tempfile.mkdtemp(prefix='soulsync-testdb-arec-')
os.environ['DATABASE_PATH'] = os.path.join(_TMP, 'a.db')
os.environ['SOULSYNC_TEST_DB_READY'] = '1'
web_server = pytest.importorskip('web_server')
@pytest.fixture
def client():
return web_server.app.test_client()
def _insert_artist():
db = web_server.get_database()
conn = db._get_connection()
try:
conn.execute(
"INSERT OR REPLACE INTO artists (id, name, genres, musicbrainz_id, "
"musicbrainz_match_status, lastfm_listeners) VALUES (?,?,?,?,?,?)",
('99001', 'Test Artist', '["rock", "metal"]',
'mbid-123', 'matched', 4242),
)
conn.commit()
finally:
conn.close()
def test_record_returns_full_row_with_decoded_json(client):
_insert_artist()
r = client.get('/api/artist/99001/record')
assert r.status_code == 200
body = r.get_json()
assert body['success'] is True
rec = body['record']
assert rec['name'] == 'Test Artist'
assert rec['genres'] == ['rock', 'metal'] # JSON text decoded to a list
assert rec['musicbrainz_id'] == 'mbid-123'
assert rec['musicbrainz_match_status'] == 'matched'
assert rec['lastfm_listeners'] == 4242
assert 'counts' in body and 'albums' in body['counts'] and 'tracks' in body['counts']
assert body['artist_id'] == '99001'
def test_missing_artist_is_404(client):
r = client.get('/api/artist/does-not-exist-77777/record')
assert r.status_code == 404
assert r.get_json()['success'] is False