當前位置: 首頁>>代碼示例>>Python>>正文


Python mock.Mock類代碼示例

本文整理匯總了Python中asynctest.mock.Mock的典型用法代碼示例。如果您正苦於以下問題:Python Mock類的具體用法?Python Mock怎麽用?Python Mock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Mock類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_handle__other_wizard

 async def test_handle__other_wizard(self):
     self.stranger.wizard = "other_wizard"
     self.stranger_setup_wizard.activate = CoroutineMock()
     message = Mock()
     message.text = "foo_text"
     self.assertFalse((await self.stranger_setup_wizard.handle(message)))
     self.stranger_setup_wizard.activate.assert_not_called()
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:7,代碼來源:test_stranger_setup_wizard.py

示例2: test_get_cached_stranger__cached

 def test_get_cached_stranger__cached(self):
     cached_stranger = Mock()
     cached_stranger.id = 31416
     self.stranger_service._strangers_cache[31416] = cached_stranger
     stranger = Mock()
     stranger.id = 31416
     self.assertEqual(self.stranger_service.get_cached_stranger(stranger), cached_stranger)
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:7,代碼來源:test_stranger_service.py

示例3: test_handle_command__not_activated_command_start

 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)
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:7,代碼來源:test_stranger_setup_wizard.py

示例4: test_send__reply

 async def test_send__reply(self):
     message = Mock()
     message.is_reply = True
     message.type = 'text'
     with self.assertRaises(StrangerSenderError):
         await self.sender.send(message)
     self.sender.sendMessage.assert_not_called()
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:7,代碼來源:test_stranger_sender.py

示例5: test_send__unknown_content_type

 async def test_send__unknown_content_type(self):
     message = Mock()
     message.is_reply = False
     message.type = 'foo_type'
     with self.assertRaises(StrangerSenderError):
         await self.sender.send(message)
     self.sender.sendMessage.assert_not_called()
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:7,代碼來源:test_stranger_sender.py

示例6: test_handle_command__other_command

 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)
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:7,代碼來源:test_admin_handler.py

示例7: test_on_chat_message__text_stranger_has_blocked_the_bot

 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?!',
         )
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:25,代碼來源:test_stranger_handler.py

示例8: get_strangers

def get_strangers():
    for stranger_json in STRANGERS:
        stranger = Mock()
        stranger.sex = stranger_json['sex']
        stranger.partner_sex = stranger_json['partner_sex']
        stranger.get_languages = Mock(return_value=stranger_json['languages'])
        yield stranger
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:7,代碼來源:test_stats_service.py

示例9: test_handle_command__start_no_invitation_is_in_setup

 async def test_handle_command__start_no_invitation_is_in_setup(self):
     message = Mock()
     message.command_args = ''
     self.stranger.wizard = 'setup'
     self.stranger.invited_by = None
     await self.stranger_handler._handle_command_start(message)
     self.assertEqual(self.stranger.invited_by, None)
     self.sender.send_notification.assert_not_called()
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:8,代碼來源:test_stranger_handler.py

示例10: test_handle__deactivated_not_novice

 async def test_handle__deactivated_not_novice(self):
     self.stranger.wizard = "none"
     self.stranger.is_novice = Mock(return_value=False)
     self.stranger_setup_wizard.activate = CoroutineMock()
     message = Mock()
     message.text = "foo_text"
     self.assertFalse((await self.stranger_setup_wizard.handle(message)))
     self.stranger_setup_wizard.activate.assert_not_called()
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:8,代碼來源:test_stranger_setup_wizard.py

示例11: test_send__text

 async def test_send__text(self):
     message = Mock()
     message.is_reply = False
     message.type = 'text'
     message.sending_kwargs = {
         'foo': 'bar',
         'baz': 'boo',
         }
     await self.sender.send(message)
     self.sender.sendMessage.assert_called_once_with(**message.sending_kwargs)
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:10,代碼來源:test_stranger_sender.py

示例12: test_handle_command_pay__no_command_args

 async def test_handle_command_pay__no_command_args(self):
     from randtalkbot.admin_handler import StrangerService
     stranger_service = StrangerService.get_instance.return_value
     message = Mock()
     message.command_args = None
     await self.admin_handler._handle_command_pay(message)
     stranger_service.get_stranger.assert_not_called()
     self.sender.send_notification.assert_called_once_with(
         'Please specify Telegram ID and bonus amount like this: `/pay 31416 10 Thanks!`',
         )
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:10,代碼來源:test_admin_handler.py

示例13: test_handle_command_clear

 async def test_handle_command_clear(self):
     from randtalkbot.admin_handler import StrangerService
     stranger = CoroutineMock()
     stranger_service = StrangerService.get_instance.return_value
     stranger_service.get_stranger.return_value = stranger
     message = Mock()
     message.command_args = '31416'
     await self.admin_handler._handle_command_clear(message)
     stranger_service.get_stranger.assert_called_once_with(31416)
     stranger.end_talk.assert_called_once_with()
     self.sender.send_notification.assert_called_once_with('Stranger {0} was cleared', 31416)
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:11,代碼來源:test_admin_handler.py

示例14: test_handle_command_pay

 async def test_handle_command_pay(self):
     from randtalkbot.admin_handler import StrangerService
     stranger_service = StrangerService.get_instance.return_value
     stranger = CoroutineMock()
     stranger_service.get_stranger.return_value = stranger
     message = Mock()
     message.command_args = '31416 27183 foo gratitude'
     await self.admin_handler._handle_command_pay(message)
     stranger_service.get_stranger.assert_called_once_with(31416)
     stranger.pay.assert_called_once_with(27183, 'foo gratitude')
     self.sender.send_notification.assert_called_once_with('Success.')
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:11,代碼來源:test_admin_handler.py

示例15: test_handle_command__start_no_invitation

 async def test_handle_command__start_no_invitation(self):
     message = Mock()
     message.command_args = ''
     self.stranger.wizard = 'none'
     self.stranger.invited_by = None
     await self.stranger_handler._handle_command_start(message)
     self.assertEqual(self.stranger.invited_by, None)
     self.sender.send_notification.assert_called_once_with(
         '*Manual*\n\nUse /begin to start looking for a conversational partner, once '
             'you\'re matched you can use /end to end the conversation.'
         )
開發者ID:quasiyoke,項目名稱:RandTalkBot,代碼行數:11,代碼來源:test_stranger_handler.py


注:本文中的asynctest.mock.Mock類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。