Add live download progress updates
This commit is contained in:
@@ -19,7 +19,7 @@ from backend.app.routers import site as site_router
|
||||
from backend.app.routers import status as status_router
|
||||
from backend.app.security import PASSWORD_POLICY_MESSAGE, validate_password_policy
|
||||
from backend.app.services import password_reset
|
||||
from backend.app.services.snapshot import _build_presentation, _episode_availability
|
||||
from backend.app.services.snapshot import _build_presentation, _episode_availability, _torrent_progress
|
||||
|
||||
|
||||
def _build_request(ip: str = "127.0.0.1", user_agent: str = "backend-test") -> Request:
|
||||
@@ -173,6 +173,9 @@ class RequestCacheTests(unittest.TestCase):
|
||||
|
||||
|
||||
class RequestPresentationTests(unittest.TestCase):
|
||||
def test_torrent_progress_keeps_tenths_for_live_updates(self) -> None:
|
||||
self.assertEqual(_torrent_progress({"progress": 0.1344}), 13.4)
|
||||
|
||||
def test_episode_availability_counts_only_aired_monitored_episodes(self) -> None:
|
||||
episodes = [
|
||||
{"seasonNumber": 1, "episodeNumber": 1, "monitored": True, "hasFile": True},
|
||||
@@ -226,6 +229,39 @@ class RequestPresentationTests(unittest.TestCase):
|
||||
self.assertEqual(download_stage["summary"], "No download attempt yet")
|
||||
|
||||
|
||||
class LiveDownloadProgressTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_live_download_progress_uses_saved_hash_and_current_qbittorrent_value(self) -> None:
|
||||
runtime = SimpleNamespace(
|
||||
jellyseerr_base_url=None,
|
||||
jellyseerr_api_key=None,
|
||||
qbittorrent_base_url="http://qbittorrent.test",
|
||||
qbittorrent_username="magent",
|
||||
qbittorrent_password="secret",
|
||||
)
|
||||
evidence = {
|
||||
"observed": True,
|
||||
"torrents": [{"hash": "abc123", "progress": 0.12}],
|
||||
}
|
||||
current = [{"hash": "abc123", "name": "Example", "progress": 0.1344, "state": "downloading"}]
|
||||
|
||||
with patch.object(requests_router, "get_runtime_settings", return_value=runtime), patch.object(
|
||||
requests_router,
|
||||
"get_request_download_evidence",
|
||||
return_value=evidence,
|
||||
), patch.object(
|
||||
requests_router.QBittorrentClient,
|
||||
"get_torrents_by_hashes",
|
||||
new=AsyncMock(return_value=current),
|
||||
) as get_torrents:
|
||||
result = await requests_router.get_download_progress(
|
||||
"3909", user={"username": "viewer", "role": "user"}
|
||||
)
|
||||
|
||||
get_torrents.assert_awaited_once_with("abc123")
|
||||
self.assertEqual(result["state"], "downloading")
|
||||
self.assertEqual(result["torrents"][0]["progressPercent"], 13.4)
|
||||
|
||||
|
||||
class DatabaseEmailTests(TempDatabaseMixin, unittest.TestCase):
|
||||
def test_set_user_email_is_case_insensitive(self) -> None:
|
||||
created = db.create_user_if_missing(
|
||||
|
||||
Reference in New Issue
Block a user