async def test_on_chat_message__text_stranger_has_blocked_the_bot(self, handle_command_mock): from randtalkbot.stranger_handler import LOGGER from randtalkbot.stranger_handler import Message from randtalkbot.stranger_handler import telepot from randtalkbot.stranger_handler import StrangerError telepot.glance.return_value = 'text', 'private', 31416 self.stranger_setup_wizard.handle.return_value = False message_json = { 'text': 'message_text', } Message.return_value.command = None partner = Mock() partner.id = 27183 self.stranger.get_partner = Mock(return_value=partner) self.stranger.id = 31416 self.stranger.send_to_partner = CoroutineMock(side_effect=TelegramError({}, '', 0)) await self.stranger_handler.on_chat_message(message_json) LOGGER.warning( 'Send text. Can\'t send to partned: %d -> %d', 31416, 27183 ) self.sender.send_notification.assert_called_once_with( 'Your partner has blocked me! How did you do that?!', )
async def test_deactivate__telegram_error(self): from randtalkbot.stranger_setup_wizard import LOGGER as logger_mock self.sender.send_notification.side_effect = TelegramError({}, '', 0) self.stranger_setup_wizard._get_sender = Mock(return_value=self.sender) self.stranger_setup_wizard._get_stranger = Mock( return_value=self.stranger) await self.stranger_setup_wizard.deactivate() self.assertTrue(logger_mock.warning.called)
async def test_prompt__telegram_error(self): from randtalkbot.stranger_setup_wizard import LOGGER self.stranger.wizard = 'setup' self.stranger.wizard_step = 'languages' self.stranger.get_languages.return_value = [] self.sender.send_notification.side_effect = TelegramError({}, '', 0) await self.stranger_setup_wizard._prompt() self.assertTrue(LOGGER.warning.called)
async def test_handle_command__telegram_error(self): from randtalkbot.stranger_setup_wizard import LOGGER self.stranger.wizard = 'setup' self.stranger.wizard_step = 'sex' self.stranger.is_full.return_value = False self.stranger_setup_wizard._prompt = CoroutineMock() message = Mock() message.command = 'begin' self.sender.send_notification.side_effect = TelegramError({}, '', 0) self.assertTrue((await self.stranger_setup_wizard.handle_command(message))) self.assertTrue(LOGGER.warning.called)
async def test_handle__telegram_error(self): from randtalkbot.stranger_setup_wizard import LOGGER from randtalkbot.stranger_setup_wizard import get_languages_codes self.stranger.wizard = 'setup' self.stranger.wizard_step = 'languages' get_languages_codes.side_effect = EmptyLanguagesError() self.stranger_setup_wizard._prompt = CoroutineMock() message = Mock() message.text = 'foo_text' self.sender.send_notification.side_effect = TelegramError({}, '', 0) self.assertTrue((await self.stranger_setup_wizard.handle(message))) self.assertTrue(LOGGER.warning.called)
async def test_prompt__telegram_error(self): from randtalkbot.stranger_setup_wizard import LOGGER as logger_mock from randtalkbot.stranger_setup_wizard import StrangerService as stranger_service_mock from randtalkbot.stranger_setup_wizard import StrangerSenderService as \ stranger_sender_service_mock self.stranger.wizard = 'setup' self.stranger.wizard_step = 'languages' self.stranger.get_languages.return_value = [] self.stranger_setup_wizard._get_sender = Mock(return_value=self.sender) self.stranger_setup_wizard._get_stranger = Mock( return_value=self.stranger) self.sender.send_notification.side_effect = TelegramError({}, '', 0) await self.stranger_setup_wizard._prompt() self.assertTrue(logger_mock.warning.called)
def send_update(update): """Raises: TelegramError: If user has blocked the bot. """ telegram_id = update['chat']['id'] if telegram_id in BOT_BLOCKERS_IDS: reason = f'User with Telegram ID {telegram_id} has blocked the bot' LOGGER.info(reason) bot_was_blocked_code = 403 raise TelegramError(reason, bot_was_blocked_code, {'reason': reason}) LOGGER.debug( 'Futures count: %d. Sending update to some (probably new) future: %s', len(SENT_FUTURES), update, ) get_first_not_done_future(SENT_FUTURES) \ .set_result(update)
async def test_handle_command_mute_bonuses__telegram_error(self): from randtalkbot.stranger_handler import LOGGER message = Mock() self.sender.send_notification.side_effect = TelegramError({}, '', 0) await self.stranger_handler._handle_command_mute_bonuses(message) self.assertTrue(LOGGER.warning.called)
async def test_deactivate__telegram_error(self): from randtalkbot.stranger_setup_wizard import LOGGER self.sender.send_notification.side_effect = TelegramError({}, '', 0) await self.stranger_setup_wizard.deactivate() self.assertTrue(LOGGER.warning.called)