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)
def test_highlights_for_command_action(self): highlights = Highlights() action = HighlightsForCommandAction(highlights) self.assert_responses_with( action, FailureThrowingMessageAwareCommandActionHandler, self._create_update_with_text('/highlights_for A test'), 'collecting highlight for A: [test]')
def test_check_highlights_some(self): highlights = Highlights() expected_member = ('First', 'Second') highlights.add_pattern('Second', '#highlights test') self.assert_command_action_responses_with( CheckHighlightsCommandAction(highlights, TestMemberRetriever(expected_member)), 'No highlights available for: [First]')
def __init__(self, updater): """ :type updater: telegram.ext.updater.Updater """ self.__updater = updater self.writer_factory = TelegramWriterFactory(updater.bot) self.__registered_actions = [] self.highlights = Highlights()
def test_check_highlights_all(self): highlights = Highlights() expected_member = ('First', 'Second') highlights.add_pattern('First', '#highlights test') highlights.add_pattern('Second', '#highlights test') self.assert_command_action_responses_with( CheckHighlightsCommandAction(highlights, TestMemberRetriever(expected_member)), 'All members have highlights \o/')
def test_collect_highlights_diff(self): highlights = Highlights() highlights.add_pattern('First', '#highlights test') remaining_user = list( filter(lambda user: not highlights.get(user), AdminRetriever(self.updater, 1).admin_member)) self.assertEqual(1, len(remaining_user)) self.assertEqual('Second', remaining_user[0])
def test_collect_highlights(self): highlights = Highlights() handler = self.registry.register_action( HighlightsCollectorRegexAction(highlights), FailureThrowingRegexActionHandler) self.updater.dispatcher.process_update( self._create_update_with_text('#highlights test', 'A')) self._check_handler(handler) self.assertIn('A: test', highlights.message_string)
def test_empty_highlights_no_send(self): highlights = Highlights() self.registry.register_action( SendHighlightsConversationAction(highlights, TestMemberRetriever(('A', ))), FailureThrowingConversationActionHandler) self.updater.dispatcher.process_update( self._create_update_with_text('/send_highlights')) self.assertEqual('No highlights available for: [A]\n', self.registry.writer_factory.writer.message)
def test_ask_for_consent_before_sending(self): highlights = Highlights() highlights.add_pattern('A', '#highlights 1') assert len(highlights.highlights) == 1, highlights.highlights self.registry.register_action( SendHighlightsConversationAction(highlights, TestMemberRetriever(('A', ))), FailureThrowingConversationActionHandler) self.updater.dispatcher.process_update( self._create_update_with_text('/send_highlights')) self.assertEqual('All members have highlights \o/\n' 'really send?\n', self.registry.writer_factory.writer.message)
def test_can_execute_show_highlights(self): highlights = Highlights() highlights.add_pattern('A', '#highlights test') self.assert_command_action_responses_with( ShowHighlightsCommandAction(highlights), 'the following')
def test_hash_and_colon(self): highlights = Highlights() self.assertTrue(highlights.add_pattern('Chris', HASH_AND_COLON)) self.assertEqual('test', highlights.get('Chris'))
def test_hash_multiple(self): highlights = Highlights() self.assertTrue(highlights.add_pattern('Chris', BOTH_HASH)) self.assertEqual('test', highlights.get('Chris'))
def test_hash_back(self): highlights = Highlights() self.assertTrue(highlights.add_pattern('Chris', BACK_HASH)) self.assertEqual('test', highlights.get('Chris'))
def test_hash_front(self): highlights = Highlights() self.assertTrue(highlights.add_pattern('Chris', FRONT_HASH)) self.assertEqual('test', highlights.get('Chris'))
def test_simple_text(self): highlights = Highlights() self.assertFalse(highlights.add_pattern('Chris', 'test'))
def test_only_user_given(self): writer = LoggingWriter() HighlightsForCommandAction(Highlights())._writer_callback( writer, '/highlights_for A') self.assertEqual('Usage: /highlights_for <user> <highlight>', writer.message)
def test_show_highlights_is_empty(self): highlights = Highlights() self.assert_command_action_responses_with( ShowHighlightsCommandAction(highlights), 'no highlights')
def test_collect_highlights_responds(self): self.assert_regex_action_responses_with( HighlightsCollectorRegexAction(Highlights()), 'collecting highlight for test')