当前位置: 首页>>代码示例>>Python>>正文


Python Mock.result方法代码示例

本文整理汇总了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 == ""
开发者ID:Demonware,项目名称:bladerunner,代码行数:33,代码来源:test_base.py

示例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)
开发者ID:renzon,项目名称:gaepagseguro,代码行数:33,代码来源:connection_tests.py

示例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)
开发者ID:GuidoBR,项目名称:gaepermission,代码行数:9,代码来源:main_user_tests.py

示例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)
开发者ID:hastexo,项目名称:hastexo-xblock,代码行数:35,代码来源:test_hastexo.py

示例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)
开发者ID:renzon,项目名称:gaepagseguro,代码行数:33,代码来源:save_commands_tests.py

示例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"}
开发者ID:Demonware,项目名称:bladerunner,代码行数:31,代码来源:test_base.py

示例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)
开发者ID:GuidoBR,项目名称:gaepermission,代码行数:10,代码来源:main_user_tests.py

示例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
开发者ID:wputra,项目名称:MOS-centos,代码行数:10,代码来源:test_mon.py

示例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
开发者ID:Ed-von-Schleck,项目名称:tinyrpc,代码行数:11,代码来源:test_client.py

示例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
开发者ID:Abhishekvrshny,项目名称:ceph-deploy,代码行数:11,代码来源:test_mon.py

示例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
开发者ID:bhuvan,项目名称:incubator-aurora,代码行数:11,代码来源:util.py

示例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
开发者ID:ceph,项目名称:ceph-deploy,代码行数:12,代码来源:test_mon.py

示例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)
开发者ID:giovaneliberato,项目名称:gaepermission,代码行数:12,代码来源:middleware_tests.py

示例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)
开发者ID:renzon,项目名称:gaepagseguro,代码行数:13,代码来源:save_commands_tests.py

示例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&param2=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)
开发者ID:GuidoBR,项目名称:gaepermission,代码行数:14,代码来源:middleware_tests.py


注:本文中的mock.Mock.result方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。