コード例 #1
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!')
コード例 #2
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')
コード例 #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())
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
ファイル: test_beeminder.py プロジェクト: WyzePal/api
    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)
コード例 #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())
コード例 #8
0
ファイル: test_beeminder.py プロジェクト: WyzePal/api
    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
ファイル: test_beeminder.py プロジェクト: WyzePal/api
    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('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'])
コード例 #12
0
ファイル: test_giphy.py プロジェクト: WyzePal/api
 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'})
コード例 #13
0
ファイル: test_giphy.py プロジェクト: WyzePal/api
 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")