Fix Sonarr season-pack imports after container updates #9
1 changed files with 77 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ class FakeSonarr {
|
||||||
calls.push({type: 'fetch', endpoint, query});
|
calls.push({type: 'fetch', endpoint, query});
|
||||||
if (endpoint === 'queue') return scenario.queueResponse || {records: []};
|
if (endpoint === 'queue') return scenario.queueResponse || {records: []};
|
||||||
if (endpoint === 'history') return scenario.historyResponse || {records: []};
|
if (endpoint === 'history') return scenario.historyResponse || {records: []};
|
||||||
|
if (endpoint === 'episode') return scenario.episodeResponse || [];
|
||||||
if (endpoint === 'parse') return scenario.parseResponse || {};
|
if (endpoint === 'parse') return scenario.parseResponse || {};
|
||||||
if (endpoint === 'manualimport') return scenario.candidates || [];
|
if (endpoint === 'manualimport') return scenario.candidates || [];
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -77,6 +78,82 @@ def run_script(scenario):
|
||||||
|
|
||||||
|
|
||||||
class SonarrImportSafetyTests(unittest.TestCase):
|
class SonarrImportSafetyTests(unittest.TestCase):
|
||||||
|
def test_pack_with_ambiguous_queue_resolves_exact_episode_from_filename(self):
|
||||||
|
pack = "Lucky.S01.Complete.2026.GERMAN.aac.720p.WEB.h265-FritzBox"
|
||||||
|
episode = "Lucky.S01E05.German.Title.2026.GERMAN.aac.720p.WEB.h265-FritzBox"
|
||||||
|
exact = f"/tdarr/converted/serien/{pack}/{episode}.mp4"
|
||||||
|
queue_records = [
|
||||||
|
{"title": pack, "seriesId": 794, "episodeId": 64000 + number}
|
||||||
|
for number in range(1, 8)
|
||||||
|
]
|
||||||
|
history_records = [
|
||||||
|
{
|
||||||
|
"sourceTitle": pack,
|
||||||
|
"seriesId": 794,
|
||||||
|
"episodeId": 64000 + number,
|
||||||
|
"eventType": "grabbed",
|
||||||
|
"quality": {"quality": {"id": 6, "name": "WEBDL-720p"}},
|
||||||
|
"languages": [{"id": 4, "name": "German"}],
|
||||||
|
"data": {"releaseGroup": "FritzBox", "releaseType": "SeasonPack"},
|
||||||
|
}
|
||||||
|
for number in range(1, 8)
|
||||||
|
]
|
||||||
|
result = run_script(
|
||||||
|
{
|
||||||
|
"releaseTitle": episode,
|
||||||
|
"exactPath": exact,
|
||||||
|
"scopeRoot": "/tdarr/converted/serien",
|
||||||
|
"queueResponse": {"records": queue_records},
|
||||||
|
"historyResponse": {"records": history_records},
|
||||||
|
"episodeResponse": [
|
||||||
|
{"id": 64000 + number, "seasonNumber": 1, "episodeNumber": number}
|
||||||
|
for number in range(1, 8)
|
||||||
|
],
|
||||||
|
"parseResponse": {},
|
||||||
|
"candidates": [
|
||||||
|
{
|
||||||
|
"path": exact,
|
||||||
|
"quality": {"quality": {"id": 0, "name": "Unknown"}},
|
||||||
|
"languages": [{"id": 0, "name": "Unknown"}],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(result["result"], 1)
|
||||||
|
command = next(call for call in result["calls"] if call["type"] == "command")
|
||||||
|
imported = command["body"]["files"][0]
|
||||||
|
self.assertEqual(imported["seriesId"], 794)
|
||||||
|
self.assertEqual(imported["episodeIds"], [64005])
|
||||||
|
self.assertEqual(imported["releaseGroup"], "FritzBox")
|
||||||
|
|
||||||
|
def test_pack_resolution_fails_closed_when_series_ids_differ(self):
|
||||||
|
pack = "Lucky.S01.Complete.2026.GERMAN.aac.720p.WEB.h265-FritzBox"
|
||||||
|
episode = "Lucky.S01E05.German.Title.2026.GERMAN.aac.720p.WEB.h265-FritzBox"
|
||||||
|
exact = f"/tdarr/converted/serien/{pack}/{episode}.mp4"
|
||||||
|
result = run_script(
|
||||||
|
{
|
||||||
|
"releaseTitle": episode,
|
||||||
|
"exactPath": exact,
|
||||||
|
"scopeRoot": "/tdarr/converted/serien",
|
||||||
|
"queueResponse": {
|
||||||
|
"records": [
|
||||||
|
{"title": pack, "seriesId": 794, "episodeId": 64005},
|
||||||
|
{"title": pack, "seriesId": 999, "episodeId": 99005},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"historyResponse": {"records": []},
|
||||||
|
"episodeResponse": [
|
||||||
|
{"id": 64005, "seasonNumber": 1, "episodeNumber": 5}
|
||||||
|
],
|
||||||
|
"parseResponse": {},
|
||||||
|
"candidates": [],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(result["result"], -1)
|
||||||
|
self.assertFalse(any(call["type"] == "command" for call in result["calls"]))
|
||||||
|
|
||||||
def test_fhd_scope_does_not_match_uhd_sibling_prefix(self):
|
def test_fhd_scope_does_not_match_uhd_sibling_prefix(self):
|
||||||
exact = (
|
exact = (
|
||||||
"/tdarr/converted/serien4k/Marshals.2026.S01.GERMAN.DUBBED/"
|
"/tdarr/converted/serien4k/Marshals.2026.S01.GERMAN.DUBBED/"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue