Limit bulk refresh to watching and planned
This commit is contained in:
+57
-13
@@ -498,17 +498,61 @@ class DownloadQueueWorkerFailureTests(unittest.TestCase):
|
||||
|
||||
|
||||
class WatchlistRefreshAllTests(unittest.TestCase):
|
||||
def test_refresh_all_iterates_every_show_id(self):
|
||||
def test_refresh_all_iterates_only_watching_and_planned_show_ids(self):
|
||||
store = object.__new__(APP.WatchlistStore)
|
||||
calls = []
|
||||
store.all_show_ids = lambda: ["show-a", "show-b", "show-c"]
|
||||
store.all_show_ids = lambda categories=None: ["show-a", "show-b"]
|
||||
store.refresh = lambda show_id, include_thumbnail=True: calls.append((show_id, include_thumbnail)) or {"show_id": show_id}
|
||||
|
||||
result = APP.WatchlistStore.refresh_all(store)
|
||||
|
||||
self.assertEqual(calls, [("show-a", False), ("show-b", False), ("show-c", False)])
|
||||
self.assertEqual(result["count"], 3)
|
||||
self.assertEqual([item["show_id"] for item in result["items"]], ["show-a", "show-b", "show-c"])
|
||||
self.assertEqual(calls, [("show-a", False), ("show-b", False)])
|
||||
self.assertEqual(result["count"], 2)
|
||||
self.assertEqual([item["show_id"] for item in result["items"]], ["show-a", "show-b"])
|
||||
|
||||
def test_all_show_ids_can_filter_by_category(self):
|
||||
with APP.WATCHLIST._connect() as conn:
|
||||
conn.execute("DELETE FROM watchlist")
|
||||
now = APP.now_iso()
|
||||
items = [
|
||||
{"show_id": "show-w", "title": "Watching", "category": "watching"},
|
||||
{"show_id": "show-p", "title": "Planned", "category": "planned"},
|
||||
{"show_id": "show-f", "title": "Finished", "category": "finished"},
|
||||
{"show_id": "show-d", "title": "Dropped", "category": "dropped"},
|
||||
]
|
||||
with APP.WATCHLIST.lock, APP.WATCHLIST._connect() as conn:
|
||||
for item in items:
|
||||
APP.WATCHLIST._upsert_conn(
|
||||
conn,
|
||||
{
|
||||
**APP.WATCHLIST._auto_download_defaults(item["title"]),
|
||||
"show_id": item["show_id"],
|
||||
"title": item["title"],
|
||||
"category": item["category"],
|
||||
"downloaded": False,
|
||||
"status": "tracked",
|
||||
"status_message": "seeded",
|
||||
"created_at": now,
|
||||
"updated_at": now,
|
||||
"last_checked": None,
|
||||
"sub_count": 0,
|
||||
"dub_count": 0,
|
||||
"expected_count": 0,
|
||||
"airing_status": None,
|
||||
"sub_latest_episode": None,
|
||||
"dub_latest_episode": None,
|
||||
"animeschedule_route": None,
|
||||
"animeschedule_title": None,
|
||||
"anidb_aid": None,
|
||||
"anidb_title": None,
|
||||
"thumbnail_path": None,
|
||||
"thumbnail_checked_at": None,
|
||||
},
|
||||
)
|
||||
|
||||
filtered = APP.WATCHLIST.all_show_ids(categories=("watching", "planned"))
|
||||
|
||||
self.assertEqual(filtered, ["show-p", "show-w"])
|
||||
|
||||
|
||||
class WatchlistRefreshJobTests(unittest.TestCase):
|
||||
@@ -518,7 +562,7 @@ class WatchlistRefreshJobTests(unittest.TestCase):
|
||||
|
||||
def test_refresh_job_tracks_completion_and_errors(self):
|
||||
class FakeStore:
|
||||
def all_show_ids(self):
|
||||
def all_show_ids(self, categories=None):
|
||||
return ["show-a", "show-b"]
|
||||
|
||||
def refresh(self, show_id, include_thumbnail=True):
|
||||
@@ -546,7 +590,7 @@ class WatchlistRefreshJobTests(unittest.TestCase):
|
||||
calls = []
|
||||
|
||||
class FakeStore:
|
||||
def all_show_ids(self):
|
||||
def all_show_ids(self, categories=None):
|
||||
return ["show-a", "show-b"]
|
||||
|
||||
def refresh(self, show_id, include_thumbnail=True):
|
||||
@@ -581,7 +625,7 @@ class WatchlistRefreshJobTests(unittest.TestCase):
|
||||
"current_title": None,
|
||||
"message": "",
|
||||
}
|
||||
service.store.all_show_ids = lambda: ["show-a"]
|
||||
service.store.all_show_ids = lambda categories=None: ["show-a"]
|
||||
service.store.refresh = mock.Mock(return_value={"title": "Show A", "status": "updated"})
|
||||
service.stop_event.set()
|
||||
|
||||
@@ -592,7 +636,7 @@ class WatchlistRefreshJobTests(unittest.TestCase):
|
||||
|
||||
def test_refresh_start_reuses_pending_job(self):
|
||||
class FakeStore:
|
||||
def all_show_ids(self):
|
||||
def all_show_ids(self, categories=None):
|
||||
return []
|
||||
|
||||
def refresh(self, _show_id, include_thumbnail=True):
|
||||
@@ -609,7 +653,7 @@ class WatchlistRefreshJobTests(unittest.TestCase):
|
||||
|
||||
def test_scheduled_refresh_logs_queue_and_completion(self):
|
||||
class FakeStore:
|
||||
def all_show_ids(self):
|
||||
def all_show_ids(self, categories=None):
|
||||
return ["show-a"]
|
||||
|
||||
def refresh(self, _show_id, include_thumbnail=True):
|
||||
@@ -629,7 +673,7 @@ class WatchlistRefreshJobTests(unittest.TestCase):
|
||||
|
||||
def test_refresh_history_marks_pending_jobs_interrupted_after_restart(self):
|
||||
class FakeStore:
|
||||
def all_show_ids(self):
|
||||
def all_show_ids(self, categories=None):
|
||||
return []
|
||||
|
||||
def refresh(self, _show_id, include_thumbnail=True):
|
||||
@@ -1526,7 +1570,7 @@ class WatchlistAutoRefreshSchedulerTests(unittest.TestCase):
|
||||
|
||||
def test_refresh_job_waits_between_series_using_configured_delay(self):
|
||||
class FakeStore:
|
||||
def all_show_ids(self):
|
||||
def all_show_ids(self, categories=None):
|
||||
return ["show-a", "show-b", "show-c"]
|
||||
|
||||
def refresh(self, show_id, include_thumbnail=True):
|
||||
@@ -1548,7 +1592,7 @@ class WatchlistAutoRefreshSchedulerTests(unittest.TestCase):
|
||||
|
||||
def test_refresh_job_sends_new_episode_and_failure_notifications(self):
|
||||
class FakeStore:
|
||||
def all_show_ids(self):
|
||||
def all_show_ids(self, categories=None):
|
||||
return ["show-a", "show-b"]
|
||||
|
||||
def refresh(self, show_id, include_thumbnail=True):
|
||||
|
||||
Reference in New Issue
Block a user