def test_not_sending_highlights_with_no(self): highlights = Highlights() highlights.yc = YammerTestConnector() highlights.add_pattern('A', '#highlights 1') assert len(highlights.highlights) == 1, highlights.highlights handler = self.registry.register_action( SendHighlightsConversationAction(highlights, TestMemberRetriever(('A', ))), FailureThrowingConversationActionHandler) ask_consent_update = self._create_update_with_text('/send_highlights') self.updater.dispatcher.process_update(ask_consent_update) assert handler.conversations[(1, 1)] == 1 yes_update = self._create_update_with_text('no') yes_update.message.reply_to_message = ask_consent_update.message.message_id self.updater.dispatcher.process_update(yes_update) assert handler.conversations == {} self.assertFalse(highlights.yc.called) self.assertEqual( 'All members have highlights \o/\n' 'really send?\n' 'ok, not sending highlights.', self.registry.writer_factory.writer.message)
def test_error_will_not_clear_highlights(self): def fail(): raise Exception highlights = Highlights() highlights.yc = YammerTestConnector() highlights.yc.post_meine_woche = fail highlights.add_pattern('A', '#highlights 1') assert len(highlights.highlights) == 1, highlights.highlights self.registry.register_action( SendHighlightsConversationAction(highlights, TestMemberRetriever(('A', ))), FailureThrowingConversationActionHandler) ask_consent_update = self._create_update_with_text('/send_highlights') self.updater.dispatcher.process_update(ask_consent_update) yes_update = self._create_update_with_text('yes') yes_update.message.reply_to_message = ask_consent_update.message.message_id self.updater.dispatcher.process_update(yes_update) self.assertTrue(highlights.is_not_empty())
def test_send_highlights_with_yes(self): highlights = Highlights() highlights.yc = YammerTestConnector() highlights.add_pattern('A', '#highlights 1') assert len(highlights.highlights) == 1, highlights.highlights self.registry.register_action( SendHighlightsConversationAction(highlights, TestMemberRetriever(('A', ))), FailureThrowingConversationActionHandler) ask_consent_update = self._create_update_with_text('/send_highlights') self.updater.dispatcher.process_update(ask_consent_update) yes_update = self._create_update_with_text('yes') yes_update.message.reply_to_message = ask_consent_update.message.message_id self.updater.dispatcher.process_update(yes_update) self.assertTrue(highlights.yc.called) self.assertEqual( 'All members have highlights \o/\n' 'really send?\n' 'highlights posted to yammer: [Die Südsterne in %s:\n' % current_calendar_week() + 'A: 1]', self.registry.writer_factory.writer.message)