test: genuinely exercise discovery ON CONFLICT dedup + config defaults
This commit is contained in:
@@ -46,3 +46,38 @@ def test_config_from_config_parses_strings():
|
||||
cfg = MonitorConfig.from_config({"monitor.enabled": "true", "monitor.qualityCutoff": "3"})
|
||||
assert cfg.enabled is True and cfg.quality_cutoff == 3
|
||||
assert MonitorConfig.from_config({}).enabled is False
|
||||
|
||||
|
||||
def test_discover_dedupes_shared_release_group_in_one_pass(conn):
|
||||
# Two watched artists whose discographies share a release-group (a collaboration):
|
||||
# the second insert must hit ON CONFLICT ("rgMbid") DO NOTHING within a single pass.
|
||||
insert_watched_artist(conn, mbid="a1", name="Artist One", auto_monitor_future=True)
|
||||
insert_watched_artist(conn, mbid="a2", name="Artist Two", auto_monitor_future=True)
|
||||
shared = ReleaseGroupInfo("rg-shared", "Split", "Album", (), "2999-01-01")
|
||||
browser = FakeMbBrowser(releases={"a1": [shared], "a2": [shared]})
|
||||
assert discover(conn, browser, MonitorConfig(enabled=True)) == 1 # deduped
|
||||
with conn.cursor() as cur:
|
||||
cur.execute('SELECT count(*) FROM "MonitoredRelease" WHERE "rgMbid" = %s', ("rg-shared",))
|
||||
assert cur.fetchone()[0] == 1
|
||||
|
||||
|
||||
def test_discover_repolls_after_interval_and_dedupes(conn):
|
||||
# Aged lastPolledAt (48h > 24h default) makes the artist due; re-browsing the same
|
||||
# releases inserts nothing new, proving both the due-branch and ON CONFLICT dedup.
|
||||
insert_watched_artist(conn, mbid="a1", name="X", auto_monitor_future=True,
|
||||
last_polled_sql="now() - interval '48 hours'")
|
||||
browser = FakeMbBrowser(releases={"a1": _releases()})
|
||||
assert discover(conn, browser, MonitorConfig(enabled=True)) == 2 # due: inserts both
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("UPDATE \"WatchedArtist\" SET \"lastPolledAt\" = now() - interval '48 hours' WHERE mbid = %s", ("a1",))
|
||||
conn.commit()
|
||||
assert discover(conn, browser, MonitorConfig(enabled=True)) == 0 # due again, all rgMbids conflict
|
||||
|
||||
|
||||
def test_config_defaults_and_truthy_variants():
|
||||
cfg = MonitorConfig.from_config({})
|
||||
assert (cfg.enabled, cfg.poll_interval_hours, cfg.retry_interval_hours,
|
||||
cfg.quality_cutoff, cfg.upgrade_window_days) == (False, 24, 6, 2, 14)
|
||||
for v in ("1", "yes", "on", "TRUE"):
|
||||
assert MonitorConfig.from_config({"monitor.enabled": v}).enabled is True
|
||||
assert MonitorConfig.from_config({"monitor.enabled": "nope"}).enabled is False
|
||||
|
||||
Reference in New Issue
Block a user