def test_send_update__updates_latest(self, bot): api = MockExportAPI() watcher = SubscriptionWatcher(api, bot) subscription = Subscription("test", 12345) submission = SubmissionBuilder().build_mock_submission() watcher._send_update(subscription, submission) assert subscription.latest_update is not None
def test_send_update__sends_message(self, bot): api = MockExportAPI() watcher = SubscriptionWatcher(api, bot) subscription = Subscription("test", 12345) submission = SubmissionBuilder().build_mock_submission() watcher._send_update(subscription, submission) bot.send_message.assert_not_called() bot.send_photo.assert_called_once() kwargs_photo = bot.send_photo.call_args[1] assert kwargs_photo['chat_id'] == 12345 assert kwargs_photo['photo'] == submission.download_url assert "update" in kwargs_photo['caption'].lower() assert "\"test\"" in kwargs_photo['caption'] assert "subscription" in kwargs_photo['caption'].lower() assert submission.link in kwargs_photo['caption']
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