def test_run__passes_correct_blocklists_to_subscriptions(self, bot): submission = MockSubmission("12322") api = MockExportAPI().with_submission(submission) watcher = SubscriptionWatcher(api, bot) method_called = MockMethod([submission]) watcher._get_new_results = method_called.call watcher.BACK_OFF = 1 watcher.blocklists = {156: {"test", "ych"}, -200: {"example"}} sub1 = MockSubscription("deer", 156) sub2 = MockSubscription("dog", -232) watcher.subscriptions = [sub1, sub2] thread = Thread(target=lambda: self.watcher_killer(watcher)) thread.start() # Run watcher watcher.run() thread.join() assert submission in sub1.submissions_checked assert len(sub1.blocklists) == 1 assert len(sub1.blocklists[0]) == 2 assert "test" in sub1.blocklists[0] assert "ych" in sub1.blocklists[0] assert submission in sub2.submissions_checked assert len(sub2.blocklists) == 1 assert len(sub2.blocklists[0]) == 0 assert method_called.called
def test_run__failed_to_send_doesnt_kill_watcher(self, bot): submission = MockSubmission("12322") api = MockExportAPI().with_browse_results([submission], 1) watcher = SubscriptionWatcher(api, bot) watcher._send_update = lambda *args: (_ for _ in ()).throw(Exception) watcher.BACK_OFF = 3 sub1 = MockSubscription("deer", 0) watcher.subscriptions = [sub1] api.call_after_x_browse = (lambda: watcher.stop(), 2) # Run watcher start_time = datetime.datetime.now() watcher.run() end_time = datetime.datetime.now() time_waited = end_time - start_time assert 3 <= time_waited.seconds <= 5
def test_run__checks_all_new_results(self, bot): submission1 = MockSubmission("12322") submission2 = MockSubmission("12324") api = MockExportAPI().with_submissions([submission1, submission2]) watcher = SubscriptionWatcher(api, bot) method_called = MockMethod([submission1, submission2]) watcher._get_new_results = method_called.call watcher.BACK_OFF = 1 sub = MockSubscription("deer", 0) watcher.subscriptions = [sub] thread = Thread(target=lambda: self.watcher_killer(watcher)) thread.start() # Run watcher watcher.run() thread.join() assert submission1 in sub.submissions_checked assert submission2 in sub.submissions_checked assert method_called.called