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


Python fixtures.MockPatch方法代碼示例

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


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

示例1: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatch [as 別名]
def setUp(self):
        super(TestServerTestCase, self).setUp()
        self.conf = self.useFixture(oslo_fixture.Config(config.cfg.CONF))
        self.conf.config(group="haproxy_amphora", base_path='/var/lib/octavia')
        self.conf.config(group="controller_worker",
                         loadbalancer_topology=consts.TOPOLOGY_SINGLE)
        self.conf.load_raw_values(project='fake_project')
        self.conf.load_raw_values(prog='fake_prog')
        self.useFixture(fixtures.MockPatch(
            'oslo_config.cfg.find_config_files',
            return_value=[AMP_AGENT_CONF_PATH]))
        with mock.patch('distro.id',
                        return_value='ubuntu'):
            self.ubuntu_test_server = server.Server()
            self.ubuntu_app = self.ubuntu_test_server.app.test_client()

        with mock.patch('distro.id',
                        return_value='centos'):
            self.centos_test_server = server.Server()
            self.centos_app = self.centos_test_server.app.test_client() 
開發者ID:openstack,項目名稱:octavia,代碼行數:22,代碼來源:test_server.py

示例2: setUp

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

        self.conf = self.useFixture(oslo_fixture.Config(cfg.CONF))
        self.conf.config(container_images_file='/home/stack/foo.yaml')
        self.conf.set_default('output_dir', '/home/stack')
        # setting this so we don't have to mock get_local_timezone everywhere
        self.conf.set_default('undercloud_timezone', 'UTC')
        # don't actually load config from ~/undercloud.conf
        self.mock_config_load = self.useFixture(
            fixtures.MockPatch('tripleoclient.utils.load_config'))
        # Get the command object to test
        app_args = mock.Mock()
        app_args.verbose_level = 1
        self.cmd = undercloud.InstallUndercloud(self.app, app_args)

    # TODO(cjeanner) drop once we have proper oslo.privsep 
開發者ID:openstack,項目名稱:python-tripleoclient,代碼行數:19,代碼來源:test_install_upgrade.py

示例3: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatch [as 別名]
def setUp(self):
        super(TestLUEnt, self).setUp()
        self.mock_feed_get = self.useFixture(fixtures.MockPatch(
            'pypowervm.wrappers.storage.LUEnt.get')).mock
        self.mock_feed_get.return_value = self.entries
        self.tier = mock.Mock(spec=stor.Tier, get=mock.Mock(
            return_value=self.entries))
        # Mock out each LUEnt's .delete so I can know I called the right ones.
        for luent in self.entries:
            luent.delete = mock.Mock()
        # This image LU...
        self.img_lu = self.entries[4]
        # ...backs these three linked clones
        self.clone1 = self.entries[9]
        self.clone2 = self.entries[11]
        self.clone3 = self.entries[21]
        self.orig_len = len(self.entries) 
開發者ID:powervm,項目名稱:pypowervm,代碼行數:19,代碼來源:test_storage.py

示例4: setUp

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

        self.adpt = self.useFixture(pvm_fx.AdapterFx()).adpt

        # Make it easier to validate job params: create_job_parameter returns a
        # simple 'name=value' string.
        mock_crt_jparm = self.useFixture(fixtures.MockPatch(
            'pypowervm.wrappers.job.Job.create_job_parameter')).mock
        mock_crt_jparm.side_effect = (
            lambda name, value, cdata=False: '%s=%s' % (name, value))

        # Patch Job.wrap to return a mocked Job wrapper
        mock_job = mock.Mock()
        self.useFixture(fixtures.MockPatch(
            'pypowervm.wrappers.job.Job.wrap')).mock.return_value = mock_job
        self.run_job = mock_job.run_job 
開發者ID:powervm,項目名稱:pypowervm,代碼行數:19,代碼來源:test_ibmi.py

示例5: setUp

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

        self.adpt = self.useFixture(fx.AdapterFx()).adpt

        # Make it easier to validate job params: create_job_parameter returns a
        # simple 'name=value' string.
        mock_crt_jparm = self.useFixture(fixtures.MockPatch(
            'pypowervm.wrappers.job.Job.create_job_parameter')).mock
        mock_crt_jparm.side_effect = (
            lambda name, value, cdata=False: '%s=%s' % (name, value))

        # Patch Job.wrap to return a mocked Job wrapper
        mock_job = mock.Mock()
        self.useFixture(fixtures.MockPatch(
            'pypowervm.wrappers.job.Job.wrap')).mock.return_value = mock_job
        self.run_job = mock_job.run_job 
開發者ID:powervm,項目名稱:pypowervm,代碼行數:19,代碼來源:test_power.py

示例6: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatch [as 別名]
def setUp(self):
        super(TestVM, self).setUp()
        self.apt = self.useFixture(pvm_fx.AdapterFx(
            traits=pvm_fx.LocalPVMTraits)).adpt
        self.apt.helpers = [pvm_log.log_helper]

        self.san_lpar_name = self.useFixture(fixtures.MockPatch(
            'pypowervm.util.sanitize_partition_name_for_api')).mock
        self.san_lpar_name.side_effect = lambda name: name

        lpar_http = pvmhttp.load_pvm_resp(LPAR_HTTPRESP_FILE, adapter=self.apt)
        self.assertNotEqual(lpar_http, None,
                            "Could not load %s " %
                            LPAR_HTTPRESP_FILE)

        self.resp = lpar_http.response 
開發者ID:openstack,項目名稱:nova-powervm,代碼行數:18,代碼來源:test_vm.py

示例7: setUp

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

        self.conf_override(
            notifications_driver='monasca_api.common.repositories.sqla.'
                                 'notifications_repository:NotificationsRepository',
            group='repositories')

        self.notifications_repo_mock = self.useFixture(fixtures.MockPatch(
            'monasca_api.common.repositories.sqla.notifications_repository.NotificationsRepository'
        )).mock

        self.notifications_type_repo_mock = self.useFixture(fixtures.MockPatch(
            'monasca_api.common.repositories.sqla.'
            'notification_method_type_repository.NotificationMethodTypeRepository'
        )).mock

        self.notification_resource = notifications.Notifications()
        self.app.add_route(
            '/v2.0/notification-methods', self.notification_resource)
        self.app.add_route(
            '/v2.0/notification-methods/{notification_method_id}', self.notification_resource) 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:24,代碼來源:test_notifications.py

示例8: setUp

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

        self.useFixture(fixtures.MockPatch(
            'monasca_api.common.messaging.kafka_publisher.KafkaPublisher'
        ))
        self.metrics_repo_mock = self.useFixture(fixtures.MockPatch(
            'monasca_api.common.repositories.influxdb.metrics_repository.MetricsRepository'
        )).mock

        # [messaging]
        self.conf_override(
            driver='monasca_api.common.messaging.'
                   'kafka_publisher:KafkaPublisher',
            group='messaging')

        self.metrics_resource = metrics.Metrics()

        self.app.add_route('/v2.0/metrics',
                           self.metrics_resource) 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:22,代碼來源:test_metrics.py

示例9: setUp

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

        self.useFixture(fixtures.MockPatch(
            'monasca_api.common.repositories.sqla.'
            'alarms_repository.AlarmsRepository'))
        self.useFixture(InfluxClientAlarmHistoryResponseFixture(
            'monasca_api.common.repositories.influxdb.'
            'metrics_repository.client.InfluxDBClient'))

        self.alarms_resource = alarms.AlarmsStateHistory()
        self.app.add_route(
            '/v2.0/alarms/{alarm_id}/state-history/', self.alarms_resource)

        self.app.add_route(
            '/v2.0/alarms/state-history/', self.alarms_resource) 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:18,代碼來源:test_alarms.py

示例10: _test_and_check_logging_communicate_errors

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatch [as 別名]
def _test_and_check_logging_communicate_errors(self, log_errors=None,
                                                   attempts=None):
        mock = self.useFixture(fixtures.MockPatch(
            'subprocess.Popen.communicate',
            side_effect=OSError(errno.EAGAIN, 'fake-test')))

        fixture = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
        kwargs = {}

        if log_errors:
            kwargs.update({"log_errors": log_errors})

        if attempts:
            kwargs.update({"attempts": attempts})

        self.assertRaises(OSError,
                          processutils.execute,
                          '/usr/bin/env',
                          'false',
                          **kwargs)

        self.assertEqual(attempts if attempts else 1, mock.mock.call_count)
        self.assertIn('Got an OSError', fixture.output)
        self.assertIn('errno: %d' % errno.EAGAIN, fixture.output)
        self.assertIn("'/usr/bin/env false'", fixture.output) 
開發者ID:openstack,項目名稱:oslo.concurrency,代碼行數:27,代碼來源:test_processutils.py

示例11: setUp

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

        self.mock_get_inv = self.useFixture(fixtures.MockPatch(
            'zun.scheduler.client.report.SchedulerReportClient.'
            '_get_inventory')).mock
        self.inv = {
            'VCPU': {'total': 16},
            'MEMORY_MB': {'total': 1024},
            'DISK_GB': {'total': 10},
        }
        self.mock_get_inv.return_value = {
            'resource_provider_generation': 41,
            'inventories': self.inv,
        }

        self.mock_get_aggs = self.useFixture(fixtures.MockPatch(
            'zun.scheduler.client.report.SchedulerReportClient.'
            '_get_provider_aggregates')).mock
        self.mock_get_aggs.return_value = report.AggInfo(
            aggregates=set([uuids.agg1]), generation=42)

        self.mock_get_traits = self.useFixture(fixtures.MockPatch(
            'zun.scheduler.client.report.SchedulerReportClient.'
            'get_provider_traits')).mock
        self.mock_get_traits.return_value = report.TraitInfo(
            traits=set(['CUSTOM_GOLD']), generation=43)

        self.mock_get_sharing = self.useFixture(fixtures.MockPatch(
            'zun.scheduler.client.report.SchedulerReportClient.'
            '_get_sharing_providers')).mock 
開發者ID:openstack,項目名稱:zun,代碼行數:33,代碼來源:test_report.py

示例12: _setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatch [as 別名]
def _setUp(self):
        self.client = mock.Mock(k8s_client.K8sClient)
        self.useFixture(fixtures.MockPatch(
            'kuryr_kubernetes.clients.get_kubernetes_client',
            lambda: self.client)) 
開發者ID:openstack,項目名稱:kuryr-kubernetes,代碼行數:7,代碼來源:kuryr_fixtures.py

示例13: setUp

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

        self.now = time.time()
        f_time = self.useFixture(fixtures.MockPatch('time.time'))
        f_time.mock.return_value = self.now

        self.k8s = self.useFixture(k_fix.MockK8sClient()).client
        f_k8s = self.useFixture(fixtures.MockPatch(
            'kuryr_kubernetes.clients.get_kubernetes_client'))
        f_k8s.mock.return_value = self.k8s 
開發者ID:openstack,項目名稱:kuryr-kubernetes,代碼行數:13,代碼來源:test_retry.py

示例14: setUp

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatch [as 別名]
def setUp(self):
        super(KeystoneContextMiddlewareTest, self).setUp()
        self.app = middleware.KeystoneContextMiddleware({})

        self.request = FakeRequest()

        # Replace the DesignateContext class..
        self.ctxt = mock.Mock()
        self.useFixture(fixtures.MockPatch(
            'designate.context.DesignateContext',
            return_value=self.ctxt
        )) 
開發者ID:openstack,項目名稱:designate,代碼行數:14,代碼來源:test_middleware.py

示例15: FIXME_test_increment_zone_serial

# 需要導入模塊: import fixtures [as 別名]
# 或者: from fixtures import MockPatch [as 別名]
def FIXME_test_increment_zone_serial(self, utils_inc_ser):
        fixtures.MockPatch('designate.central.service.utils.increment_serial')
        zone = RoObject(serial=1)
        self.service._increment_zone_serial(self.context, zone) 
開發者ID:openstack,項目名稱:designate,代碼行數:6,代碼來源:test_basic.py


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