Python fixtures.MockPatch() Examples

The following are 30 code examples of fixtures.MockPatch(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fixtures , or try the search function .
Example #1
Source File: test_storage.py    From pypowervm with Apache License 2.0 6 votes vote down vote up
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) 
Example #2
Source File: test_metrics.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
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) 
Example #3
Source File: test_alarms.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
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) 
Example #4
Source File: test_notifications.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestNotificationsType, self).setUp()

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

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

        self.notification_resource = notificationstype.NotificationsType()
        self.app.add_route(
            '/v2.0/notification-methods/types', self.notification_resource) 
Example #5
Source File: test_alarms.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestAlarmDefinition, self).setUp()

        self.alarm_def_repo_mock = self.useFixture(fixtures.MockPatch(
            'monasca_api.common.repositories.'
            'alarm_definitions_repository.AlarmDefinitionsRepository'
        )).mock

        self.alarm_definition_resource = alarm_definitions.AlarmDefinitions()
        self.alarm_definition_resource.send_event = Mock()
        self._send_event = self.alarm_definition_resource.send_event

        self.app.add_route("/v2.0/alarm-definitions/",
                           self.alarm_definition_resource)
        self.app.add_route("/v2.0/alarm-definitions/{alarm_definition_id}",
                           self.alarm_definition_resource) 
Example #6
Source File: test_notifications.py    From monasca-api with Apache License 2.0 6 votes vote down vote up
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) 
Example #7
Source File: test_install_upgrade.py    From python-tripleoclient with Apache License 2.0 6 votes vote down vote up
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 
Example #8
Source File: test_processutils.py    From oslo.concurrency with Apache License 2.0 6 votes vote down vote up
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) 
Example #9
Source File: test_vm.py    From nova-powervm with Apache License 2.0 6 votes vote down vote up
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 
Example #10
Source File: test_ibmi.py    From pypowervm with Apache License 2.0 6 votes vote down vote up
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 
Example #11
Source File: test_server.py    From octavia with Apache License 2.0 6 votes vote down vote up
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() 
Example #12
Source File: test_power.py    From pypowervm with Apache License 2.0 6 votes vote down vote up
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 
Example #13
Source File: test_media.py    From nova-powervm with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestConfigDrivePowerVM, self).setUp()

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

        self.validate_vopt = self.useFixture(fixtures.MockPatch(
            'pypowervm.tasks.vopt.validate_vopt_repo_exists')).mock
        self.validate_vopt.return_value = None, None 
Example #14
Source File: test_alarm_scenarios.py    From aodh with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestAlarmsBase, self).setUp()
        self.project_id = uuidutils.generate_uuid()
        self.user_id = uuidutils.generate_uuid()
        self.auth_headers = {'X-User-Id': self.user_id,
                             'X-Project-Id': self.project_id}

        c = mock.Mock()
        c.capabilities.list.return_value = {'aggregation_methods': [
            'count', 'mean', 'max', 'min', 'first', 'last', 'std']}
        self.useFixture(fixtures.MockPatch(
            'aodh.api.controllers.v2.alarm_rules.gnocchi.client.Client',
            return_value=c
        )) 
Example #15
Source File: test_evaluator.py    From aodh with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestAlarmEvaluationService, self).setUp()
        conf = service.prepare_service(argv=[], config_files=[])
        self.CONF = self.useFixture(fixture_config.Config(conf)).conf
        self.CONF.set_override('workers', 1, 'evaluator')
        self.setup_messaging(self.CONF)

        self.threshold_eval = mock.MagicMock()
        self._fake_conn = mock.Mock()
        self._fake_conn.get_alarms.return_value = []
        self._fake_pc = mock.Mock()
        self._fake_em = extension.ExtensionManager.make_test_instance(
            [
                extension.Extension(
                    'gnocchi_aggregation_by_metrics_threshold',
                    None,
                    None,
                    self.threshold_eval),
            ]
        )

        self.useFixture(fixtures.MockPatch(
            'stevedore.extension.ExtensionManager',
            return_value=self._fake_em
        ))
        self.useFixture(fixtures.MockPatch(
            'aodh.coordination.PartitionCoordinator',
            return_value=self._fake_pc
        ))
        self.useFixture(fixtures.MockPatch(
            'aodh.storage.get_connection_from_config',
            return_value=self._fake_conn
        )) 
Example #16
Source File: test_metrics.py    From monasca-api with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestMeasurements, self).setUp()

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

        self.metrics_resource = metrics.MetricsMeasurements()

        self.app.add_route('/v2.0/metrics/measurements',
                           self.metrics_resource) 
Example #17
Source File: db.py    From aodh with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestBase, self).setUp()
        db_url = os.environ.get(
            'AODH_TEST_STORAGE_URL',
            'sqlite://').replace(
                "mysql://", "mysql+pymysql://")
        engine = urlparse.urlparse(db_url).scheme
        # In case some drivers have additional specification, for example:
        # PyMySQL will have scheme mysql+pymysql.
        self.engine = engine.split('+')[0]

        conf = service.prepare_service(argv=[], config_files=[])
        self.CONF = self.useFixture(fixture_config.Config(conf)).conf
        self.CONF.set_override('connection', db_url, group="database")

        manager = self.DRIVER_MANAGERS.get(self.engine)
        if not manager:
            self.skipTest("missing driver manager: %s" % self.engine)

        self.db_manager = manager(self.CONF)

        self.useFixture(self.db_manager)

        self.CONF.set_override('connection', self.db_manager.url,
                               group="database")

        self.alarm_conn = storage.get_connection_from_config(self.CONF)
        self.alarm_conn.upgrade()

        self.useFixture(fixtures.MockPatch(
            'aodh.storage.get_connection_from_config',
            side_effect=self._get_connection)) 
Example #18
Source File: base.py    From aodh with Apache License 2.0 5 votes vote down vote up
def setup_messaging(self, conf, exchange=None):
        self.useFixture(oslo_messaging.conffixture.ConfFixture(conf))
        conf.set_override("notification_driver", ["messaging"])
        if not exchange:
            exchange = 'aodh'
        conf.set_override("control_exchange", exchange)

        # NOTE(sileht): Ensure a new oslo.messaging driver is loaded
        # between each tests
        self.transport = messaging.get_transport(conf, "fake://", cache=False)
        self.useFixture(fixtures.MockPatch(
            'aodh.messaging.get_transport',
            return_value=self.transport)) 
Example #19
Source File: test_composite.py    From aodh with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.client = self.useFixture(fixtures.MockPatch(
            'aodh.evaluator.gnocchi.client'
        )).mock.Client.return_value
        super(BaseCompositeEvaluate, self).setUp() 
Example #20
Source File: test_notifier.py    From aodh with Apache License 2.0 5 votes vote down vote up
def test_trust_zaqar_notifier_action(self):
        client = mock.MagicMock()
        client.session.auth.get_access.return_value.auth_token = 'token_1234'

        self.useFixture(
            fixtures.MockPatch('aodh.keystone_client.get_trusted_client',
                               lambda *args: client))

        action = 'trust+zaqar://trust-1234:delete@?queue_name=foobar-critical'
        self._msg_notifier.sample({}, 'alarm.update',
                                  self._notification(action))
        time.sleep(1)
        self.assertEqual(0, self.zaqar.subscriptions)
        self.assertEqual(1, self.zaqar.posts) 
Example #21
Source File: test_mockpatch.py    From oslotest with Apache License 2.0 5 votes vote down vote up
def test_reference(self):
        # Applications expect these public symbols to be available until the
        # deprecated module is removed.
        self.assertTrue(fixtures.MockPatchObject)
        self.assertTrue(fixtures.MockPatch)
        self.assertTrue(fixtures.MockPatchMultiple) 
Example #22
Source File: test_metrics.py    From monasca-api with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestDimensionValues, self).setUp()

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

        self.metrics_resource = metrics.DimensionValues()

        self.app.add_route('/v2.0/metrics/dimensions/values',
                           self.metrics_resource) 
Example #23
Source File: test_localdisk.py    From nova-powervm with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestLocalDisk, self).setUp()

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

        # The mock VIOS needs to have scsi_mappings as a list.  Internals are
        # set by individual test cases as needed.
        smaps = [mock.Mock()]
        self.vio_to_vg = mock.Mock(spec=pvm_vios.VIOS, scsi_mappings=smaps,
                                   uuid='vios-uuid')
        # Set up mock for internal VIOS.get()s
        self.mock_vios_get = self.useFixture(fixtures.MockPatch(
            'pypowervm.wrappers.virtual_io_server.VIOS',
            autospec=True)).mock.get
        # For our tests, we want find_maps to return the mocked list of scsi
        # mappings in our mocked VIOS.
        self.mock_find_maps = self.useFixture(fixtures.MockPatch(
            'pypowervm.tasks.scsi_mapper.find_maps', autospec=True)).mock
        self.mock_find_maps.return_value = smaps

        # Set up for the mocks for get_ls
        self.mock_find_vg = self.useFixture(fixtures.MockPatch(
            'pypowervm.tasks.storage.find_vg', autospec=True)).mock
        self.vg_uuid = uuids.vg_uuid
        self.vg = mock.Mock(spec=pvm_stor.VG, uuid=self.vg_uuid)
        self.mock_find_vg.return_value = (self.vio_to_vg, self.vg)

        # Return the mgmt uuid
        self.mgmt_uuid = self.useFixture(fixtures.MockPatch(
            'nova_powervm.virt.powervm.mgmt.mgmt_uuid')).mock
        self.mgmt_uuid.return_value = 'mp_uuid'

        self.flags(volume_group_name='fakevg', group='powervm') 
Example #24
Source File: test_ssp.py    From nova-powervm with Apache License 2.0 5 votes vote down vote up
def mockpatch(self, methstr):
        return self.useFixture(fixtures.MockPatch(methstr)).mock 
Example #25
Source File: test_imagecache.py    From nova-powervm with Apache License 2.0 5 votes vote down vote up
def test_get_base(self):
        self.mock_vg_get = self.useFixture(fixtures.MockPatch(
            'pypowervm.wrappers.storage.VG.get')).mock
        self.mock_vg_get.return_value = self.mock_vg
        vg_wrap = self.img_cache._get_base()
        self.assertEqual(vg_wrap, self.mock_vg)
        self.mock_vg_get.assert_called_once_with(
            self.adpt, uuid=self.vg_uuid,
            parent_type=pvm_vios.VIOS.schema_type, parent_uuid=self.vios_uuid) 
Example #26
Source File: test_vm.py    From nova-powervm with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestVMBuilder, self).setUp()

        self.adpt = mock.MagicMock()
        self.host_w = mock.MagicMock()
        self.lpar_b = vm.VMBuilder(self.host_w, self.adpt)

        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 
Example #27
Source File: test_storage.py    From nova-powervm with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestStorage, self).setUp()

        self.adapter = mock.Mock()
        self.disk_dvr = mock.MagicMock()
        self.mock_cfg_drv = self.useFixture(fixtures.MockPatch(
            'nova_powervm.virt.powervm.media.ConfigDrivePowerVM')).mock
        self.mock_mb = self.mock_cfg_drv.return_value
        self.instance = mock.MagicMock()
        self.context = 'context' 
Example #28
Source File: fixtures.py    From nova-powervm with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TaskFlow, self).setUp()
        self.tasks_added = []
        self.lf_fix = self.useFixture(
            fixtures.MockPatch(self.linear_flow_import))
        self.lf_fix.mock.Flow.return_value.add.side_effect = self._record_tasks

        self.engine_fx = self.useFixture(
            fixtures.MockPatch(self.engines_import)) 
Example #29
Source File: fixtures.py    From nova-powervm with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(VolumeAdapter, self).setUp()
        self.std_vol_adpt_fx = self.useFixture(
            fixtures.MockPatch(self.patch_class, __name__='MockVolumeAdapter'))
        self.std_vol_adpt = self.std_vol_adpt_fx.mock
        # We want to mock out the connection_info individually so it gives
        # back a new mock on every call.  That's because the vol id is
        # used for task names and we can't have duplicates.  Here we have
        # just one mock for simplicity of the vol driver but we need
        # multiple names.
        self.std_vol_adpt.return_value.connection_info.__getitem__\
            .side_effect = mock.MagicMock
        self.drv = self.std_vol_adpt.return_value 
Example #30
Source File: fixtures.py    From nova-powervm with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(ComprehensiveScrub, self).setUp()
        self.mock_comp_scrub = self.useFixture(
            fixtures.MockPatch('pypowervm.tasks.storage.ComprehensiveScrub'))