コード例 #1
0
 def setUp(self, stranger_sender_service, StrangerSetupWizard):
     from randtalkbot.stranger_handler import Message
     from randtalkbot.stranger_handler import StrangerService
     self.stranger = CoroutineMock()
     stranger_service = StrangerService.get_instance.return_value
     stranger_service.get_or_create_stranger.return_value = self.stranger
     StrangerSetupWizard.reset_mock()
     self.StrangerSetupWizard = StrangerSetupWizard
     self.stranger_setup_wizard = StrangerSetupWizard.return_value
     self.stranger_setup_wizard.activate = CoroutineMock()
     self.stranger_setup_wizard.handle = CoroutineMock()
     self.stranger_setup_wizard.handle_command = CoroutineMock()
     self.initial_msg = {
         'from': {
             'id': 31416,
             },
         }
     self.sender = stranger_sender_service.get_or_create_stranger_sender.return_value
     self.sender.answer_inline_query = CoroutineMock()
     self.sender.send_notification = CoroutineMock()
     self.stranger_handler = StrangerHandler(
         (Mock(), self.initial_msg, 31416),
         event_space=None,
         timeout=1,
         )
     self.stranger_sender_service = stranger_sender_service
     self.message_cls = Message
コード例 #2
0
 def test_init__stranger_service_error(self):
     from randtalkbot.stranger_handler import StrangerService
     stranger_service = StrangerService.get_instance.return_value
     stranger_service.get_or_create_stranger.side_effect = StrangerServiceError()
     with self.assertRaises(SystemExit):
         self.stranger_handler = StrangerHandler(
             (Mock(), self.initial_msg, 31416),
             event_space=None,
             timeout=1,
             )
     self.assertEqual(self.stranger_handler._from_id, 31416)
     self.assertEqual(self.stranger_handler._stranger, self.stranger)
     self.assertEqual(self.stranger_handler._stranger_setup_wizard, self.stranger_setup_wizard)
     stranger_service.get_or_create_stranger.assert_called_once_with(31416)
     self.stranger_sender_service.get_or_create_stranger_sender.assert_called_once_with(self.stranger)
     self.StrangerSetupWizard.assert_called_once_with(self.stranger)
コード例 #3
0
 def test_init__ok(self, StrangerSetupWizard):
     from randtalkbot.stranger_handler import StrangerService
     stranger_setup_wizard = StrangerSetupWizard.return_value
     stranger_service = StrangerService.get_instance.return_value
     stranger_service.get_or_create_stranger.return_value = self.stranger
     self.stranger_handler = StrangerHandler(
         (Mock(), self.initial_msg, 31416),
         event_space=None,
         timeout=1,
         )
     self.assertEqual(self.stranger_handler._from_id, 31416)
     self.assertEqual(self.stranger_handler._stranger, self.stranger)
     self.assertEqual(self.stranger_handler._stranger_setup_wizard, stranger_setup_wizard)
     stranger_service.get_or_create_stranger.assert_called_once_with(31416)
     self.stranger_sender_service.get_or_create_stranger_sender.assert_called_once_with(self.stranger)
     self.StrangerSetupWizard.assert_called_once_with(self.stranger)