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_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_on_chat_message__text(self, handle_command_mock):
     from randtalkbot.stranger_handler import Message
     from randtalkbot.stranger_handler import telepot
     telepot.glance.return_value = 'text', 'private', 31416
     self.stranger_setup_wizard.handle.return_value = False
     message_json = {
         'text': 'message_text'
         }
     message = Message.return_value
     message.command = None
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger.send_to_partner.assert_called_once_with(Message.return_value)
     self.stranger_setup_wizard.handle.assert_called_once_with(message)
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()
 async def test_on_chat_message__text(self, handle_command_mock):
     from randtalkbot.stranger_handler import Message
     from randtalkbot.stranger_handler import telepot
     telepot.glance.return_value = 'text', 'private', 31416
     self.stranger_setup_wizard.handle.return_value = False
     message_json = {
         'text': 'message_text'
         }
     message = Message.return_value
     message.command = None
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger.send_to_partner.assert_called_once_with(Message.return_value)
     self.stranger_setup_wizard.handle.assert_called_once_with(message)
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()
 async def test_on_chat_message__setup(self, handle_command_mock):
     from randtalkbot.stranger_handler import Message
     from randtalkbot.stranger_handler import telepot
     telepot.glance.return_value = 'text', 'private', 31416
     # This means, message was handled by StrangerSetupWizard.
     self.stranger_setup_wizard.handle.return_value = True
     message_json = {
         'text': 'message_text',
         }
     message = Message.return_value
     message.command = None
     self.stranger_setup_wizard.handle.return_value = True
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger_setup_wizard.handle.assert_called_once_with(message)
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()
 async def test_on_chat_message__setup(self, handle_command_mock):
     from randtalkbot.stranger_handler import Message
     from randtalkbot.stranger_handler import telepot
     telepot.glance.return_value = 'text', 'private', 31416
     # This means, message was handled by StrangerSetupWizard.
     self.stranger_setup_wizard.handle.return_value = True
     message_json = {
         'text': 'message_text',
         }
     message = Message.return_value
     message.command = None
     self.stranger_setup_wizard.handle.return_value = True
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger_setup_wizard.handle.assert_called_once_with(message)
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()
 async def test_on_chat_message__not_supported_by_message_cls_content(self, handle_command_mock):
     from randtalkbot.stranger_handler import Message
     from randtalkbot.stranger_handler import telepot
     from randtalkbot.stranger_handler import StrangerError
     telepot.glance.return_value = 'unsupported_content', 'private', 31416
     message_json = Mock()
     message = Message.return_value
     message.command = None
     self.stranger.send_to_partner = CoroutineMock()
     self.stranger_setup_wizard.handle.return_value = False
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger.send_to_partner.assert_not_called()
     self.sender.send_notification.assert_called_once_with(
         'Messages of this type aren\'t supported.',
         )
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()
 async def test_on_chat_message__text_no_partner(self, handle_command_mock):
     from randtalkbot.stranger_handler import Message
     from randtalkbot.stranger_handler import telepot
     from randtalkbot.errors import MissingPartnerError
     telepot.glance.return_value = 'text', 'private', 31416
     self.stranger_setup_wizard.handle.return_value = False
     message_json = {
         'text': 'message_text',
         }
     self.stranger.send_to_partner = CoroutineMock(side_effect=MissingPartnerError())
     message = Message.return_value
     message.command = None
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger.send_to_partner.assert_called_once_with(message)
     self.stranger_setup_wizard.handle.assert_called_once_with(message)
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()
 async def test_on_chat_message__not_supported_by_message_cls_content(self, handle_command_mock):
     from randtalkbot.stranger_handler import Message
     from randtalkbot.stranger_handler import telepot
     from randtalkbot.stranger_handler import StrangerError
     telepot.glance.return_value = 'unsupported_content', 'private', 31416
     message_json = Mock()
     message = Message.return_value
     message.command = None
     self.stranger.send_to_partner = CoroutineMock()
     self.stranger_setup_wizard.handle.return_value = False
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger.send_to_partner.assert_not_called()
     self.sender.send_notification.assert_called_once_with(
         'Messages of this type aren\'t supported.',
         )
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()
 async def test_on_chat_message__text_no_partner(self, handle_command_mock):
     from randtalkbot.stranger_handler import Message
     from randtalkbot.stranger_handler import telepot
     from randtalkbot.errors import MissingPartnerError
     telepot.glance.return_value = 'text', 'private', 31416
     self.stranger_setup_wizard.handle.return_value = False
     message_json = {
         'text': 'message_text',
         }
     self.stranger.send_to_partner = CoroutineMock(side_effect=MissingPartnerError())
     message = Message.return_value
     message.command = None
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger.send_to_partner.assert_called_once_with(message)
     self.stranger_setup_wizard.handle.assert_called_once_with(message)
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()
Exemplo n.º 11
0
 async def test_on_chat_message__text_stranger_error(self, handle_command_mock):
     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
     self.stranger.send_to_partner = CoroutineMock(side_effect=StrangerError())
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger.send_to_partner.assert_called_once_with(Message.return_value)
     self.sender.send_notification.assert_called_once_with(
         'Messages of this type aren\'t supported.',
         )
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()
 async def test_on_chat_message__text_stranger_error(self, handle_command_mock):
     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
     self.stranger.send_to_partner = CoroutineMock(side_effect=StrangerError())
     await self.stranger_handler.on_chat_message(message_json)
     self.stranger.send_to_partner.assert_called_once_with(Message.return_value)
     self.sender.send_notification.assert_called_once_with(
         'Messages of this type aren\'t supported.',
         )
     Message.assert_called_once_with(message_json)
     handle_command_mock.assert_not_called()