本文整理匯總了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)