Exemplo n.º 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())
Exemplo n.º 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)
Exemplo n.º 3
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())
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def test_bot_responds_to_empty_message(self) -> None:
     with patch('wyzepal_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!')
Exemplo n.º 7
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 wyzepal chat itself',
                      bot.usage())
Exemplo n.º 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)
Exemplo n.º 9
0
    def test_normal(self) -> None:
        with patch('wyzepal_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')
Exemplo n.º 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!')
Exemplo n.º 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)
Exemplo n.º 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('wyzepal_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'])
Exemplo n.º 13
0
 def test_valid_config(self) -> None:
     bot = get_bot_message_handler(self.bot_name)
     bot_handler = StubBotHandler()
     with self.mock_http_conversation('test_normal'):
         self.validate_valid_config({'key': '12345678'})
Exemplo n.º 14
0
 def test_invalid_config(self) -> None:
     bot = get_bot_message_handler(self.bot_name)
     bot_handler = StubBotHandler()
     with self.mock_http_conversation('test_403'):
         self.validate_invalid_config(
             {'key': '12345678'}, "This is likely due to an invalid key.\n")
Exemplo n.º 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())
Exemplo n.º 16
0
 def test_bot_quit_with_invalid_config(self) -> None:
     with self.mock_config_info(mock_config), self.assertRaises(
             StubBotHandler.BotQuitException):
         TrelloHandler().initialize(StubBotHandler())
Exemplo n.º 17
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