Notify completed downloads and finish watchlist entries
This commit is contained in:
+44
-4
@@ -350,6 +350,45 @@ class DownloadQueueWorkerFailureTests(unittest.TestCase):
|
||||
self.assertIsNone(queue.current_job)
|
||||
self.assertFalse(staging_dir.exists())
|
||||
|
||||
def test_successful_download_sends_completion_notification(self):
|
||||
queue = APP.DownloadQueue(
|
||||
lambda: {
|
||||
"mode": "sub",
|
||||
"quality": "best",
|
||||
"download_dir": "/tmp/example",
|
||||
"discord_webhook_url": "https://discord.example/webhook",
|
||||
"discord_webhook_events": ["download_completed"],
|
||||
},
|
||||
watchlist_sync_fn=lambda _job: {
|
||||
"show_id": "show-55",
|
||||
"title": "Queue Show",
|
||||
"category": "finished",
|
||||
"thumbnail_path": None,
|
||||
},
|
||||
start_worker=False,
|
||||
)
|
||||
job = queue.add({"query": "Queue Show", "title": "Queue Show", "season": "1", "episodes": "1-2"})
|
||||
|
||||
class FakeProc:
|
||||
pid = 4321
|
||||
stdout = []
|
||||
|
||||
def wait(self):
|
||||
return 0
|
||||
|
||||
with mock.patch.object(queue_jobs.subprocess, "Popen", return_value=FakeProc()), mock.patch.object(
|
||||
queue_jobs, "finalize_library_files", return_value=["/tmp/example/Queue Show - S01E01.mp4"]
|
||||
), mock.patch.object(queue_jobs, "send_discord_webhook_event") as send_webhook:
|
||||
queue._run_job(job)
|
||||
|
||||
stored = queue._find(job["id"])
|
||||
self.assertEqual(stored["status"], "done")
|
||||
self.assertIn("Download completed.", stored["log"])
|
||||
send_webhook.assert_called_once()
|
||||
self.assertEqual(send_webhook.call_args.args[1], "download_completed")
|
||||
self.assertEqual(send_webhook.call_args.args[2]["title"], "Queue Show")
|
||||
self.assertEqual(send_webhook.call_args.args[2]["category"], "finished")
|
||||
|
||||
|
||||
class WatchlistRefreshAllTests(unittest.TestCase):
|
||||
def test_refresh_all_iterates_every_show_id(self):
|
||||
@@ -810,7 +849,7 @@ class WatchlistCompletionTests(unittest.TestCase):
|
||||
self.assertEqual(item["status"], "queued")
|
||||
self.assertEqual(item["status_message"], "Queued from test.")
|
||||
|
||||
def test_mark_downloaded_keeps_existing_category_and_sets_download_flag(self):
|
||||
def test_mark_downloaded_moves_existing_category_to_finished_and_sets_download_flag(self):
|
||||
self.seed_watchlist_item(show_id="show-9", title="Queue Show", category="planned", downloaded=False)
|
||||
|
||||
with mock.patch.object(APP.WATCHLIST, "schedule_refresh", side_effect=lambda show_id: APP.WATCHLIST.get(show_id)), mock.patch.object(
|
||||
@@ -818,9 +857,9 @@ class WatchlistCompletionTests(unittest.TestCase):
|
||||
):
|
||||
item = APP.WATCHLIST.mark_downloaded("show-9", title="Queue Show")
|
||||
|
||||
self.assertEqual(item["category"], "planned")
|
||||
self.assertEqual(item["category"], "finished")
|
||||
self.assertTrue(item["downloaded"])
|
||||
self.assertEqual(item["finished_badge"], "")
|
||||
self.assertEqual(item["finished_badge"], "downloaded")
|
||||
self.assertEqual(item["status"], "queued")
|
||||
|
||||
def test_mark_downloaded_creates_missing_show_in_finished_category(self):
|
||||
@@ -843,8 +882,9 @@ class WatchlistCompletionTests(unittest.TestCase):
|
||||
item = APP.WATCHLIST.mark_downloaded("resolved-show-9", title="Queue Show")
|
||||
|
||||
self.assertEqual(item["show_id"], "resolved-show-9")
|
||||
self.assertEqual(item["category"], "watching")
|
||||
self.assertEqual(item["category"], "finished")
|
||||
self.assertTrue(item["downloaded"])
|
||||
self.assertEqual(item["finished_badge"], "downloaded")
|
||||
self.assertEqual(item["status"], "queued")
|
||||
self.assertFalse(APP.WATCHLIST.has_show("legacy-show-9"))
|
||||
self.assertEqual(APP.WATCHLIST.all_show_ids(), ["resolved-show-9"])
|
||||
|
||||
Reference in New Issue
Block a user