本文整理汇总了Python中mock.Mock.result方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.result方法的具体用法?Python Mock.result怎么用?Python Mock.result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.result方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run_interactive
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_run_interactive(capfd):
"""Ensure the calls to run a command on a list of hosts interactively."""
runner = Bladerunner({"threads": 14})
fake_result = Mock()
fake_result.result = Mock(return_value="fake results")
mock_con = Mock()
runner.interactive_hosts = {"fake host": mock_con}
fake_thread = Mock()
fake_thread.__enter__ = fake_context
fake_thread.__exit__ = fake_context
fake_thread.submit = Mock(return_value=fake_result)
threadpool_mock = patch.object(
base,
"ThreadPoolExecutor",
return_value=fake_thread,
)
with patch.object(runner, "setup_interactive") as mock_setup:
with threadpool_mock as mock_threadpool:
runner.run_interactive("fake cmd", "fake host")
mock_setup.assert_called_once_with("fake host")
mock_threadpool.assert_called_once_with(max_workers=14)
stdout, stderr = capfd.readouterr()
assert stdout == "fake host: fake results\n"
assert stderr == ""
示例2: test_success
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_success(self, UrlFetchClassMock):
# Mocking pagseguro Fetch
UrlFetchClassMock.return_value = _build_mock()
# Mocking previous command
data_cmd_mock = Mock()
data_cmd_mock.access_data.email = '[email protected]'
data_cmd_mock.access_data.token = '4567890oiuytfgh'
reference0 = ItemReferenceMock()
reference1 = ItemReferenceMock()
items = [PagSegItem(description='Python Course', price=Decimal('120'), quantity=1, reference=reference0.key),
PagSegItem(description='Another Python Course', price=Decimal('240'), quantity=2,
reference=reference1.key)]
ndb.put_multi(items)
data_cmd_mock.items = items
data_cmd_mock.client_form = ValidateClientCmd(email='[email protected]', name='Jhon Doe').form
data_cmd_mock.address_form = pagseguro_facade.validate_address_cmd('Rua 1', '2', 'meu bairro', '12345678',
'São Paulo', 'SP', 'apto 4').form
payment = PagSegPayment()
payment.put()
data_cmd_mock.result = payment
contact_pagseguro_cmd = ContactPagseguro('https://store.com/pagseguro')
CommandSequential(data_cmd_mock, contact_pagseguro_cmd).execute()
self.assertEqual(payment, contact_pagseguro_cmd.result)
self.assertEqual(payment.status, STATUS_SENT_TO_PAGSEGURO)
self.assertEqual(contact_pagseguro_cmd.checkout_code, _SUCCESS_PAGSEGURO_CODE,
'Should have the code extracted from xml _PAGSEGURO_DETAIL_XML')
self.assertIsNone(payment.code)
示例3: test_no_logged_user
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_no_logged_user(self, cookie_facade):
cmd_mock = Mock()
cmd_mock.execute = Mock(return_value=cmd_mock)
cmd_mock.result = None
cookie_facade.retrive_cookie_data = Mock(return_value=cmd_mock)
result = facade.logged_user(None).execute().result
self.assertIsNone(result)
示例4: test_get_user_stack_status_resume_after_suspend
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_get_user_stack_status_resume_after_suspend(self):
self.init_block()
now = int(time.time())
suspend_timeout = self.block.configuration.get("suspend_timeout")
suspend_timestamp = now - suspend_timeout
self.block.stacks = {
self.block.stack_name: {
"suspend_timestamp": suspend_timestamp,
"status": {"status": "CREATE_COMPLETE"}
}
}
mock_result = Mock()
mock_result.ready.return_value = True
mock_result.successful.return_value = True
mock_result.result = {"status": "RESUME_COMPLETE"}
mock_launch_stack_task=Mock(return_value=mock_result)
mock_suspend_user_stack=Mock()
with patch.multiple(self.block,
launch_stack_task=mock_launch_stack_task,
suspend_user_stack=mock_suspend_user_stack
):
data = {
"initialize": True,
"reset": False
}
result = self.call_handler("get_user_stack_status", data)
self.assertEqual(result, mock_result.result)
self.assertTrue(mock_launch_stack_task.called)
self.assertTrue(mock_suspend_user_stack.called)
示例5: test_save_item_arcs_command
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_save_item_arcs_command(self):
command_with_item_forms = Mock()
access_data = CreateOrUpdateAccessData('[email protected]', 'abc1234')()
items = [PagSegItem(description='Python Birds', price=Decimal('18.99'), quantity=3),
PagSegItem(description='Objetos Pythônicos', price=Decimal('24.99'), quantity=2,
reference=ndb.Key(PagSegItem, 10))]
command_with_item_forms.items = items
address_form_mock = Mock()
client_form_mock = Mock()
command_with_item_forms.address_form = address_form_mock
command_with_item_forms.client_form = client_form_mock
command_with_item_forms.access_data = access_data
ndb.put_multi(items)
payment = mommy.save_one(PagSegPayment)
command_with_item_forms.result = payment
save_payment_to_items_arcs_cmd = SavePaymentToItemsArcs()
CommandSequential(command_with_item_forms, save_payment_to_items_arcs_cmd).execute()
self.assertListEqual(items, SearchItems(payment)())
self.assertListEqual(items, save_payment_to_items_arcs_cmd.items)
# Data used for sequential commands
self.assertEqual('[email protected].com', save_payment_to_items_arcs_cmd.access_data.email)
self.assertEqual('abc1234', save_payment_to_items_arcs_cmd.access_data.token)
self.assertEqual(save_payment_to_items_arcs_cmd.address_form, address_form_mock)
self.assertEqual(save_payment_to_items_arcs_cmd.client_form, client_form_mock)
示例6: test_run_interactive_returns
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_run_interactive_returns():
"""Confirm the dict return when print_results is False."""
runner = Bladerunner({"threads": 17})
fake_result = Mock()
fake_result.result = Mock(return_value="some result")
mock_con = Mock()
runner.interactive_hosts = {"host": mock_con}
fake_thread = Mock()
fake_thread.__enter__ = fake_context
fake_thread.__exit__ = fake_context
fake_thread.submit = Mock(return_value=fake_result)
threadpool_mock = patch.object(
base,
"ThreadPoolExecutor",
return_value=fake_thread,
)
with patch.object(runner, "setup_interactive") as mock_setup:
with threadpool_mock as mock_threadpool:
results = runner.run_interactive("ok", "host", print_results=False)
mock_setup.assert_called_once_with("host")
mock_threadpool.assert_called_once_with(max_workers=17)
assert results == {"host": "some result"}
示例7: test_logged_user
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_logged_user(self, cookie_facade):
user = mommy.save_one(MainUser)
cmd_mock = Mock()
cmd_mock.execute = Mock(return_value=cmd_mock)
cmd_mock.result = {'id': user.key.id()}
cookie_facade.retrive_cookie_data = Mock(return_value=cmd_mock)
result = facade.logged_user(None).execute().result
self.assertEqual(user, result)
示例8: make_fake_conn
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def make_fake_conn(receive_returns=None):
receive_returns = receive_returns or (["{}"], "", 0)
conn = Mock()
conn.return_value = conn
conn.execute = conn
conn.receive = Mock(return_value=receive_returns)
conn.result = Mock(return_value=conn)
return conn
示例9: mock_protocol
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def mock_protocol():
mproto = Mock(RPCProtocol)
foo = Mock(RPCResponse)
foo.result = None
mproto.parse_reply = Mock(return_value=foo)
return mproto
示例10: make_fake_conn
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def make_fake_conn(receive_returns=None):
receive_returns = receive_returns or (['{}'], '', 0)
conn = Mock()
conn.return_value = conn
conn.execute = conn
conn.receive = Mock(return_value=receive_returns)
conn.gateway.remote_exec = conn.receive
conn.result = Mock(return_value=conn)
return conn
示例11: create_blank_response
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def create_blank_response(cls, code, msg):
response = Mock(spec=Response)
response.responseCode = code
mock_msg = Mock()
mock_msg.message = msg
response.details = [mock_msg]
response.messageDEPRECATED = msg
response.result = Mock(spec=Result)
return response
示例12: make_fake_conn
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def make_fake_conn(receive_returns=None):
receive_returns = receive_returns or ([b'{}'], [], 0)
conn = Mock()
conn.return_value = conn
conn.execute = conn
conn.receive = Mock(return_value=receive_returns)
conn.gateway.remote_exec = conn.receive
conn.result = Mock(return_value=conn)
conn.cmd = lambda x: x
return conn
示例13: test_no_logged_user
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_no_logged_user(self, facade):
cmd_mock = Mock()
cmd_mock.execute = Mock(return_value=cmd_mock)
cmd_mock.result = None
facade.logged_user = Mock(return_value=cmd_mock)
dependency = {}
middleware.LoggedUserMiddleware(Mock(), dependency, Mock()).set_up()
self.assertEqual({'_login_path': '/login',
'_logout_path': '/logout',
'_logged_user': None}, dependency)
示例14: test_save_payment_to_log_command
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_save_payment_to_log_command(self):
command_with_item_forms = Mock()
payment = mommy.save_one(PagSegPayment)
command_with_item_forms.result = payment
save_payment_to_log_cmd = SavePaymentToLog()
CommandSequential(command_with_item_forms, save_payment_to_log_cmd).execute()
logs = SearchLogs(payment)()
self.assertEqual(1, len(logs))
self.assertEqual(STATUS_CREATED, logs[0].status)
示例15: test_no_logged_user
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import result [as 别名]
def test_no_logged_user(self, facade):
cmd_mock = Mock()
cmd_mock.execute = Mock(return_value=cmd_mock)
cmd_mock.result = None
facade.logged_user = Mock(return_value=cmd_mock)
dependency = {}
handler = Mock()
handler.request.path_qs='/foo?param1=1¶m2=2'
middleware.LoggedUserMiddleware(handler, dependency, Mock()).set_up()
self.assertEqual({'_login_path': '/login?ret_path=%2Ffoo%3Fparam1%3D1%26param2%3D2',
'_logout_path': None,
'_logged_user': None}, dependency)