本文整理汇总了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()
示例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)
示例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)
示例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()
示例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()
示例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)
示例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?!',
)
示例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
示例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()
示例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()
示例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)
示例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!`',
)
示例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)
示例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.')
示例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.'
)