0ddc9db611
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
import psycopg
|
|
import pytest
|
|
|
|
from tests.conftest import insert_discovery_suggestion, insert_watched_artist
|
|
|
|
|
|
def test_suggestion_round_trip(conn):
|
|
sid = insert_discovery_suggestion(
|
|
conn, kind="album", artist_mbid="a1", artist_name="Boygenius",
|
|
rg_mbid="rg1", album="the record", score=2.5, seed_count=2,
|
|
sources=["listenbrainz"], status="pending",
|
|
)
|
|
with conn.cursor() as cur:
|
|
cur.execute(
|
|
'SELECT kind::text, "artistName", "rgMbid", album, score, "seedCount", '
|
|
'sources, status::text FROM "DiscoverySuggestion" WHERE id = %s', (sid,))
|
|
assert cur.fetchone() == (
|
|
"album", "Boygenius", "rg1", "the record", 2.5, 2, ["listenbrainz"], "pending")
|
|
|
|
|
|
def test_dedupe_key_is_unique(conn):
|
|
insert_discovery_suggestion(conn, kind="artist", artist_mbid="dup", rg_mbid=None)
|
|
with pytest.raises(psycopg.errors.UniqueViolation):
|
|
insert_discovery_suggestion(conn, kind="artist", artist_mbid="dup", rg_mbid=None)
|
|
|
|
|
|
def test_watched_artist_has_last_discovered_column(conn):
|
|
insert_watched_artist(conn, mbid="a1", last_discovered_sql="now()")
|
|
with conn.cursor() as cur:
|
|
cur.execute('SELECT "lastDiscoveredAt" IS NOT NULL FROM "WatchedArtist" WHERE mbid = %s', ("a1",))
|
|
assert cur.fetchone()[0] is True
|