async def test_handle_command__other_command(self, handle_command): from randtalkbot.admin_handler import StrangerHandler message = Mock() message.command = 'foo_command' message.command_args = 'foo_args' await self.admin_handler.handle_command(message) handle_command.assert_called_once_with(message)
async def test_handle_command__ok(self): message = Mock() message.command = 'foo_command' self.stranger_handler._handle_command_foo_command = CoroutineMock() await self.stranger_handler.handle_command(message) self.stranger_handler._handle_command_foo_command.assert_called_once_with( message)
async def test_handle_command__not_activated_command_start(self): self.stranger.wizard = "none" message = Mock() message.command = "start" self.stranger_setup_wizard.handle = CoroutineMock(return_value=True) self.assertFalse((await self.stranger_setup_wizard.handle_command(message))) self.stranger_setup_wizard.handle.assert_called_once_with(message)
async def test_handle_command__not_activated_command_start(self): self.stranger.wizard = 'none' message = Mock() message.command = 'start' self.stranger_setup_wizard.handle = CoroutineMock(return_value=True) self.assertFalse((await self.stranger_setup_wizard.handle_command(message))) self.stranger_setup_wizard.handle.assert_called_once_with(message)
async def test_handle_command__full_stranger(self): self.stranger.wizard = "setup" self.stranger.wizard_step = "sex" self.stranger.is_full.return_value = True self.stranger_setup_wizard._prompt = CoroutineMock() self.stranger_setup_wizard.deactivate = CoroutineMock() message = Mock() message.command = "begin" self.assertFalse((await self.stranger_setup_wizard.handle_command(message))) self.stranger.is_full.assert_called_once_with() self.stranger_setup_wizard._prompt.assert_not_called() self.stranger_setup_wizard.deactivate.assert_called_once_with()
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_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_command__not_full_stranger(self): 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.assertTrue((await self.stranger_setup_wizard.handle_command(message))) self.sender.send_notification.assert_called_once_with( "Finish setup process please. After that you can start using bot." ) self.stranger_setup_wizard._prompt.assert_called_once_with()
async def test_on_chat_message__command_setup(self, handle_command_mock): from randtalkbot.stranger_handler import Message as message_cls_mock from randtalkbot.stranger_handler import telepot telepot.glance.return_value = 'text', 'private', 31416 message_json = {'text': 'some_command_text'} message = Mock() message.command = 'foo_command' message_cls_mock.return_value = message self.stranger_setup_wizard.handle_command.return_value = True await self.stranger_handler.on_chat_message(message_json) self.stranger.send_to_partner.assert_not_called() message_cls_mock.assert_called_once_with(message_json) handle_command_mock.assert_not_called()
async def test_handle_command__not_full_stranger(self): 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.assertTrue((await self.stranger_setup_wizard.handle_command(message))) self.sender.send_notification.assert_called_once_with( 'Finish setup process please. After that you can start using bot.', ) self.stranger_setup_wizard._prompt.assert_called_once_with()
async def test_handle_command__full_stranger(self): self.stranger.wizard = 'setup' self.stranger.wizard_step = 'sex' self.stranger.is_full.return_value = True self.stranger_setup_wizard._prompt = CoroutineMock() self.stranger_setup_wizard.deactivate = CoroutineMock() message = Mock() message.command = 'begin' self.assertFalse((await self.stranger_setup_wizard.handle_command(message))) self.stranger.is_full.assert_called_once_with() self.stranger_setup_wizard._prompt.assert_not_called() self.stranger_setup_wizard.deactivate.assert_called_once_with()
async def test_on_chat_message__command_setup(self, handle_command_mock): from randtalkbot.stranger_handler import Message from randtalkbot.stranger_handler import telepot telepot.glance.return_value = 'text', 'private', 31416 message_json = { 'text': 'some_command_text' } message = Mock() message.command = 'foo_command' Message.return_value = message self.stranger_setup_wizard.handle_command.return_value = True await self.stranger_handler.on_chat_message(message_json) self.stranger.send_to_partner.assert_not_called() Message.assert_called_once_with(message_json) handle_command_mock.assert_not_called()
async def test_handle_command__unknown_command(self): message = Mock() message.command = 'foo_command' with self.assertRaises(UnknownCommandError): await self.stranger_handler.handle_command(message)
async def test_handle_command__ok(self): message = Mock() message.command = 'foo_command' self.stranger_handler._handle_command_foo_command = CoroutineMock() await self.stranger_handler.handle_command(message) self.stranger_handler._handle_command_foo_command.assert_called_once_with(message)
async def test_handle_command__other_command(self, handle_command): message = Mock() message.command = 'foo_command' message.command_args = 'foo_args' await self.admin_handler.handle_command(message) handle_command.assert_called_once_with(message)