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


Python mock.call方法代码示例

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


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

示例1: test_admin_can_manage_other_apps

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_admin_can_manage_other_apps(self, mock_requests, mock_logger):
        """Administrators of Deis should be able to manage all applications.
        """
        # log in as non-admin user and create an app
        user = User.objects.get(username='autotest2')
        token = Token.objects.get(user=user).key
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token)
        app_id = self.create_app()

        # log in as admin, check to see if they have access
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
        url = '/v2/apps/{}'.format(app_id)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200, response.data)
        # check app logs
        exp_msg = "autotest2 created initial release"
        exp_log_call = mock.call(logging.INFO, exp_msg)
        mock_logger.log.has_calls(exp_log_call)

        # TODO: test run needs an initial build
        # delete the app
        url = '/v2/apps/{}'.format(app_id)
        response = self.client.delete(url)
        self.assertEqual(response.status_code, 204, response.data) 
开发者ID:deis,项目名称:controller,代码行数:26,代码来源:test_app.py

示例2: test_execute_push_artifactory_all

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_execute_push_artifactory_all(self, mock_artifactory, mock_remove, mock_copy):
        config = sb.objects.config.Config(version="1.0.0")
        args = argparse.Namespace(job="push", force=True, artifact='ALL', user='sean', token='abc123')

        self.artifactory.execute(config, args)

        mock_artifactory.assert_has_calls([
            mock.call("artifactory.test.com/ml/test/test_v1.0.0.pkl", auth=('sean', 'abc123')),
            mock.call("artifactory.test.com/ml/test/test2_v1.0.0.pkl", auth=('sean', 'abc123'))
        ], any_order=True)
        mock_copy.assert_has_calls([
            mock.call("test.pkl", "test_v1.0.0.pkl"),
            mock.call("test2.pkl", "test2_v1.0.0.pkl")
        ], any_order=True)
        mock_remove.assert_has_calls([
            mock.call("test_v1.0.0.pkl"),
            mock.call("test2_v1.0.0.pkl")
        ], any_order=True) 
开发者ID:carsdotcom,项目名称:skelebot,代码行数:20,代码来源:test_components_repository_repository.py

示例3: test_refresh

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_refresh(self):
        uuid = self.fake_provider['uuid']
        new_uuid = uuidutils.generate_uuid()
        returns = [dict(self.fake_provider, uuid=uuid),
                   dict(self.fake_provider, uuid=new_uuid)]
        expected = [mock.call(self.context, uuid),
                    mock.call(self.context, uuid)]
        with mock.patch.object(self.dbapi, 'get_resource_provider',
                               side_effect=returns,
                               autospec=True) as mock_get_resource_provider:
            provider = objects.ResourceProvider.get_by_uuid(self.context, uuid)
            self.assertEqual(uuid, provider.uuid)
            provider.refresh()
            self.assertEqual(new_uuid, provider.uuid)
            self.assertEqual(
                expected, mock_get_resource_provider.call_args_list)
            self.assertEqual(self.context, provider._context) 
开发者ID:openstack,项目名称:zun,代码行数:19,代码来源:test_resource_provider.py

示例4: test_refresh

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_refresh(self):
        uuid = self.fake_compute_node['uuid']
        hostname = self.fake_compute_node['hostname']
        new_hostname = 'myhostname'
        returns = [dict(self.fake_compute_node, hostname=hostname),
                   dict(self.fake_compute_node, hostname=new_hostname)]
        expected = [mock.call(self.context, uuid),
                    mock.call(self.context, uuid)]
        with mock.patch.object(self.dbapi, 'get_compute_node',
                               side_effect=returns,
                               autospec=True) as mock_get:
            compute_node = objects.ComputeNode.get_by_uuid(self.context, uuid)
            self.assertEqual(hostname, compute_node.hostname)
            compute_node.refresh()
            self.assertEqual(new_hostname, compute_node.hostname)
            self.assertEqual(expected, mock_get.call_args_list)
            self.assertEqual(self.context, compute_node._context) 
开发者ID:openstack,项目名称:zun,代码行数:19,代码来源:test_compute_node.py

示例5: test_refresh

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_refresh(self):
        uuid = self.fake_container['uuid']
        container_type = self.fake_container['container_type']
        new_uuid = uuidutils.generate_uuid()
        returns = [dict(self.fake_container, uuid=uuid),
                   dict(self.fake_container, uuid=new_uuid)]
        expected = [mock.call(self.context, container_type, uuid),
                    mock.call(self.context, container_type, uuid)]
        with mock.patch.object(self.dbapi, 'get_container_by_uuid',
                               side_effect=returns,
                               autospec=True) as mock_get_container:
            container = objects.Container.get_by_uuid(self.context, uuid)
            self.assertEqual(uuid, container.uuid)
            container.refresh()
            self.assertEqual(new_uuid, container.uuid)
            self.assertEqual(expected, mock_get_container.call_args_list)
            self.assertEqual(self.context, container._context) 
开发者ID:openstack,项目名称:zun,代码行数:19,代码来源:test_container.py

示例6: test_refresh

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_refresh(self):
        uuid = self.fake_volume_mapping['uuid']
        new_uuid = uuidutils.generate_uuid()
        returns = [dict(self.fake_volume_mapping, uuid=uuid),
                   dict(self.fake_volume_mapping, uuid=new_uuid)]
        expected = [mock.call(self.context, uuid),
                    mock.call(self.context, uuid)]
        with mock.patch.object(self.dbapi, 'get_volume_mapping_by_uuid',
                               side_effect=returns,
                               autospec=True) as mock_get_volume_mapping:
            volume_mapping = objects.VolumeMapping.get_by_uuid(self.context,
                                                               uuid)
            self.assertEqual(uuid, volume_mapping.uuid)
            volume_mapping.refresh()
            self.assertEqual(new_uuid, volume_mapping.uuid)
            self.assertEqual(expected, mock_get_volume_mapping.call_args_list)
            self.assertEqual(self.context, volume_mapping._context) 
开发者ID:openstack,项目名称:zun,代码行数:19,代码来源:test_volume_mapping.py

示例7: test_409_concurrent_provider_update

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_409_concurrent_provider_update(self, mock_sleep):
        # there will be 1 normal call and 3 retries
        self.mock_get.side_effect = [self.source_rsp, self.target_rsp,
                                     self.source_rsp, self.target_rsp,
                                     self.source_rsp, self.target_rsp,
                                     self.source_rsp, self.target_rsp]
        rsp = fake_requests.FakeResponse(
            409,
            jsonutils.dumps(
                {'errors': [
                    {'code': 'placement.concurrent_update',
                     'detail': ''}]}))

        self.mock_post.return_value = rsp

        resp = self.client.move_allocations(
            self.context, self.source_consumer_uuid, self.target_consumer_uuid)

        self.assertFalse(resp)
        # Post was attempted four times.
        self.assertEqual(4, self.mock_post.call_count) 
开发者ID:openstack,项目名称:zun,代码行数:23,代码来源:test_report.py

示例8: test_ensure_resource_provider_refresh_fetch

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_ensure_resource_provider_refresh_fetch(self, mock_ref_assoc,
                                                    mock_gpit):
        """Make sure refreshes are called with the appropriate UUIDs and flags
        when we fetch the provider tree from placement.
        """
        tree_uuids = set([uuids.root, uuids.one, uuids.two])
        mock_gpit.return_value = [{'uuid': u, 'name': u, 'generation': 42}
                                  for u in tree_uuids]
        self.assertEqual(uuids.root,
                         self.client._ensure_resource_provider(self.context,
                                                               uuids.root))
        mock_gpit.assert_called_once_with(self.context, uuids.root)
        mock_ref_assoc.assert_has_calls(
            [mock.call(self.context, uuid, force=True)
             for uuid in tree_uuids])
        self.assertEqual(tree_uuids,
                         set(self.client._provider_tree.get_provider_uuids())) 
开发者ID:openstack,项目名称:zun,代码行数:19,代码来源:test_report.py

示例9: test_get_sharing_providers_error

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_get_sharing_providers_error(self, logging_mock):
        # Ensure _get_sharing_providers() logs an error and raises if the
        # placement API call doesn't respond 200
        resp_mock = mock.Mock(status_code=503)
        self.ks_adap_mock.get.return_value = resp_mock
        self.ks_adap_mock.get.return_value.headers = {
            'x-openstack-request-id': uuids.request_id}

        uuid = uuids.agg
        self.assertRaises(exception.ResourceProviderRetrievalFailed,
                          self.client._get_sharing_providers,
                          self.context, [uuid])

        expected_url = ('/resource_providers?member_of=in:' + uuid +
                        '&required=MISC_SHARES_VIA_AGGREGATE')
        self.ks_adap_mock.get.assert_called_once_with(
            expected_url, microversion='1.18', endpoint_filter=mock.ANY,
            logger=mock.ANY,
            headers={'X-Openstack-Request-Id': self.context.global_id})
        # A 503 Service Unavailable should trigger an error log that
        # includes the placement request id
        self.assertTrue(logging_mock.called)
        self.assertEqual(uuids.request_id,
                         logging_mock.call_args[0][1]['placement_req_id']) 
开发者ID:openstack,项目名称:zun,代码行数:26,代码来源:test_report.py

示例10: test_aggregate_add_host_retry_success

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_aggregate_add_host_retry_success(
            self, mock_get_by_name, mock_get_aggs, mock_set_aggs):
        mock_get_by_name.return_value = {
            'uuid': uuids.cn1,
            'generation': 1,
        }
        gens = (42, 43, 44)
        mock_get_aggs.side_effect = (
            report.AggInfo(aggregates=set([]), generation=gen) for gen in gens)
        mock_set_aggs.side_effect = (
            exception.ResourceProviderUpdateConflict(
                uuid='uuid', generation=42, error='error'),
            exception.ResourceProviderUpdateConflict(
                uuid='uuid', generation=43, error='error'),
            None,
        )
        self.client.aggregate_add_host(self.context, uuids.agg1,
                                       host_name='cn1')
        mock_set_aggs.assert_has_calls([mock.call(
            self.context, uuids.cn1, set([uuids.agg1]), use_cache=False,
            generation=gen) for gen in gens]) 
开发者ID:openstack,项目名称:zun,代码行数:23,代码来源:test_report.py

示例11: test_aggregate_add_host_retry_raises

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_aggregate_add_host_retry_raises(
            self, mock_get_by_name, mock_get_aggs, mock_set_aggs):
        mock_get_by_name.return_value = {
            'uuid': uuids.cn1,
            'generation': 1,
        }
        gens = (42, 43, 44, 45)
        mock_get_aggs.side_effect = (
            report.AggInfo(aggregates=set([]), generation=gen) for gen in gens)
        mock_set_aggs.side_effect = (
            exception.ResourceProviderUpdateConflict(
                uuid='uuid', generation=gen, error='error') for gen in gens)
        self.assertRaises(
            exception.ResourceProviderUpdateConflict,
            self.client.aggregate_add_host, self.context, uuids.agg1,
            host_name='cn1')
        mock_set_aggs.assert_has_calls([mock.call(
            self.context, uuids.cn1, set([uuids.agg1]), use_cache=False,
            generation=gen) for gen in gens]) 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:test_report.py

示例12: test_aggregate_remove_host_retry_success

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_aggregate_remove_host_retry_success(
            self, mock_get_by_name, mock_get_aggs, mock_set_aggs):
        mock_get_by_name.return_value = {
            'uuid': uuids.cn1,
            'generation': 1,
        }
        gens = (42, 43, 44)
        mock_get_aggs.side_effect = (
            report.AggInfo(aggregates=set([uuids.agg1]), generation=gen)
            for gen in gens)
        mock_set_aggs.side_effect = (
            exception.ResourceProviderUpdateConflict(
                uuid='uuid', generation=42, error='error'),
            exception.ResourceProviderUpdateConflict(
                uuid='uuid', generation=43, error='error'),
            None,
        )
        self.client.aggregate_remove_host(self.context, uuids.agg1, 'cn1')
        mock_set_aggs.assert_has_calls([mock.call(
            self.context, uuids.cn1, set([]), use_cache=False,
            generation=gen) for gen in gens]) 
开发者ID:openstack,项目名称:zun,代码行数:23,代码来源:test_report.py

示例13: test_select_destinations

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_select_destinations(self, mock_random_choice, mock_hosts_up):
        all_hosts = ['host1', 'host2', 'host3', 'host4']

        def _return_hosts(*args, **kwargs):
            return all_hosts

        mock_random_choice.side_effect = ['host3']
        mock_hosts_up.side_effect = _return_hosts

        test_container = utils.get_test_container()
        containers = [objects.Container(self.context, **test_container)]
        extra_spec = {}
        dests = self.driver_cls().select_destinations(self.context, containers,
                                                      extra_spec)

        self.assertEqual(1, len(dests))
        (host, node) = (dests[0]['host'], dests[0]['nodename'])
        self.assertEqual('host3', host)
        self.assertIsNone(node)

        calls = [mock.call(all_hosts)]
        self.assertEqual(calls, mock_random_choice.call_args_list) 
开发者ID:openstack,项目名称:zun,代码行数:24,代码来源:test_chance_scheduler.py

示例14: test_hosts_up

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_hosts_up(self, mock_service_is_up, mock_list_by_binary):
        service1 = objects.ZunService()
        service2 = objects.ZunService()
        service1.host = 'host1'
        service1.disabled = False
        service2.host = 'host2'
        service2.disabled = False
        services = [service1, service2]

        mock_list_by_binary.return_value = services
        mock_service_is_up.side_effect = [False, True]

        result = self.driver.hosts_up(self.context)
        self.assertEqual(['host2'], result)

        mock_list_by_binary.assert_called_once_with(self.context,
                                                    'zun-compute')
        calls = [mock.call(service1), mock.call(service2)]
        self.assertEqual(calls, mock_service_is_up.call_args_list) 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:test_scheduler.py

示例15: test_get_records_after_head

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import call [as 别名]
def test_get_records_after_head(shard, session):
    """Once the shard has reached head, get_stream_records is called once per get_records."""
    shard.empty_responses = CALLS_TO_REACH_HEAD

    # Intentionally provide more than one page to ensure
    # the call isn't stopping because there is only one page.
    records = build_get_records_responses(1, 1)
    session.get_stream_records.side_effect = records

    returned_records = shard.get_records()

    assert len(returned_records) == 1
    assert returned_records[0]["meta"]["sequence_number"] == "0"
    assert session.get_stream_records.called_once_with(shard.iterator_id)

    assert shard.iterator_type == "at_sequence"
    assert shard.sequence_number == "0" 
开发者ID:numberoverzero,项目名称:bloop,代码行数:19,代码来源:test_shard.py


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