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


Python mock.NonCallableMock方法代码示例

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


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

示例1: test_no_result_data

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_no_result_data(self, mock_request):
        req = wsgi.Request.blank('/test')
        req.GET['Signature'] = 'test-signature'
        req.GET['AWSAccessKeyId'] = 'test-key-id'
        resp = self.kauth(req)
        self._validate_ec2_error(resp, 400, 'AuthFailure')
        mock_request.assert_called_with('POST',
                                        CONF.keystone_ec2_tokens_url,
                                        data=mock.ANY, headers=mock.ANY)

        fake_request = mock.NonCallableMock(status_code=200, headers={})
        fake_request.json.return_value = {'token': {}}
        mock_request.return_value = fake_request
        resp = self.kauth(req)
        self._validate_ec2_error(resp, 400, 'AuthFailure')

        fake_request.json.return_value = {'access': {}}
        resp = self.kauth(req)
        self._validate_ec2_error(resp, 400, 'AuthFailure') 
开发者ID:openstack,项目名称:ec2-api,代码行数:21,代码来源:test_middleware.py

示例2: test_delete_zone_abandon

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_delete_zone_abandon(self):
        self.service.storage.get_zone.return_value = RoObject(
            name='foo',
            tenant_id='2',
            id=CentralZoneTestCase.zone__id_2
        )
        designate.central.service.policy = mock.NonCallableMock(spec_set=[
            'reset',
            'set_rules',
            'init',
            'check',
        ])
        self.context.abandon = True
        self.service.storage.count_zones.return_value = 0
        self.service.delete_zone(self.context,
                                 CentralZoneTestCase.zone__id)
        self.assertTrue(self.service.storage.delete_zone.called)
        self.assertFalse(self.service.zone_api.delete_zone.called)
        pcheck, _, _ = designate.central.service.policy.check.call_args[0]
        self.assertEqual('abandon_zone', pcheck) 
开发者ID:openstack,项目名称:designate,代码行数:22,代码来源:test_basic.py

示例3: test_get_potential_posters

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_get_potential_posters(self, mocked_search):
        with self.subTest('When MAL returns no poster'):
            expected = [{
                'current': True,
                'url': self.kiznaiver.ext_poster
            }]
            mocked_search.return_value = NonCallableMock(poster=None)
            # Let the magic occur.
            posters = get_potential_posters(self.kiznaiver)
            # In this case, `get_potential_posters` cannot fix the current poster.
            self.assertCountEqual(posters, expected)

        with self.subTest('When MAL returns a poster'):
            expected = [{
                'current': True,
                'url': self.kiznaiver.ext_poster
            }, {
                'current': False,
                'url': 'kiznaiver_mal_poster_url'
            }]
            mocked_search.return_value = NonCallableMock(poster=expected[1]['url'])
            posters = get_potential_posters(self.kiznaiver)
            # In this case, `get_potential_posters` should return a list of two posters, i.e. old external, MAL's one.
            self.assertCountEqual(posters, expected) 
开发者ID:mangaki,项目名称:mangaki,代码行数:26,代码来源:test_posters.py

示例4: test_global_preference

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_global_preference(self, m_conf, m_manager):
        """Test if the global preference is used"""

        m_conf.watcher_datasources.datasources = \
            ['gnocchi', 'monasca', 'ceilometer']

        # Make sure we access the property and not the underlying function.
        m_manager.return_value.get_backend.return_value = \
            mock.NonCallableMock()

        # Access the property so that the configuration is read in order to
        # get the correct datasource
        self.strategy.datasource_backend

        m_manager.assert_called_once_with(
            config=m_conf.watcher_datasources, osc=None) 
开发者ID:openstack,项目名称:watcher,代码行数:18,代码来源:test_base.py

示例5: test_global_preference_reverse

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_global_preference_reverse(self, m_conf, m_manager):
        """Test if the global preference is used with another order"""

        m_conf.watcher_datasources.datasources = \
            ['ceilometer', 'monasca', 'gnocchi']

        # Make sure we access the property and not the underlying function.
        m_manager.return_value.get_backend.return_value = \
            mock.NonCallableMock()

        # Access the property so that the configuration is read in order to
        # get the correct datasource
        self.strategy.datasource_backend

        m_manager.assert_called_once_with(
            config=m_conf.watcher_datasources, osc=None) 
开发者ID:openstack,项目名称:watcher,代码行数:18,代码来源:test_base.py

示例6: setUp

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def setUp(self):
        super(EC2RequesterTestCase, self).setUp()
        self.controller = self.mock(
            'ec2api.api.cloud.VpcCloudController').return_value
        self.fake_context = mock.NonCallableMock(
            request_id=context.generate_request_id()) 
开发者ID:openstack,项目名称:ec2-api,代码行数:8,代码来源:test_apirequest.py

示例7: setUp

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def setUp(self):
        super(ApiInitTestCase, self).setUp()
        self.controller = self.mock(
            'ec2api.api.cloud.VpcCloudController').return_value
        self.fake_context = mock.NonCallableMock(
            request_id=context.generate_request_id())

        ec2_request = apirequest.APIRequest('FakeAction', 'fake_v1',
                                            {'Param': 'fake_param'})
        self.environ = {'REQUEST_METHOD': 'FAKE',
                        'ec2.request': ec2_request,
                        'ec2api.context': self.fake_context}
        self.request = wsgi.Request(self.environ)
        self.application = api.Executor() 
开发者ID:openstack,项目名称:ec2-api,代码行数:16,代码来源:test_api_init.py

示例8: setUp

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def setUp(self):
        super(DbApiTestCase, self).setUp()
        self.context = mock.NonCallableMock(
            project_id=fakes.random_os_id())
        self.other_context = mock.NonCallableMock(
            project_id=fakes.random_os_id()) 
开发者ID:openstack,项目名称:ec2-api,代码行数:8,代码来源:test_db_api.py

示例9: test_nova

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_nova(self, nova, get_api_version):
        context = mock.NonCallableMock(session=mock.sentinel.session)

        # test normal flow with get_api_version call
        res = clients.nova(context)
        self.assertEqual(nova.return_value, res)
        nova.assert_called_with('2.3', service_type='compute',
                                session=mock.sentinel.session)
        get_api_version.assert_called_once_with(context)

        # test CONF.nova_service_type is used
        self.configure(nova_service_type='compute_legacy')
        clients.nova(context)
        nova.assert_called_with('2.3', service_type='compute_legacy',
                                session=mock.sentinel.session) 
开发者ID:openstack,项目名称:ec2-api,代码行数:17,代码来源:test_clients.py

示例10: test_neutron

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_neutron(self, neutron):
        context = mock.NonCallableMock(session=mock.sentinel.session)
        res = clients.neutron(context)
        self.assertEqual(neutron.return_value, res)
        neutron.assert_called_with(service_type='network',
                                   session=mock.sentinel.session) 
开发者ID:openstack,项目名称:ec2-api,代码行数:8,代码来源:test_clients.py

示例11: test_glance

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_glance(self, glance):
        context = mock.NonCallableMock(session=mock.sentinel.session)
        res = clients.glance(context)
        self.assertEqual(glance.return_value, res)
        glance.assert_called_with(version='2', service_type='image',
                                  session=mock.sentinel.session) 
开发者ID:openstack,项目名称:ec2-api,代码行数:8,代码来源:test_clients.py

示例12: test_cinder

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_cinder(self, cinder):
        # test normal flow
        context = mock.NonCallableMock(session=mock.sentinel.session)
        res = clients.cinder(context)
        self.assertEqual(cinder.return_value, res)
        cinder.assert_called_with('2', service_type='volumev2',
                                  session=mock.sentinel.session) 
开发者ID:openstack,项目名称:ec2-api,代码行数:9,代码来源:test_clients.py

示例13: test_executor_name_with_task

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_executor_name_with_task(self):
        mock_task = mock.NonCallableMock(spec_set=[
            'task_name',
        ])
        mock_task.task_name = 'task_name'

        exe = processing.Executor()

        self.assertEqual('task_name', exe.task_name(mock_task)) 
开发者ID:openstack,项目名称:designate,代码行数:11,代码来源:test_processing.py

示例14: test_executor_name_with_func

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def test_executor_name_with_func(self):
        mock_task = mock.NonCallableMock(spec_set=[
            'func_name',
        ])
        mock_task.func_name = 'func_name'

        exe = processing.Executor()

        self.assertEqual('func_name', exe.task_name(mock_task)) 
开发者ID:openstack,项目名称:designate,代码行数:11,代码来源:test_processing.py

示例15: setUp

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import NonCallableMock [as 别名]
def setUp(self):
        super().setUp()
        self.app = mock.NonCallableMock()
        self.dom0 = mock.NonCallableMock(spec=qubes.vm.adminvm.AdminVM)
        self.dom0.name = 'dom0'
        self.domains = {
            'dom0': self.dom0,
        }
        self.app.domains = mock.MagicMock(**{
            '__iter__.side_effect': lambda: iter(self.domains.values()),
            '__getitem__.side_effect': self.domains.get,
        }) 
开发者ID:QubesOS,项目名称:qubes-core-admin,代码行数:14,代码来源:api_internal.py


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