本文整理汇总了Python中asynctest.mock.Mock.command方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.command方法的具体用法?Python Mock.command怎么用?Python Mock.command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asynctest.mock.Mock
的用法示例。
在下文中一共展示了Mock.command方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handle_command__other_command
# 需要导入模块: from asynctest.mock import Mock [as 别名]
# 或者: from asynctest.mock.Mock import command [as 别名]
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)
示例2: test_handle_command__not_activated_command_start
# 需要导入模块: from asynctest.mock import Mock [as 别名]
# 或者: from asynctest.mock.Mock import command [as 别名]
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)
示例3: test_handle_command__telegram_error
# 需要导入模块: from asynctest.mock import Mock [as 别名]
# 或者: from asynctest.mock.Mock import command [as 别名]
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)
示例4: test_handle_command__not_full_stranger
# 需要导入模块: from asynctest.mock import Mock [as 别名]
# 或者: from asynctest.mock.Mock import command [as 别名]
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()
示例5: test_handle_command__full_stranger
# 需要导入模块: from asynctest.mock import Mock [as 别名]
# 或者: from asynctest.mock.Mock import command [as 别名]
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()
示例6: test_on_chat_message__command_setup
# 需要导入模块: from asynctest.mock import Mock [as 别名]
# 或者: from asynctest.mock.Mock import command [as 别名]
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()
示例7: test_handle_command__unknown_command
# 需要导入模块: from asynctest.mock import Mock [as 别名]
# 或者: from asynctest.mock.Mock import command [as 别名]
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)
示例8: test_handle_command__ok
# 需要导入模块: from asynctest.mock import Mock [as 别名]
# 或者: from asynctest.mock.Mock import command [as 别名]
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)