Files
alembic/tests/test_ndjson.py
andrew bcd07750bf R7: consolidate duplicated Spotify-token and NDJSON-parse logic
- The client-credentials token fetch was copy-pasted across spotify-retag.py,
  spotify-genre.py, and fix-track-metadata.py (and the app's spotify_client).
  Add pipeline/lib/_spotify_auth.get_token (cached per id/secret); the three
  scripts now source their own credentials but delegate the request to it. The
  scripts run with pipeline/lib on sys.path, so the plain `from _spotify_auth
  import get_token` resolves.
- The identical _parse_json_lines helper in dedup_review_service and
  genre_review_service is now a single app/services/_ndjson.parse_json_lines.

Verified: unit test of the token helper (cache + request), the NDJSON parser
(tests/test_ndjson.py), full suite green (40), and a live spotify-genre dry-run
that fetched a token and queried Spotify through the shared helper.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 16:08:15 -06:00

18 lines
409 B
Python

from app.services._ndjson import parse_json_lines
def test_parses_only_json_object_lines():
output = "\n".join([
"[info] starting",
'{"a": 1}',
"not json",
' {"b": 2} ',
'{"bad": ', # truncated -> skipped
"[info] done",
])
assert parse_json_lines(output) == [{"a": 1}, {"b": 2}]
def test_empty_output():
assert parse_json_lines("") == []