當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。