예제 #1
0
    def test_exception_when_api_key_is_invalid(self) -> None:
        bot_test_instance = BaremetricsHandler()

        with self.mock_config_info({'api_key': 'TEST'}):
            with self.mock_http_conversation('invalid_api_key'):
                with self.assertRaises(StubBotHandler.BotQuitException):
                    bot_test_instance.initialize(StubBotHandler())
예제 #2
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)
예제 #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('displays details on github issues', bot.usage())
예제 #5
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())
예제 #6
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!')
예제 #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_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')
예제 #9
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)
예제 #10
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!')
예제 #11
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)
예제 #12
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'])
예제 #13
0
 def test_bot_quit_with_invalid_config(self) -> None:
     with self.mock_config_info(mock_config), self.assertRaises(StubBotHandler.BotQuitException):
         with self.mock_http_conversation('invalid_key'):
             TrelloHandler().initialize(StubBotHandler())
예제 #14
0
 def get_test_quiz(self) -> Tuple[Dict[str, Any], Any]:
     bot_handler = StubBotHandler()
     quiz_payload = read_bot_fixture_data('trivia_quiz', 'test_new_question')['response']
     with patch('random.shuffle'):
         quiz = get_quiz_from_payload(quiz_payload)
     return quiz, bot_handler
예제 #15
0
 def test_exception_when_api_key_is_invalid(self) -> None:
     bot_test_instance = LinkShortenerHandler()
     with self.mock_config_info({'key': 'qwertyuiopx'}):
         with self.mock_http_conversation('test_invalid_access_token'):
             with self.assertRaises(StubBotHandler.BotQuitException):
                 bot_test_instance.initialize(StubBotHandler())