예제 #1
0
 def test_bot_responds_to_empty_message(self) -> None:
     with patch('yakkl_bots.bots.witai.witai.get_handle',
                return_value=mock_handle):
         with self.mock_config_info(self.MOCK_CONFIG_INFO):
             get_bot_message_handler(self.bot_name).initialize(
                 StubBotHandler())
             with patch('wit.Wit.message',
                        return_value=self.MOCK_WITAI_RESPONSE):
                 self.verify_reply('', 'Qwertyuiop!')
예제 #2
0
    def test_normal(self) -> None:
        with patch('yakkl_bots.bots.witai.witai.get_handle',
                   return_value=mock_handle):
            with self.mock_config_info(self.MOCK_CONFIG_INFO):
                get_bot_message_handler(self.bot_name).initialize(
                    StubBotHandler())

                with patch('wit.Wit.message',
                           return_value=self.MOCK_WITAI_RESPONSE):
                    self.verify_reply('What is your favorite food?', 'pizza')
예제 #3
0
    def test_unknown_error(self) -> None:
        bot = get_bot_message_handler(self.bot_name)
        bot_handler = StubBotHandler()

        with self.mock_config_info(self.normal_config), \
                self.mock_http_conversation('test_unknown_error'), \
                self.assertRaises(HTTPError):
            bot.initialize(bot_handler)
예제 #4
0
    def test_bot_usage(self) -> None:
        bot = get_bot_message_handler(self.bot_name)
        bot_handler = StubBotHandler()

        with self.mock_config_info(self.mock_config):
            bot.initialize(bot_handler)

        self.assertIn('This bot posts on twitter from yakkl chat itself', bot.usage())
예제 #5
0
    def test_invalid_key(self) -> None:
        bot = get_bot_message_handler(self.bot_name)
        bot_handler = StubBotHandler()

        with self.mock_config_info({'key': 'somethinginvalid', 'number_of_results': '5', 'video_region': 'US'}), \
                self.mock_http_conversation('test_invalid_key'), \
                self.assertRaises(bot_handler.BotQuitException):
            bot.initialize(bot_handler)
예제 #6
0
    def test_bot_usage(self) -> None:
        bot = get_bot_message_handler(self.bot_name)
        bot_handler = StubBotHandler()

        with self.mock_config_info(self.mock_config):
            bot.initialize(bot_handler)

        self.assertIn('displays details on github issues', bot.usage())
예제 #7
0
    def test_connection_error_during_initialize(self) -> None:
        bot = get_bot_message_handler(self.bot_name)
        bot_handler = StubBotHandler()

        with self.mock_config_info(self.normal_config), \
                patch('requests.get', side_effect=ConnectionError()), \
                patch('logging.exception') as mock_logging:
            bot.initialize(bot_handler)
            self.assertTrue(mock_logging.called)
예제 #8
0
    def test_invalid_when_initialize(self) -> None:
        bot = get_bot_message_handler(self.bot_name)
        bot_handler = StubBotHandler()

        with self.mock_config_info({'auth_token': 'someInvalidKey',
                                    'username': '******',
                                    'goalname': 'goal'}), \
                self.mock_http_conversation('test_invalid_when_initialize'), \
                self.assertRaises(bot_handler.BotQuitException):
            bot.initialize(bot_handler)
예제 #9
0
    def test_invalid_when_handle_message(self) -> None:
        bot = get_bot_message_handler(self.bot_name)
        bot_handler = StubBotHandler()

        with self.mock_config_info({'auth_token': 'someInvalidKey',
                                    'username': '******',
                                    'goalname': 'goal'}), \
                patch('requests.get', side_effect=ConnectionError()), \
                self.mock_http_conversation('test_invalid_when_handle_message'), \
                patch('logging.exception'):
            self.verify_reply('5', 'Error. Check your key!')
예제 #10
0
    def test_multiple(self) -> None:
        bot = get_bot_message_handler(self.bot_name)
        bot_handler = StubBotHandler()

        bot_response = 'Here is what I found for `marvel` : ' \
                       '\n * Marvel Studios\' Avengers: Infinity War Official Trailer - [Watch now](https://www.youtube.com/watch/6ZfuNTqbHE8)' \
                       '\n * Marvel Studios\' Black Panther - Official Trailer - [Watch now](https://www.youtube.com/watch/xjDjIWPwcPU)' \
                       '\n * MARVEL RISING BEGINS! | The Next Generation of Marvel Heroes (EXCLUSIVE) - [Watch now](https://www.youtube.com/watch/6HTPCTtkWoA)' \
                       '\n * Marvel Contest of Champions Taskmaster Spotlight - [Watch now](https://www.youtube.com/watch/-8uqxdcJ9WM)' \
                       '\n * 5* Crystal Opening! SO LUCKY! - Marvel Contest Of Champions - [Watch now](https://www.youtube.com/watch/l7rrsGKJ_O4)'

        with self.mock_config_info(self.normal_config), \
                self.mock_http_conversation('test_multiple'):
            self.verify_reply('list marvel', bot_response)
예제 #11
0
    def test_bot(self) -> None:
        bot = get_bot_message_handler(self.bot_name)
        bot_handler = StubBotHandler()

        message = dict(type='stream')

        bot.initialize(bot_handler)
        bot.handle_message(message, bot_handler)

        with patch('yakkl_bots.simple_lib.SimpleMessageServer.update') as m:
            bot.handle_message(message, bot_handler)
            bot.handle_message(message, bot_handler)
            bot.handle_message(message, bot_handler)

        content_updates = [item[0][0]['content'] for item in m.call_args_list]
        self.assertEqual(content_updates, ['2', '3', '4'])