def test_get_new_results__goes_to_another_page(self, bot): api = MockExportAPI() api.with_browse_results([ MockSubmission("1227"), MockSubmission("1225"), MockSubmission("1224") ], page=1) api.with_browse_results([ MockSubmission("1223"), MockSubmission("1222"), MockSubmission("1220") ], page=2) watcher = SubscriptionWatcher(api, bot) watcher.latest_ids = collections.deque(maxlen=4) watcher.latest_ids.append("1220") watcher.running = True results = watcher._get_new_results() assert len(results) == 5 assert results[0].submission_id == "1222" assert results[1].submission_id == "1223" assert results[2].submission_id == "1224" assert results[3].submission_id == "1225" assert results[4].submission_id == "1227"
def test_get_new_results__returns_new_results(self, bot): api = MockExportAPI() api.with_browse_results([ MockSubmission("1223"), MockSubmission("1222"), MockSubmission("1220") ]) watcher = SubscriptionWatcher(api, bot) watcher.latest_ids.append("1220") watcher.running = True results = watcher._get_new_results() assert len(results) == 2 assert results[0].submission_id == "1222" assert results[1].submission_id == "1223"
def test_get_new_results__handles_empty_latest_ids(self, bot): api = MockExportAPI() api.with_browse_results([ MockSubmission("1223"), MockSubmission("1222"), MockSubmission("1220") ]) watcher = SubscriptionWatcher(api, bot) watcher.running = True results = watcher._get_new_results() assert len(results) == 0 assert len(watcher.latest_ids) == 3 assert watcher.latest_ids[0] == "1220" assert watcher.latest_ids[1] == "1222" assert watcher.latest_ids[2] == "1223"
def test_get_new_results__respects_page_cap(self, bot): api = MockExportAPI() api.with_browse_results([MockSubmission("1300")], page=1) api.with_browse_results([MockSubmission("1298")], page=2) api.with_browse_results([MockSubmission("1297")], page=3) api.with_browse_results([MockSubmission("1295")], page=4) api.with_browse_results([MockSubmission("1280")], page=5) api.with_browse_results([MockSubmission("1272")], page=6) api.with_browse_results([MockSubmission("1250")], page=7) watcher = SubscriptionWatcher(api, bot) watcher.PAGE_CAP = 5 watcher.latest_ids.append("1250") watcher.running = True results = watcher._get_new_results() assert len(results) == 5 assert "1272" not in [x.submission_id for x in results]