當前位置: 首頁>>代碼示例>>Python>>正文


Python fixtures.MockPatchObject方法代碼示例

本文整理匯總了Python中fixtures.MockPatchObject方法的典型用法代碼示例。如果您正苦於以下問題:Python fixtures.MockPatchObject方法的具體用法?Python fixtures.MockPatchObject怎麽用?Python fixtures.MockPatchObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fixtures的用法示例。


在下文中一共展示了fixtures.MockPatchObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(PeriodicSecondaryRefreshTest, self).setUp()
        self.useFixture(cfg_fixture.Config(CONF))

        # Mock a ctxt...
        self.ctxt = mock.Mock()
        self.useFixture(fixtures.MockPatchObject(
            context.DesignateContext, 'get_admin_context',
            return_value=self.ctxt
        ))

        # Mock a central...
        self.central = mock.Mock()
        self.useFixture(fixtures.MockPatchObject(
            central_api.CentralAPI, 'get_instance',
            return_value=self.central
        ))

        self.task = tasks.PeriodicSecondaryRefreshTask()
        self.task.my_partitions = 0, 9 
開發者ID:openstack,項目名稱:designate,代碼行數:22,代碼來源:test_tasks.py

示例2: test_multiple_pools

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def test_multiple_pools(self):
        pools = objects.PoolList.from_list(
            [
                {"id": "6c346011-e581-429b-a7a2-6cdf0aba91c3"},
                {"id": "5fabcd37-262c-4cf3-8625-7f419434b6df"}
            ]
        )

        self.useFixture(fixtures.MockPatchObject(
            policy, 'check',
            return_value=None
        ))

        pools = self.test_filter.filter(self.context, pools, self.zone)

        self.assertEqual(len(pools), 1)

        self.assertEqual("6c346011-e581-429b-a7a2-6cdf0aba91c3", pools[0].id) 
開發者ID:openstack,項目名稱:designate,代碼行數:20,代碼來源:test_filters.py

示例3: test_policy_failure

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def test_policy_failure(self):
        pools = objects.PoolList.from_list(
            [{"id": "6c346011-e581-429b-a7a2-6cdf0aba91c3"}]
        )

        self.useFixture(fixtures.MockPatchObject(
            policy, 'check',
            side_effect=exceptions.Forbidden
        ))

        self.assertRaises(
            exceptions.Forbidden,
            self.test_filter.filter, self.context, pools, self.zone,
        )

        policy.check.assert_called_once_with(
            'zone_create_forced_pool',
            self.context,
            pools[0]) 
開發者ID:openstack,項目名稱:designate,代碼行數:21,代碼來源:test_filters.py

示例4: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(GeneratorTest, self).setUp()

        # The baremetal inspector client expects the service to be running
        # when it is initialised and attempts to connect. This mocks out this
        # service only and returns a simple function that can be used by the
        # inspection utils.
        self.useFixture(fixtures.MockPatchObject(
            actions.BaremetalIntrospectionAction, "get_fake_client_method",
            return_value=lambda x: None))

        # Do the same for the Zun client.
        # There is no rpm packaging for Zun client
        # so importing the client will fail when building
        # the rpm and running the unittest so lets mock it
        self.useFixture(fixtures.MockPatchObject(
            actions.ZunAction, "get_fake_client_method",
            return_value=lambda x: None))

        # Same for Qinling client
        self.useFixture(fixtures.MockPatchObject(
            actions.QinlingAction, "get_fake_client_method",
            return_value=lambda x: None)) 
開發者ID:openstack,項目名稱:mistral-extra,代碼行數:25,代碼來源:test_generator.py

示例5: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(BaseProcessTest, self).setUp()

        self.cache_fixture = self.useFixture(
            fixtures.MockPatchObject(node_cache, 'find_node', autospec=True))
        self.process_fixture = self.useFixture(
            fixtures.MockPatchObject(process, '_process_node', autospec=True))

        self.find_mock = self.cache_fixture.mock
        self.node_info = node_cache.NodeInfo(
            uuid=self.node.uuid,
            state=istate.States.waiting,
            started_at=self.started_at)
        self.node_info.finished = mock.Mock()
        self.find_mock.return_value = self.node_info
        self.cli.get_node.return_value = self.node
        self.process_mock = self.process_fixture.mock
        self.process_mock.return_value = self.fake_result_json
        self.addCleanup(self._cleanup_lock, self.node_info) 
開發者ID:openstack,項目名稱:ironic-inspector,代碼行數:21,代碼來源:test_process.py

示例6: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(BaseTest, self).setUp()
        introspect._LAST_INTROSPECTION_TIME = 0
        self.node.power_state = 'power off'
        self.ports = [mock.Mock(address=m) for m in self.macs]
        self.ports_dict = collections.OrderedDict((p.address, p)
                                                  for p in self.ports)
        self.node_info = mock.Mock(uuid=self.uuid, options={})
        self.node_info.ports.return_value = self.ports_dict
        self.node_info.node.return_value = self.node
        driver_fixture = self.useFixture(fixtures.MockPatchObject(
            pxe_filter, 'driver', autospec=True))
        driver_mock = driver_fixture.mock.return_value
        self.sync_filter_mock = driver_mock.sync

        self.async_exc = None
        executor_fixture = self.useFixture(fixtures.MockPatchObject(
            utils, 'executor', autospec=True))
        self.submit_mock = executor_fixture.mock.return_value.submit
        self.submit_mock.side_effect = self._submit 
開發者ID:openstack,項目名稱:ironic-inspector,代碼行數:22,代碼來源:test_introspect.py

示例7: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(TestManagerInitHost, self).setUp()
        self.mock_db_init = self.useFixture(fixtures.MockPatchObject(
            manager.db, 'init')).mock
        self.mock_validate_processing_hooks = self.useFixture(
            fixtures.MockPatchObject(manager.plugins_base,
                                     'validate_processing_hooks')).mock
        self.mock_filter = self.useFixture(fixtures.MockPatchObject(
            manager.pxe_filter, 'driver')).mock.return_value
        self.mock_PeriodicWorker = self.useFixture(fixtures.MockPatchObject(
            manager.periodics, 'PeriodicWorker')).mock
        self.mock_executor = self.useFixture(fixtures.MockPatchObject(
            manager.utils, 'executor')).mock
        self.mock_ExistingExecutor = self.useFixture(fixtures.MockPatchObject(
            manager.periodics, 'ExistingExecutor')).mock
        self.mock_exit = self.useFixture(fixtures.MockPatchObject(
            manager.sys, 'exit')).mock 
開發者ID:openstack,項目名稱:ironic-inspector,代碼行數:19,代碼來源:test_manager.py

示例8: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(TestDnsmasqDriverAPI, self).setUp()
        self.mock__execute = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_execute')).mock
        self.driver._sync = mock.Mock()
        self.driver._tear_down = mock.Mock()
        self.mock__purge_dhcp_hostsdir = self.useFixture(
            fixtures.MockPatchObject(dnsmasq, '_purge_dhcp_hostsdir')).mock
        self.mock_ironic = mock.Mock()
        get_client_mock = self.useFixture(
            fixtures.MockPatchObject(ir_utils, 'get_client')).mock
        get_client_mock.return_value = self.mock_ironic
        self.start_command = '/far/boo buzz -V --ack 42'
        CONF.set_override('dnsmasq_start_command', self.start_command,
                          'dnsmasq_pxe_filter')
        self.stop_command = '/what/ever'
        CONF.set_override('dnsmasq_stop_command', self.stop_command,
                          'dnsmasq_pxe_filter') 
開發者ID:openstack,項目名稱:ironic-inspector,代碼行數:20,代碼來源:test_dnsmasq_pxe_filter.py

示例9: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(TestIptablesDriver, self).setUp()
        CONF.set_override('rootwrap_config', '/some/fake/path')
        # NOTE(milan) we ignore the state checking in order to avoid having to
        # always call e.g self.driver.init_filter() to set proper driver state
        self.mock_fsm = self.useFixture(
            fixtures.MockPatchObject(iptables.IptablesFilter, 'fsm')).mock
        self.mock_call = self.useFixture(
            fixtures.MockPatchObject(iptables.processutils, 'execute')).mock
        self.driver = iptables.IptablesFilter()
        self.mock_iptables = self.useFixture(
            fixtures.MockPatchObject(self.driver, '_iptables')).mock
        self.mock_should_enable_dhcp = self.useFixture(
            fixtures.MockPatchObject(iptables, '_should_enable_dhcp')).mock
        self.mock__get_blacklist = self.useFixture(
            fixtures.MockPatchObject(iptables, '_get_blacklist')).mock
        self.mock__get_blacklist.return_value = []
        self.mock_ironic = mock.Mock() 
開發者ID:openstack,項目名稱:ironic-inspector,代碼行數:20,代碼來源:test_iptables.py

示例10: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(RestTest, self).setUp()

        if self.auth_mode == "keystone":
            self.auth_token_fixture = self.useFixture(
                ksm_fixture.AuthTokenFixture())
            self.auth_token_fixture.add_token_data(
                is_v2=True,
                token_id=TestingApp.VALID_TOKEN_ADMIN,
                user_id=TestingApp.USER_ID_ADMIN,
                user_name='adminusername',
                project_id=TestingApp.PROJECT_ID_ADMIN,
                role_list=['admin'])
            self.auth_token_fixture.add_token_data(
                is_v2=True,
                token_id=TestingApp.VALID_TOKEN,
                user_id=TestingApp.USER_ID,
                user_name='myusername',
                project_id=TestingApp.PROJECT_ID,
                role_list=["member"])
            self.auth_token_fixture.add_token_data(
                is_v2=True,
                token_id=TestingApp.VALID_TOKEN_2,
                user_id=TestingApp.USER_ID_2,
                user_name='myusername2',
                project_id=TestingApp.PROJECT_ID_2,
                role_list=["member"])

        self.conf.set_override("auth_mode", self.auth_mode, group="api")

        self.useFixture(fixtures.MockPatchObject(
            app.GnocchiHook, "_lazy_load", self._fake_lazy_load))

        self.app = TestingApp(app.load_app(conf=self.conf,
                                           not_implemented_middleware=False),
                              chef=self.chef,
                              auth_mode=self.auth_mode) 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:39,代碼來源:test_rest.py

示例11: test_create_zone_no_servers

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def test_create_zone_no_servers(self):
        self.service._enforce_zone_quota = mock.Mock()
        self.service._is_valid_zone_name = mock.Mock()
        self.service._is_valid_ttl = mock.Mock()
        self.service._is_subzone = mock.Mock(
            return_value=False
        )
        self.service._is_superzone = mock.Mock(
            return_value=[]
        )
        self.service.storage.get_pool.return_value = RoObject(
            ns_records=[]
        )

        self.useFixture(
            fixtures.MockPatchObject(
                self.service.storage,
                'find_pools',
                return_value=objects.PoolList.from_list(
                    [
                        {'id': '94ccc2c1-d751-44fe-b57f-8894c9f5c842'}
                    ]
                )
            )
        )

        z = objects.Zone(tenant_id='1',
                         name='example.com.', ttl=60,
                         pool_id=CentralZoneTestCase.pool__id)

        self.assertRaises(exceptions.NoServersConfigured,
                          self.service.create_zone,
                          self.context, z) 
開發者ID:openstack,項目名稱:designate,代碼行數:35,代碼來源:test_basic.py

示例12: test_no_pools

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def test_no_pools(self):
        pools = objects.PoolList()

        self.useFixture(fixtures.MockPatchObject(
            policy, 'check',
            return_value=None
        ))

        pools = self.test_filter.filter(self.context, pools, self.zone)

        self.assertEqual(len(pools), 0) 
開發者ID:openstack,項目名稱:designate,代碼行數:13,代碼來源:test_filters.py

示例13: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(TestAdapterClasses, self).setUp()
        self.mock_logoff = self.useFixture(
            fixtures.MockPatchObject(adp.Session, '_logoff')).mock
        self.mock_logon = self.useFixture(
            fixtures.MockPatchObject(adp.Session, '_logon')).mock
        self.mock_events = self.useFixture(
            fixtures.MockPatchObject(adp._EventListener, '_get_events')).mock
        # Mock the initial events coming in on start
        self.mock_events.return_value = {'general': 'init'}, [], [] 
開發者ID:powervm,項目名稱:pypowervm,代碼行數:12,代碼來源:test_adapter.py

示例14: patchClass

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def patchClass(self, module, name, autospec=True, attach_as=None):
        """Patches a modules class.

        This will create a class instance mock (using the provided name to
        find the class in the module) and attach a mock class the master mock
        to be cleaned up on test exit.
        """
        if autospec:
            instance_mock = mock.Mock(spec_set=getattr(module, name))
        else:
            instance_mock = mock.Mock()

        f = self.useFixture(fixtures.MockPatchObject(module, name,
                                                     autospec=autospec))
        class_mock = f.mock
        class_mock.return_value = instance_mock

        if attach_as is None:
            attach_class_as = name
            attach_instance_as = name.lower()
        else:
            attach_class_as = attach_as + '_class'
            attach_instance_as = attach_as

        self.master_mock.attach_mock(class_mock, attach_class_as)
        self.master_mock.attach_mock(instance_mock, attach_instance_as)
        return class_mock, instance_mock 
開發者ID:openstack,項目名稱:taskflow,代碼行數:29,代碼來源:test.py

示例15: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatchObject [as 別名]
def setUp(self):
        super(TestNvramManager, self).setUp()
        self.fake_store = fake_api.NoopNvramStore()
        self.fake_exp_store = fake_api.ExpNvramStore()
        self.mock_store = self.useFixture(
            fixtures.MockPatchObject(self.fake_store, 'store')).mock
        self.mock_fetch = self.useFixture(
            fixtures.MockPatchObject(self.fake_store, 'fetch')).mock
        self.mock_remove = self.useFixture(
            fixtures.MockPatchObject(self.fake_store, 'delete')).mock
        self.mock_exp_remove = self.useFixture(
            fixtures.MockPatchObject(self.fake_exp_store, 'delete')).mock 
開發者ID:openstack,項目名稱:nova-powervm,代碼行數:14,代碼來源:test_manager.py


注:本文中的fixtures.MockPatchObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。