Add live request pipeline recheck
Magent CI/CD / verify (push) Successful in 11m6s
Magent CI/CD / deploy-prod (push) Skipped
Magent CI/CD / deploy-beta (push) Successful in 1m56s

This commit is contained in:
2026-08-30 19:50:09 +12:00
parent 2cbd9fe73f
commit 02245d365e
5 changed files with 257 additions and 18 deletions
+90
View File
@@ -310,6 +310,96 @@ class RequestPresentationTests(unittest.TestCase):
self.assertEqual(download_stage["state"], "attention")
self.assertTrue(download_stage["visible"])
def test_collector_file_waits_for_media_server_before_marking_available(self) -> None:
snapshot = Snapshot(
request_id="3914",
title="I See You",
request_type=RequestType.movie,
state=NormalizedState.importing,
actions=[],
)
presentation = _build_presentation(
snapshot,
approved=True,
arr_state="available",
arr_details={
"availability": {"available": 1, "missing": 0, "total": 1, "seasons": []}
},
prowlarr_state="ok",
download={
"visible": False,
"state": "not_started",
"summary": "No download attempt has been observed.",
"torrents": [],
},
jellyfin_found=False,
jellyfin_link=None,
)
self.assertEqual(presentation["status"]["label"], "Collected — waiting for the media server")
self.assertEqual(presentation["nextStep"]["title"], "Wait for the media server to index this title")
search_stage = next(stage for stage in presentation["pipeline"] if stage["id"] == "search")
download_stage = next(stage for stage in presentation["pipeline"] if stage["id"] == "download")
available_stage = next(stage for stage in presentation["pipeline"] if stage["id"] == "available")
self.assertEqual(search_stage["state"], "complete")
self.assertEqual(download_stage["state"], "complete")
self.assertEqual(available_stage["state"], "active")
class RequestRecheckTests(unittest.IsolatedAsyncioTestCase):
async def test_recheck_refreshes_seerr_cache_and_returns_rebuilt_snapshot(self) -> None:
runtime = SimpleNamespace(
jellyseerr_base_url="http://seerr.test",
jellyseerr_api_key="seerr-key",
)
fresh_request = {
"id": 3914,
"type": "movie",
"status": 2,
"createdAt": "2026-08-30T00:00:00Z",
"updatedAt": "2026-08-30T01:00:00Z",
"requestedBy": {"username": "viewer"},
"media": {
"id": 9001,
"mediaType": "movie",
"tmdbId": 524251,
"title": "I See You",
"year": 2019,
},
}
seerr = SimpleNamespace(
configured=lambda: True,
get_request=AsyncMock(return_value=fresh_request),
)
snapshot = Snapshot(
request_id="3914",
title="I See You",
request_type=RequestType.movie,
state=NormalizedState.importing,
presentation={
"status": {"label": "Collected — waiting for the media server"},
},
)
with patch.object(requests_router, "get_runtime_settings", return_value=runtime), patch.object(
requests_router, "JellyseerrClient", return_value=seerr
), patch.object(requests_router, "upsert_request_cache") as upsert, patch.object(
requests_router, "_cache_set"
) as cache_set, patch.object(requests_router, "_refresh_recent_cache_from_db"), patch.object(
requests_router, "build_snapshot", new=AsyncMock(return_value=snapshot)
), patch.object(requests_router, "save_action") as save_action:
result = await requests_router.action_recheck(
"3914", user={"username": "viewer", "role": "user"}
)
seerr.get_request.assert_awaited_once_with("3914")
upsert.assert_called_once()
cache_set.assert_called_once_with("request:3914", fresh_request)
save_action.assert_called_once()
self.assertEqual(result["status"], "ok")
self.assertIs(result["snapshot"], snapshot)
class LiveDownloadProgressTests(unittest.IsolatedAsyncioTestCase):
async def test_live_download_progress_uses_saved_hash_and_current_qbittorrent_value(self) -> None: