Ejemplo n.º 1
0
    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())
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
 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]')
Ejemplo n.º 5
0
 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/')
Ejemplo n.º 6
0
    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])
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
 def test_hash_and_colon(self):
     highlights = Highlights()
     self.assertTrue(highlights.add_pattern('Chris', HASH_AND_COLON))
     self.assertEqual('test', highlights.get('Chris'))
Ejemplo n.º 9
0
 def test_hash_multiple(self):
     highlights = Highlights()
     self.assertTrue(highlights.add_pattern('Chris', BOTH_HASH))
     self.assertEqual('test', highlights.get('Chris'))
Ejemplo n.º 10
0
 def test_hash_back(self):
     highlights = Highlights()
     self.assertTrue(highlights.add_pattern('Chris', BACK_HASH))
     self.assertEqual('test', highlights.get('Chris'))
Ejemplo n.º 11
0
 def test_hash_front(self):
     highlights = Highlights()
     self.assertTrue(highlights.add_pattern('Chris', FRONT_HASH))
     self.assertEqual('test', highlights.get('Chris'))
Ejemplo n.º 12
0
 def test_simple_text(self):
     highlights = Highlights()
     self.assertFalse(highlights.add_pattern('Chris', 'test'))
Ejemplo n.º 13
0
 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')