Redesign the request portal flow
Magent CI/CD / verify (push) Canceled after 5m59s
Magent CI/CD / deploy-prod (push) Canceled after 0s
Magent CI/CD / deploy-beta (push) Canceled after 0s

This commit is contained in:
2026-08-31 14:53:15 +12:00
parent 963506d098
commit 9dfea25d56
6 changed files with 1084 additions and 11 deletions
+115
View File
@@ -387,6 +387,121 @@ class RequestPresentationTests(unittest.TestCase):
self.assertEqual(available_stage["state"], "active")
class RequestCreationFlowTests(unittest.IsolatedAsyncioTestCase):
async def test_seerr_search_percent_encodes_multi_word_titles(self) -> None:
client = requests_router.JellyseerrClient("http://seerr.test", "key")
client.get = AsyncMock(return_value={"results": []})
await client.search("Ricky Gervais Alley Cats", page=2)
client.get.assert_awaited_once_with(
"/api/v1/search?query=Ricky%20Gervais%20Alley%20Cats&page=2"
)
async def test_seerr_request_includes_validated_destination_and_profile(self) -> None:
client = requests_router.JellyseerrClient("http://seerr.test", "key")
client.post = AsyncMock(return_value={"id": 42})
await client.create_request(
media_type="tv",
media_id=123,
seasons=[1, 2],
server_id=0,
profile_id=7,
root_folder="/TV98",
)
client.post.assert_awaited_once_with(
"/api/v1/request",
payload={
"mediaType": "tv",
"mediaId": 123,
"seasons": [1, 2],
"serverId": 0,
"profileId": 7,
"rootFolder": "/TV98",
},
)
async def test_request_destination_only_offers_live_sonarr_profiles(self) -> None:
runtime = SimpleNamespace(
sonarr_base_url="http://sonarr.test",
sonarr_api_key="key",
sonarr_quality_profile_id=7,
sonarr_root_folder="/tv",
)
seerr = SimpleNamespace(
get_service_settings=AsyncMock(
return_value=[
{
"id": 4,
"name": "Main Sonarr",
"isDefault": True,
"is4k": False,
"activeProfileId": 7,
"activeDirectory": "/tv",
}
]
)
)
sonarr = SimpleNamespace(
configured=lambda: True,
get_quality_profiles=AsyncMock(
return_value=[{"id": 7, "name": "WEB-1080p"}, {"id": 10, "name": "Optimal"}]
),
get_root_folders=AsyncMock(return_value=[{"id": 1, "path": "/tv"}]),
)
with patch.object(requests_router, "SonarrClient", return_value=sonarr):
destination = await requests_router._resolve_request_destination(
runtime, seerr, "tv", requested_profile_id=10
)
self.assertEqual(destination["profile_id"], 10)
self.assertEqual(destination["default_profile_id"], 7)
self.assertEqual(destination["root_folder"], "/tv")
self.assertEqual(destination["profiles"], [
{"id": 7, "name": "WEB-1080p"},
{"id": 10, "name": "Optimal"},
])
async def test_request_destination_rejects_stale_profile_id(self) -> None:
runtime = SimpleNamespace(
radarr_base_url="http://radarr.test",
radarr_api_key="key",
radarr_quality_profile_id=6,
radarr_root_folder="/movies",
)
seerr = SimpleNamespace(
get_service_settings=AsyncMock(
return_value=[
{
"id": 2,
"name": "Main Radarr",
"isDefault": True,
"is4k": False,
"activeProfileId": 6,
"activeDirectory": "/movies",
}
]
)
)
radarr = SimpleNamespace(
configured=lambda: True,
get_quality_profiles=AsyncMock(return_value=[{"id": 6, "name": "HD"}]),
get_root_folders=AsyncMock(return_value=[{"id": 1, "path": "/movies"}]),
)
with patch.object(requests_router, "RadarrClient", return_value=radarr):
with self.assertRaises(HTTPException) as context:
await requests_router._resolve_request_destination(
runtime, seerr, "movie", requested_profile_id=999
)
self.assertEqual(context.exception.status_code, 400)
self.assertIn("not available in Radarr", context.exception.detail)
class RequestRecheckTests(unittest.IsolatedAsyncioTestCase):
async def test_recheck_refreshes_seerr_cache_and_returns_rebuilt_snapshot(self) -> None:
runtime = SimpleNamespace(