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


Python MagicMock.assert_called_with方法代码示例

本文整理汇总了Python中unittest.mock.MagicMock.assert_called_with方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.assert_called_with方法的具体用法?Python MagicMock.assert_called_with怎么用?Python MagicMock.assert_called_with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.MagicMock的用法示例。


在下文中一共展示了MagicMock.assert_called_with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_handle_script_query_with_params

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
 def test_handle_script_query_with_params(self):
     scriptMock = MagicMock()
     getAttrMock = MagicMock(return_value=scriptMock)
     subject = QueryHandler(QueryParser('script arg1:a arg2:b'))
     with patch('query_handler.getattr', getAttrMock):
         response = subject.handle_query(self.aliases)
         scriptMock.assert_called_with(arg1='a', arg2='b')
开发者ID:andrew-zhou,项目名称:tourguide,代码行数:9,代码来源:query_handler_test.py

示例2: test_success

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_success(self):
        bintray_files_endpoint_response = [
            {
                'owner': 'typesafe',
                'repo': 'bundle',
                'package': 'reactive-maps-frontend',
                'version': 'v1-023f9da22',
                'path': 'download/path.zip'
            }
        ]
        get_json_mock = MagicMock(return_value=bintray_files_endpoint_response)

        with patch('conductr_cli.resolvers.bintray_resolver.get_json', get_json_mock):
            result = bintray_resolver.bintray_resolve_version('username', 'password',
                                                              'typesafe', 'bundle', 'reactive-maps-frontend',
                                                              'v1', '023f9da22')
            self.assertEqual(result, {
                'org': 'typesafe',
                'repo': 'bundle',
                'package_name': 'reactive-maps-frontend',
                'compatibility_version': 'v1',
                'digest': '023f9da22',
                'path': 'download/path.zip',
                'resolver': bintray_resolver.__name__
            })

        get_json_mock.assert_called_with(
            'https://api.bintray.com/packages/typesafe/bundle/reactive-maps-frontend/versions/v1-023f9da22/files',
            'username', 'password')
开发者ID:fsat,项目名称:conductr-cli,代码行数:31,代码来源:test_bintray_resolver.py

示例3: test_success_with_affinity

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_success_with_affinity(self):
        args = {
            'ip': '127.0.0.1',
            'port': 9005,
            'api_version': '2',
            'verbose': False,
            'quiet': False,
            'no_wait': False,
            'long_ids': False,
            'cli_parameters': '',
            'bundle': self.bundle_id,
            'scale': self.scale,
            'affinity': 'other-bundle'
        }

        expected_url = \
            'http://127.0.0.1:9005/v2/bundles/45e0c477d3e5ea92aa8d85c0d8f3e25c?scale=3&affinity=other-bundle'

        http_method = self.respond_with(200, self.default_response)
        wait_for_scale_mock = MagicMock()
        stdout = MagicMock()

        input_args = MagicMock(**args)
        with patch('requests.put', http_method), \
                patch('conductr_cli.bundle_scale.wait_for_scale', wait_for_scale_mock):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_run.run(input_args)
            self.assertTrue(result)

        http_method.assert_called_with(expected_url)
        wait_for_scale_mock.assert_called_with(self.bundle_id, self.scale, input_args)

        self.assertEqual(self.default_output(), self.output(stdout))
开发者ID:JustinPihony,项目名称:conductr-cli,代码行数:35,代码来源:test_conduct_run_v2.py

示例4: test_failure_no_disk_space

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_failure_no_disk_space(self):
        stderr = MagicMock()

        tmpdir, bundle_file = create_temp_bundle(
            strip_margin(
                """|nrOfCpus   = {}
                            |memory     = {}
                            |roles      = [{}]
                            |"""
            ).format(self.nr_of_cpus, self.memory, ", ".join(self.roles))
        )

        resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, bundle_file))
        with patch("conductr_cli.resolver.resolve_bundle", resolve_bundle_mock):
            args = self.default_args.copy()
            args.update({"bundle": bundle_file})
            logging_setup.configure_logging(MagicMock(**args), err_output=stderr)
            result = conduct_load.load(MagicMock(**args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, bundle_file)

        self.assertEqual(
            as_error(
                strip_margin(
                    """|Error: Unable to parse bundle.conf.
                                     |Error: No configuration setting found for key diskSpace.
                                     |"""
                )
            ),
            self.output(stderr),
        )

        shutil.rmtree(tmpdir)
开发者ID:fsat,项目名称:conductr-cli,代码行数:36,代码来源:test_conduct_load_v1.py

示例5: test_failure_roles_not_a_list

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_failure_roles_not_a_list(self):
        stderr = MagicMock()

        tmpdir, bundle_file = create_temp_bundle(
            strip_margin("""|nrOfCpus   = {}
                            |memory     = {}
                            |diskSpace  = {}
                            |roles      = {}
                            |""").format(self.nr_of_cpus, self.memory, self.disk_space, '-'.join(self.roles)))

        resolve_bundle_mock = MagicMock(return_value=(self.bundle_name, bundle_file))
        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock):
            args = self.default_args.copy()
            args.update({'bundle': bundle_file})
            logging_setup.configure_logging(MagicMock(**args), err_output=stderr)
            result = conduct_load.load(MagicMock(**args))
            self.assertFalse(result)

        resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, bundle_file)

        self.assertEqual(
            as_error(strip_margin("""|Error: Unable to parse bundle.conf.
                                     |Error: roles has type 'str' rather than 'list'.
                                     |""")),
            self.output(stderr))

        shutil.rmtree(tmpdir)
开发者ID:pengyangtuo,项目名称:conductr-cli,代码行数:29,代码来源:test_conduct_load_v1.py

示例6: test_success_with_configuration

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_success_with_configuration(self):
        tmpdir, config_file = create_temp_bundle_with_contents({
            'bundle.conf': '{name="overlaid-name"}',
            'config.sh': 'echo configuring'
        })

        request_headers_mock = MagicMock(return_value=self.mock_headers)
        resolve_bundle_mock = MagicMock(side_effect=[(self.bundle_name, self.bundle_file), ('config.zip', config_file)])
        zip_entry_mock = MagicMock(side_effect=['mock bundle.conf', 'mock bundle.conf overlay'])
        http_method = self.respond_with(200, self.default_response)
        stdout = MagicMock()
        open_mock = MagicMock(return_value=1)
        wait_for_installation_mock = MagicMock()

        args = self.default_args.copy()
        args.update({'configuration': config_file})
        input_args = MagicMock(**args)

        with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \
                patch('conductr_cli.bundle_utils.zip_entry', zip_entry_mock), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock), \
                patch('requests.post', http_method), \
                patch('builtins.open', open_mock), \
                patch('conductr_cli.bundle_installation.wait_for_installation', wait_for_installation_mock):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_load.load(input_args)
            self.assertTrue(result)

        self.assertEqual(
            resolve_bundle_mock.call_args_list,
            [
                call(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file),
                call(self.custom_settings, self.bundle_resolve_cache_dir, config_file)
            ]
        )

        self.assertEqual(
            open_mock.call_args_list,
            [call(self.bundle_file, 'rb'), call(config_file, 'rb')]
        )

        request_headers_mock.assert_called_with(input_args)
        expected_files = [
            ('bundleConf', ('bundle.conf', 'mock bundle.conf')),
            ('bundleConfOverlay', ('bundle.conf', 'mock bundle.conf overlay')),
            ('bundle', ('bundle.zip', 1)),
            ('configuration', ('config.zip', 1))
        ]
        http_method.assert_called_with(self.default_url, files=expected_files, timeout=LOAD_HTTP_TIMEOUT,
                                       headers=self.mock_headers)

        wait_for_installation_mock.assert_called_with(self.bundle_id, input_args)

        self.assertEqual(self.default_output(downloading_configuration='Retrieving configuration...\n'),
                         self.output(stdout))

        self.assertEqual(
            zip_entry_mock.call_args_list,
            [call('bundle.conf', self.bundle_file), call('bundle.conf', config_file)]
        )
开发者ID:pengyangtuo,项目名称:conductr-cli,代码行数:62,代码来源:test_conduct_load_v2.py

示例7: test_search

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_search(self):
        """Test that ldap is correctly queried."""
        test_query = "äüáíðáßðöó"
        attr = [
            'cn',
            'swissEduPersonMatriculationNumber',
            'givenName',
            'sn',
            'swissEduPersonGender',
            'departmentNumber',
            'ou'
        ]
        mock_results = [1, 2, 3]
        # Mock ldap query

        mock_search = MagicMock(return_value=mock_results)
        self.app.config['ldap_connector'].search = mock_search
        # Mock _process_data to check results
        with patch('amivapi.ldap._process_data') as mock_filter:
            with self.app.app_context():
                result = ldap._search(test_query)

                # Verify correct query
                mock_search.assert_called_with(test_query, attributes=attr)

                # Assert _process_data is called with ldap results
                for ind, _ in enumerate(result):
                    mock_filter.assert_called_with(mock_results[ind])
开发者ID:amiv-eth,项目名称:amivapi,代码行数:30,代码来源:test_ldap.py

示例8: test_two_bundles_mult_components_endpoints_no_path

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_two_bundles_mult_components_endpoints_no_path(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with_file_contents('data/bundle_with_services/two_bundles_no_path.json')
        stdout = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.get', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_services.services(input_args)
            self.assertTrue(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT, headers=self.mock_headers)
        self.assertEqual(
            strip_margin("""|SERVICE                   BUNDLE ID  BUNDLE NAME                   STATUS
                            |http://:6011              6e4560e    multi2-comp-multi-endp-1.0.0  Running
                            |http://:7010/comp3-endp1  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                            |http://:7011/comp3-endp2  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                            |http://:8010/comp1-endp1  f804d64    multi-comp-multi-endp-1.0.0   Running
                            |http://:8011/comp1-endp2  f804d64    multi-comp-multi-endp-1.0.0   Running
                            |http://:9010/comp2-endp1  f804d64    multi-comp-multi-endp-1.0.0   Running
                            |http://:9010/comp2-endp1  6e4560e    multi2-comp-multi-endp-1.0.0  Running
                            |http://:9011              f804d64    multi-comp-multi-endp-1.0.0   Running
                            |"""),
            self.output(stdout))
开发者ID:pengyangtuo,项目名称:conductr-cli,代码行数:28,代码来源:test_conduct_services.py

示例9: CheckTaskTests

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
class CheckTaskTests(TestCase):
    def setUp(self):
        self.subscription = factories.Subscription()
        self.client = factories.Client()
        self.subscription.clients.add(self.client)
        self.http_post = MagicMock()
        self.store_result = MagicMock()

    def test_basic_run(self):
        check = factories.Check()
        self.subscription.checks.add(check)

        tasks.run_check(
            check.pk,
            self.client.pk,
            func_http_post=self.http_post,
            func_store_result=self.store_result,
        )
        url = 'http://{}:{}/kolekti/run'.format(
            self.client.address,
            self.client.port,
        )
        data = {"command": check.command}
        self.http_post.assert_called_with(url, data)

        assert [
            call(
                check.pk,
                self.client.pk,
                ANY,
                ANY,
                ANY,
            )
        ] in self.store_result.mock_calls
开发者ID:kolekti-project,项目名称:kolekti-server,代码行数:36,代码来源:test_tasks_check.py

示例10: test_stopped_bundle

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_stopped_bundle(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with(text="""[
            {
                "attributes": { "bundleName": "test-bundle" },
                "bundleId": "45e0c477d3e5ea92aa8d85c0d8f3e25c",
                "bundleExecutions": [],
                "bundleInstallations": [1]
            }
        ]""")
        stdout = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.get', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_info.info(input_args)
            self.assertTrue(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT, headers=self.mock_headers)
        self.assertEqual(
            strip_margin("""|ID       NAME         #REP  #STR  #RUN
                            |45e0c47  test-bundle     1     0     0
                            |"""),
            self.output(stdout))
开发者ID:pengyangtuo,项目名称:conductr-cli,代码行数:28,代码来源:test_conduct_info.py

示例11: test_one_bundle_starting_long_ids

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_one_bundle_starting_long_ids(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with_file_contents('data/bundle_with_services/one_bundle_starting.json')
        stdout = MagicMock()

        args = self.default_args.copy()
        args.update({'long_ids': True})
        input_args = MagicMock(**args)
        with patch('requests.get', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_services.services(input_args)
            self.assertTrue(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT, headers=self.mock_headers)
        self.assertEqual(
            strip_margin(
                """|SERVICE                   BUNDLE ID                         BUNDLE NAME                  STATUS
                   |http://:8010/comp1-endp1  f804d644a01a5ab9f679f76939f5c7e2  multi-comp-multi-endp-1.0.0  Starting
                   |http://:8011/comp1-endp2  f804d644a01a5ab9f679f76939f5c7e2  multi-comp-multi-endp-1.0.0  Starting
                   |http://:9010/comp2-endp1  f804d644a01a5ab9f679f76939f5c7e2  multi-comp-multi-endp-1.0.0  Starting
                   |http://:9011/comp2-endp2  f804d644a01a5ab9f679f76939f5c7e2  multi-comp-multi-endp-1.0.0  Starting
                   |http://my.service         f804d644a01a5ab9f679f76939f5c7e2  multi-comp-multi-endp-1.0.0  Starting
                   |"""),
            self.output(stdout))
开发者ID:pengyangtuo,项目名称:conductr-cli,代码行数:28,代码来源:test_conduct_services.py

示例12: test_has_error

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_has_error(self):
        request_headers_mock = MagicMock(return_value=self.mock_headers)
        http_method = self.respond_with(text="""[
            {
                "attributes": { "bundleName": "test-bundle" },
                "bundleId": "45e0c477d3e5ea92aa8d85c0d8f3e25c",
                "bundleExecutions": [],
                "bundleInstallations": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                "hasError": true
            }
        ]""")
        stdout = MagicMock()

        input_args = MagicMock(**self.default_args)
        with patch('requests.get', http_method), \
                patch('conductr_cli.conduct_url.request_headers', request_headers_mock):
            logging_setup.configure_logging(input_args, stdout)
            result = conduct_info.info(input_args)
            self.assertTrue(result)

        request_headers_mock.assert_called_with(input_args)
        http_method.assert_called_with(self.default_url, timeout=DEFAULT_HTTP_TIMEOUT, headers=self.mock_headers)
        self.assertEqual(
            strip_margin("""|ID         NAME         #REP  #STR  #RUN
                            |! 45e0c47  test-bundle    10     0     0
                            |There are errors: use `conduct events` or `conduct logs` for further information
                            |"""),
            self.output(stdout))
开发者ID:pengyangtuo,项目名称:conductr-cli,代码行数:30,代码来源:test_conduct_info.py

示例13: SubQueueTest

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
class SubQueueTest(unittest.TestCase):

    def setUp(self):
        self.mock_ctx = MagicMock('zmq.Ctx')

        self.mock_socket = MagicMock('Socket')
        self.mock_socket.connect = MagicMock('Socket.bind')

        mock_socket = MagicMock('Socket', return_value=self.mock_socket)
        self.mock_ctx.socket = mock_socket
        self.mock_ctx.return_value = self.mock_ctx
        self.patch_ctx = patch('zmq.Context.instance', self.mock_ctx)
        self.patch_ctx.start()

        self.mock_zmqstream = MagicMock('ZMQStream')
        self.mock_zmqstream.on_recv = MagicMock('on_recv')
        self.mock_zmqstream.flush = MagicMock('flush')
        self.mock_zmqstream.return_value = self.mock_zmqstream
        self.patch_zmqstream = patch('redsparrow.queue.ZMQStream', self.mock_zmqstream)
        self.patch_zmqstream.start()


    def tearDown(self):
        self.patch_ctx.stop()
        self.patch_zmqstream.stop()

    def test_construct(self):
        callback = Mock('callback')
        oub  = SubQueue('test', callback)
        self.mock_socket.connect.assert_called_with('test')
        self.mock_zmqstream.assert_called_with(self.mock_socket, None)
        self.mock_zmqstream.on_recv.assert_called_with(callback)
开发者ID:Teleinformatyka,项目名称:RedSparrow,代码行数:34,代码来源:test_queue.py

示例14: PubQueueTest

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
class PubQueueTest(unittest.TestCase):

    def setUp(self):
        self.mock_ctx = MagicMock('zmq.Ctx')

        self.mock_socket = MagicMock('Socket')
        self.mock_socket.bind = MagicMock('Socket.bind')

        mock_socket = MagicMock('Socket', return_value=self.mock_socket)
        self.mock_ctx.socket = mock_socket
        self.mock_ctx.return_value = self.mock_ctx
        self.patch_ctx = patch('zmq.Context.instance', self.mock_ctx)
        self.patch_ctx.start()

        self.mock_zmqstream = MagicMock('ZMQStream')
        self.patch_zmqstream = patch('redsparrow.queue.ZMQStream', self.mock_zmqstream)
        self.patch_zmqstream.start()


    def tearDown(self):
        self.patch_ctx.stop()
        self.patch_zmqstream.stop()

    def test_construct(self):
        oub  = PubQueue('test')
        self.mock_socket.bind.assert_called_with('test')
        self.mock_zmqstream.assert_called_with(self.mock_socket, None)
开发者ID:Teleinformatyka,项目名称:RedSparrow,代码行数:29,代码来源:test_queue.py

示例15: test_vm_type_docker_machine

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import assert_called_with [as 别名]
    def test_vm_type_docker_machine(self):
        with_docker_machine_mock = MagicMock(return_value="result")
        with patch("conductr_cli.host.with_docker_machine", with_docker_machine_mock):
            result = host.resolve_ip_by_vm_type(DockerVmType.DOCKER_MACHINE)
            self.assertEqual(result, "result")

        with_docker_machine_mock.assert_called_with()
开发者ID:fsat,项目名称:conductr-cli,代码行数:9,代码来源:test_host.py


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