diff options
| author | Stephen Finucane <sfinucan@redhat.com> | 2022-09-29 18:42:26 +0100 |
|---|---|---|
| committer | Stephen Finucane <stephenfin@redhat.com> | 2022-09-30 11:42:07 +0000 |
| commit | 1aaaa6f1d14ebc2498513aabe788239c9f867639 (patch) | |
| tree | 6bab1ce1ca60e45a56d248e2db15b96ae00212c5 /openstackclient/tests/unit/volume/v1 | |
| parent | d7f431be507f3f6904a503e5b0ce7fcc23caa326 (diff) | |
| download | python-openstackclient-1aaaa6f1d14ebc2498513aabe788239c9f867639.tar.gz | |
tests: Remove unnecessary nesting of volume resources
Change-Id: I210ce7534d161e89115e5cb96e42ab7f27170aa1
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/tests/unit/volume/v1')
7 files changed, 664 insertions, 701 deletions
diff --git a/openstackclient/tests/unit/volume/v1/fakes.py b/openstackclient/tests/unit/volume/v1/fakes.py index 2ec40190..76b208b2 100644 --- a/openstackclient/tests/unit/volume/v1/fakes.py +++ b/openstackclient/tests/unit/volume/v1/fakes.py @@ -24,7 +24,6 @@ from openstackclient.tests.unit import utils class FakeVolumev1Client: - def __init__(self, **kwargs): self.volumes = mock.Mock() self.volumes.resource_class = fakes.FakeResource(None, {}) @@ -37,8 +36,9 @@ class FakeVolumev1Client: self.volume_types = mock.Mock() self.volume_types.resource_class = fakes.FakeResource(None, {}) self.volume_encryption_types = mock.Mock() - self.volume_encryption_types.resource_class = ( - fakes.FakeResource(None, {})) + self.volume_encryption_types.resource_class = fakes.FakeResource( + None, {} + ) self.transfers = mock.Mock() self.transfers.resource_class = fakes.FakeResource(None, {}) self.volume_snapshots = mock.Mock() @@ -52,7 +52,6 @@ class FakeVolumev1Client: class TestVolumev1(utils.TestCommand): - def setUp(self): super().setUp() @@ -75,577 +74,538 @@ class TestVolumev1(utils.TestCommand): ) -class FakeTransfer(object): - """Fake one or more Transfer.""" - - @staticmethod - def create_one_transfer(attrs=None): - """Create a fake transfer. - - :param Dictionary attrs: - A dictionary with all attributes of Transfer Request - :return: - A FakeResource object with volume_id, name, id. - """ - # Set default attribute - transfer_info = { - 'volume_id': 'volume-id-' + uuid.uuid4().hex, - 'name': 'fake_transfer_name', - 'id': 'id-' + uuid.uuid4().hex, - 'links': 'links-' + uuid.uuid4().hex, - } - - # Overwrite default attributes if there are some attributes set - attrs = attrs or {} - - transfer_info.update(attrs) - - transfer = fakes.FakeResource( - None, - transfer_info, - loaded=True) - - return transfer - - @staticmethod - def create_transfers(attrs=None, count=2): - """Create multiple fake transfers. - - :param Dictionary attrs: - A dictionary with all attributes of transfer - :param Integer count: - The number of transfers to be faked - :return: - A list of FakeResource objects - """ - transfers = [] - for n in range(0, count): - transfers.append(FakeTransfer.create_one_transfer(attrs)) - - return transfers - - @staticmethod - def get_transfers(transfers=None, count=2): - """Get an iterable MagicMock object with a list of faked transfers. - - If transfers list is provided, then initialize the Mock object with the - list. Otherwise create one. - - :param List transfers: - A list of FakeResource objects faking transfers - :param Integer count: - The number of transfers to be faked - :return - An iterable Mock object with side_effect set to a list of faked - transfers - """ - if transfers is None: - transfers = FakeTransfer.create_transfers(count) - - return mock.Mock(side_effect=transfers) - - -class FakeService(object): - """Fake one or more Services.""" - - @staticmethod - def create_one_service(attrs=None): - """Create a fake service. - - :param Dictionary attrs: - A dictionary with all attributes of service - :return: - A FakeResource object with host, status, etc. - """ - # Set default attribute - service_info = { - 'host': 'host_test', - 'binary': 'cinder_test', - 'status': 'enabled', - 'disabled_reason': 'LongHoliday-GoldenWeek', - 'zone': 'fake_zone', - 'updated_at': 'fake_date', - 'state': 'fake_state', - } - - # Overwrite default attributes if there are some attributes set - attrs = attrs or {} - - service_info.update(attrs) - - service = fakes.FakeResource( - None, - service_info, - loaded=True) - - return service - - @staticmethod - def create_services(attrs=None, count=2): - """Create multiple fake services. - - :param Dictionary attrs: - A dictionary with all attributes of service - :param Integer count: - The number of services to be faked - :return: - A list of FakeResource objects - """ - services = [] - for n in range(0, count): - services.append(FakeService.create_one_service(attrs)) - - return services - - @staticmethod - def get_services(services=None, count=2): - """Get an iterable MagicMock object with a list of faked services. - - If services list is provided, then initialize the Mock object with the - list. Otherwise create one. - - :param List services: - A list of FakeResource objects faking services - :param Integer count: - The number of services to be faked - :return - An iterable Mock object with side_effect set to a list of faked - services - """ - if services is None: - services = FakeService.create_services(count) - - return mock.Mock(side_effect=services) - - -class FakeQos(object): - """Fake one or more Qos specification.""" - - @staticmethod - def create_one_qos(attrs=None): - """Create a fake Qos specification. - - :param Dictionary attrs: - A dictionary with all attributes - :return: - A FakeResource object with id, name, consumer, etc. - """ - attrs = attrs or {} - - # Set default attributes. - qos_info = { - "id": 'qos-id-' + uuid.uuid4().hex, - "name": 'qos-name-' + uuid.uuid4().hex, - "consumer": 'front-end', - "specs": {"foo": "bar", "iops": "9001"}, - } - - # Overwrite default attributes. - qos_info.update(attrs) - - qos = fakes.FakeResource( - info=copy.deepcopy(qos_info), - loaded=True) - return qos - - @staticmethod - def create_one_qos_association(attrs=None): - """Create a fake Qos specification association. - - :param Dictionary attrs: - A dictionary with all attributes - :return: - A FakeResource object with id, name, association_type, etc. - """ - attrs = attrs or {} - - # Set default attributes. - qos_association_info = { - "id": 'type-id-' + uuid.uuid4().hex, - "name": 'type-name-' + uuid.uuid4().hex, - "association_type": 'volume_type', - } - - # Overwrite default attributes. - qos_association_info.update(attrs) - - qos_association = fakes.FakeResource( - info=copy.deepcopy(qos_association_info), - loaded=True) - return qos_association - - @staticmethod - def create_qoses(attrs=None, count=2): - """Create multiple fake Qos specifications. - - :param Dictionary attrs: - A dictionary with all attributes - :param int count: - The number of Qos specifications to fake - :return: - A list of FakeResource objects faking the Qos specifications - """ - qoses = [] - for i in range(0, count): - qos = FakeQos.create_one_qos(attrs) - qoses.append(qos) - - return qoses - - @staticmethod - def get_qoses(qoses=None, count=2): - """Get an iterable MagicMock object with a list of faked qoses. - - If qoses list is provided, then initialize the Mock object with the - list. Otherwise create one. - - :param List volumes: - A list of FakeResource objects faking qoses - :param Integer count: - The number of qoses to be faked - :return - An iterable Mock object with side_effect set to a list of faked - qoses - """ - if qoses is None: - qoses = FakeQos.create_qoses(count) - - return mock.Mock(side_effect=qoses) - - -class FakeVolume(object): - """Fake one or more volumes.""" - - @staticmethod - def create_one_volume(attrs=None): - """Create a fake volume. - - :param Dictionary attrs: - A dictionary with all attributes of volume - :return: - A FakeResource object with id, name, status, etc. - """ - attrs = attrs or {} - - # Set default attribute - volume_info = { - 'id': 'volume-id' + uuid.uuid4().hex, - 'display_name': 'volume-name' + uuid.uuid4().hex, - 'display_description': 'description' + uuid.uuid4().hex, - 'status': 'available', - 'size': 10, - 'volume_type': - random.choice(['fake_lvmdriver-1', 'fake_lvmdriver-2']), - 'bootable': 'true', - 'metadata': { - 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex, - 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex, - 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex}, - 'snapshot_id': 'snapshot-id-' + uuid.uuid4().hex, - 'availability_zone': 'zone' + uuid.uuid4().hex, - 'attachments': [{ +def create_one_transfer(attrs=None): + """Create a fake transfer. + + :param Dictionary attrs: + A dictionary with all attributes of Transfer Request + :return: + A FakeResource object with volume_id, name, id. + """ + # Set default attribute + transfer_info = { + 'volume_id': 'volume-id-' + uuid.uuid4().hex, + 'name': 'fake_transfer_name', + 'id': 'id-' + uuid.uuid4().hex, + 'links': 'links-' + uuid.uuid4().hex, + } + + # Overwrite default attributes if there are some attributes set + attrs = attrs or {} + + transfer_info.update(attrs) + + transfer = fakes.FakeResource(None, transfer_info, loaded=True) + + return transfer + + +def create_transfers(attrs=None, count=2): + """Create multiple fake transfers. + + :param Dictionary attrs: + A dictionary with all attributes of transfer + :param Integer count: + The number of transfers to be faked + :return: + A list of FakeResource objects + """ + transfers = [] + for n in range(0, count): + transfers.append(create_one_transfer(attrs)) + + return transfers + + +def get_transfers(transfers=None, count=2): + """Get an iterable MagicMock object with a list of faked transfers. + + If transfers list is provided, then initialize the Mock object with the + list. Otherwise create one. + + :param List transfers: + A list of FakeResource objects faking transfers + :param Integer count: + The number of transfers to be faked + :return + An iterable Mock object with side_effect set to a list of faked + transfers + """ + if transfers is None: + transfers = create_transfers(count) + + return mock.Mock(side_effect=transfers) + + +def create_one_service(attrs=None): + """Create a fake service. + + :param Dictionary attrs: + A dictionary with all attributes of service + :return: + A FakeResource object with host, status, etc. + """ + # Set default attribute + service_info = { + 'host': 'host_test', + 'binary': 'cinder_test', + 'status': 'enabled', + 'disabled_reason': 'LongHoliday-GoldenWeek', + 'zone': 'fake_zone', + 'updated_at': 'fake_date', + 'state': 'fake_state', + } + + # Overwrite default attributes if there are some attributes set + attrs = attrs or {} + + service_info.update(attrs) + + service = fakes.FakeResource(None, service_info, loaded=True) + + return service + + +def create_services(attrs=None, count=2): + """Create multiple fake services. + + :param Dictionary attrs: + A dictionary with all attributes of service + :param Integer count: + The number of services to be faked + :return: + A list of FakeResource objects + """ + services = [] + for n in range(0, count): + services.append(create_one_service(attrs)) + + return services + + +def get_services(services=None, count=2): + """Get an iterable MagicMock object with a list of faked services. + + If services list is provided, then initialize the Mock object with the + list. Otherwise create one. + + :param List services: + A list of FakeResource objects faking services + :param Integer count: + The number of services to be faked + :return + An iterable Mock object with side_effect set to a list of faked + services + """ + if services is None: + services = create_services(count) + + return mock.Mock(side_effect=services) + + +def create_one_qos(attrs=None): + """Create a fake Qos specification. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with id, name, consumer, etc. + """ + attrs = attrs or {} + + # Set default attributes. + qos_info = { + "id": 'qos-id-' + uuid.uuid4().hex, + "name": 'qos-name-' + uuid.uuid4().hex, + "consumer": 'front-end', + "specs": {"foo": "bar", "iops": "9001"}, + } + + # Overwrite default attributes. + qos_info.update(attrs) + + qos = fakes.FakeResource(info=copy.deepcopy(qos_info), loaded=True) + return qos + + +def create_one_qos_association(attrs=None): + """Create a fake Qos specification association. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with id, name, association_type, etc. + """ + attrs = attrs or {} + + # Set default attributes. + qos_association_info = { + "id": 'type-id-' + uuid.uuid4().hex, + "name": 'type-name-' + uuid.uuid4().hex, + "association_type": 'volume_type', + } + + # Overwrite default attributes. + qos_association_info.update(attrs) + + qos_association = fakes.FakeResource( + info=copy.deepcopy(qos_association_info), loaded=True + ) + return qos_association + + +def create_qoses(attrs=None, count=2): + """Create multiple fake Qos specifications. + + :param Dictionary attrs: + A dictionary with all attributes + :param int count: + The number of Qos specifications to fake + :return: + A list of FakeResource objects faking the Qos specifications + """ + qoses = [] + for i in range(0, count): + qos = create_one_qos(attrs) + qoses.append(qos) + + return qoses + + +def get_qoses(qoses=None, count=2): + """Get an iterable MagicMock object with a list of faked qoses. + + If qoses list is provided, then initialize the Mock object with the + list. Otherwise create one. + + :param List volumes: + A list of FakeResource objects faking qoses + :param Integer count: + The number of qoses to be faked + :return + An iterable Mock object with side_effect set to a list of faked + qoses + """ + if qoses is None: + qoses = create_qoses(count) + + return mock.Mock(side_effect=qoses) + + +def create_one_volume(attrs=None): + """Create a fake volume. + + :param Dictionary attrs: + A dictionary with all attributes of volume + :return: + A FakeResource object with id, name, status, etc. + """ + attrs = attrs or {} + + # Set default attribute + volume_info = { + 'id': 'volume-id' + uuid.uuid4().hex, + 'display_name': 'volume-name' + uuid.uuid4().hex, + 'display_description': 'description' + uuid.uuid4().hex, + 'status': 'available', + 'size': 10, + 'volume_type': random.choice(['fake_lvmdriver-1', 'fake_lvmdriver-2']), + 'bootable': 'true', + 'metadata': { + 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex, + 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex, + 'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex, + }, + 'snapshot_id': 'snapshot-id-' + uuid.uuid4().hex, + 'availability_zone': 'zone' + uuid.uuid4().hex, + 'attachments': [ + { 'device': '/dev/' + uuid.uuid4().hex, 'server_id': uuid.uuid4().hex, - }, ], - 'created_at': 'time-' + uuid.uuid4().hex, - } - - # Overwrite default attributes if there are some attributes set - volume_info.update(attrs) - - volume = fakes.FakeResource( - None, - volume_info, - loaded=True) - return volume - - @staticmethod - def create_volumes(attrs=None, count=2): - """Create multiple fake volumes. - - :param Dictionary attrs: - A dictionary with all attributes of volume - :param Integer count: - The number of volumes to be faked - :return: - A list of FakeResource objects - """ - volumes = [] - for n in range(0, count): - volumes.append(FakeVolume.create_one_volume(attrs)) - - return volumes - - @staticmethod - def get_volumes(volumes=None, count=2): - """Get an iterable MagicMock object with a list of faked volumes. - - If volumes list is provided, then initialize the Mock object with the - list. Otherwise create one. - - :param List volumes: - A list of FakeResource objects faking volumes - :param Integer count: - The number of volumes to be faked - :return - An iterable Mock object with side_effect set to a list of faked - volumes - """ - if volumes is None: - volumes = FakeVolume.create_volumes(count) - - return mock.Mock(side_effect=volumes) - - -class FakeVolumeType(object): - """Fake one or more type.""" - - @staticmethod - def create_one_volume_type(attrs=None, methods=None): - """Create a fake volume type. - - :param Dictionary attrs: - A dictionary with all attributes - :param Dictionary methods: - A dictionary with all methods - :return: - A FakeResource object with id, name, description, etc. - """ - attrs = attrs or {} - methods = methods or {} - - # Set default attributes. - volume_type_info = { - "id": 'type-id-' + uuid.uuid4().hex, - "name": 'type-name-' + uuid.uuid4().hex, - "description": 'type-description-' + uuid.uuid4().hex, - "extra_specs": {"foo": "bar"}, - "is_public": True, - } - - # Overwrite default attributes. - volume_type_info.update(attrs) - - volume_type = fakes.FakeResource( - info=copy.deepcopy(volume_type_info), - methods=methods, - loaded=True) - return volume_type - - @staticmethod - def create_volume_types(attrs=None, count=2): - """Create multiple fake types. - - :param Dictionary attrs: - A dictionary with all attributes - :param int count: - The number of types to fake - :return: - A list of FakeResource objects faking the types - """ - volume_types = [] - for i in range(0, count): - volume_type = FakeVolumeType.create_one_volume_type(attrs) - volume_types.append(volume_type) - - return volume_types - - @staticmethod - def get_volume_types(volume_types=None, count=2): - """Get an iterable MagicMock object with a list of faked types. - - If types list is provided, then initialize the Mock object with the - list. Otherwise create one. - - :param List volume_types: - A list of FakeResource objects faking types - :param Integer count: - The number of types to be faked - :return - An iterable Mock object with side_effect set to a list of faked - types - """ - if volume_types is None: - volume_types = FakeVolumeType.create_volume_types(count) - - return mock.Mock(side_effect=volume_types) - - @staticmethod - def create_one_encryption_volume_type(attrs=None): - """Create a fake encryption volume type. - - :param Dictionary attrs: - A dictionary with all attributes - :return: - A FakeResource object with volume_type_id etc. - """ - attrs = attrs or {} - - # Set default attributes. - encryption_info = { - "volume_type_id": 'type-id-' + uuid.uuid4().hex, - 'provider': 'LuksEncryptor', - 'cipher': None, - 'key_size': None, - 'control_location': 'front-end', - } - - # Overwrite default attributes. - encryption_info.update(attrs) - - encryption_type = fakes.FakeResource( - info=copy.deepcopy(encryption_info), - loaded=True) - return encryption_type - - -class FakeSnapshot(object): - """Fake one or more snapshot.""" - - @staticmethod - def create_one_snapshot(attrs=None): - """Create a fake snapshot. - - :param Dictionary attrs: - A dictionary with all attributes - :return: - A FakeResource object with id, name, description, etc. - """ - attrs = attrs or {} - - # Set default attributes. - snapshot_info = { - "id": 'snapshot-id-' + uuid.uuid4().hex, - "display_name": 'snapshot-name-' + uuid.uuid4().hex, - "display_description": 'snapshot-description-' + uuid.uuid4().hex, - "size": 10, - "status": "available", - "metadata": {"foo": "bar"}, - "created_at": "2015-06-03T18:49:19.000000", - "volume_id": 'vloume-id-' + uuid.uuid4().hex, - } - - # Overwrite default attributes. - snapshot_info.update(attrs) - - snapshot_method = {'update': None} - - snapshot = fakes.FakeResource( - info=copy.deepcopy(snapshot_info), - methods=copy.deepcopy(snapshot_method), - loaded=True) - return snapshot - - @staticmethod - def create_snapshots(attrs=None, count=2): - """Create multiple fake snapshots. - - :param Dictionary attrs: - A dictionary with all attributes - :param int count: - The number of snapshots to fake - :return: - A list of FakeResource objects faking the snapshots - """ - snapshots = [] - for i in range(0, count): - snapshot = FakeSnapshot.create_one_snapshot(attrs) - snapshots.append(snapshot) - - return snapshots - - @staticmethod - def get_snapshots(snapshots=None, count=2): - """Get an iterable MagicMock object with a list of faked snapshots. - - If snapshots list is provided, then initialize the Mock object with the - list. Otherwise create one. - - :param List volumes: - A list of FakeResource objects faking snapshots - :param Integer count: - The number of snapshots to be faked - :return - An iterable Mock object with side_effect set to a list of faked - snapshots - """ - if snapshots is None: - snapshots = FakeSnapshot.create_snapshots(count) - - return mock.Mock(side_effect=snapshots) - - -class FakeBackup(object): - """Fake one or more backup.""" - - @staticmethod - def create_one_backup(attrs=None): - """Create a fake backup. - - :param Dictionary attrs: - A dictionary with all attributes - :return: - A FakeResource object with id, name, volume_id, etc. - """ - attrs = attrs or {} - - # Set default attributes. - backup_info = { - "id": 'backup-id-' + uuid.uuid4().hex, - "name": 'backup-name-' + uuid.uuid4().hex, - "volume_id": 'volume-id-' + uuid.uuid4().hex, - "snapshot_id": 'snapshot-id' + uuid.uuid4().hex, - "description": 'description-' + uuid.uuid4().hex, - "object_count": None, - "container": 'container-' + uuid.uuid4().hex, - "size": random.randint(1, 20), - "status": "error", - "availability_zone": 'zone' + uuid.uuid4().hex, - "links": 'links-' + uuid.uuid4().hex, - } - - # Overwrite default attributes. - backup_info.update(attrs) - - backup = fakes.FakeResource( - info=copy.deepcopy(backup_info), - loaded=True) - return backup - - @staticmethod - def create_backups(attrs=None, count=2): - """Create multiple fake backups. - - :param Dictionary attrs: - A dictionary with all attributes - :param int count: - The number of backups to fake - :return: - A list of FakeResource objects faking the backups - """ - backups = [] - for i in range(0, count): - backup = FakeBackup.create_one_backup(attrs) - backups.append(backup) - - return backups - - @staticmethod - def get_backups(backups=None, count=2): - """Get an iterable MagicMock object with a list of faked backups. - - If backups list is provided, then initialize the Mock object with the - list. Otherwise create one. - - :param List volumes: - A list of FakeResource objects faking backups - :param Integer count: - The number of backups to be faked - :return - An iterable Mock object with side_effect set to a list of faked - backups - """ - if backups is None: - backups = FakeBackup.create_backups(count) - - return mock.Mock(side_effect=backups) + }, + ], + 'created_at': 'time-' + uuid.uuid4().hex, + } + + # Overwrite default attributes if there are some attributes set + volume_info.update(attrs) + + volume = fakes.FakeResource(None, volume_info, loaded=True) + return volume + + +def create_volumes(attrs=None, count=2): + """Create multiple fake volumes. + + :param Dictionary attrs: + A dictionary with all attributes of volume + :param Integer count: + The number of volumes to be faked + :return: + A list of FakeResource objects + """ + volumes = [] + for n in range(0, count): + volumes.append(create_one_volume(attrs)) + + return volumes + + +def get_volumes(volumes=None, count=2): + """Get an iterable MagicMock object with a list of faked volumes. + + If volumes list is provided, then initialize the Mock object with the + list. Otherwise create one. + + :param List volumes: + A list of FakeResource objects faking volumes + :param Integer count: + The number of volumes to be faked + :return + An iterable Mock object with side_effect set to a list of faked + volumes + """ + if volumes is None: + volumes = create_volumes(count) + + return mock.Mock(side_effect=volumes) + + +def create_one_volume_type(attrs=None, methods=None): + """Create a fake volume type. + + :param Dictionary attrs: + A dictionary with all attributes + :param Dictionary methods: + A dictionary with all methods + :return: + A FakeResource object with id, name, description, etc. + """ + attrs = attrs or {} + methods = methods or {} + + # Set default attributes. + volume_type_info = { + "id": 'type-id-' + uuid.uuid4().hex, + "name": 'type-name-' + uuid.uuid4().hex, + "description": 'type-description-' + uuid.uuid4().hex, + "extra_specs": {"foo": "bar"}, + "is_public": True, + } + + # Overwrite default attributes. + volume_type_info.update(attrs) + + volume_type = fakes.FakeResource( + info=copy.deepcopy(volume_type_info), methods=methods, loaded=True + ) + return volume_type + + +def create_volume_types(attrs=None, count=2): + """Create multiple fake types. + + :param Dictionary attrs: + A dictionary with all attributes + :param int count: + The number of types to fake + :return: + A list of FakeResource objects faking the types + """ + volume_types = [] + for i in range(0, count): + volume_type = create_one_volume_type(attrs) + volume_types.append(volume_type) + + return volume_types + + +def get_volume_types(volume_types=None, count=2): + """Get an iterable MagicMock object with a list of faked types. + + If types list is provided, then initialize the Mock object with the + list. Otherwise create one. + + :param List volume_types: + A list of FakeResource objects faking types + :param Integer count: + The number of types to be faked + :return + An iterable Mock object with side_effect set to a list of faked + types + """ + if volume_types is None: + volume_types = create_volume_types(count) + + return mock.Mock(side_effect=volume_types) + + +def create_one_encryption_volume_type(attrs=None): + """Create a fake encryption volume type. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with volume_type_id etc. + """ + attrs = attrs or {} + + # Set default attributes. + encryption_info = { + "volume_type_id": 'type-id-' + uuid.uuid4().hex, + 'provider': 'LuksEncryptor', + 'cipher': None, + 'key_size': None, + 'control_location': 'front-end', + } + + # Overwrite default attributes. + encryption_info.update(attrs) + + encryption_type = fakes.FakeResource( + info=copy.deepcopy(encryption_info), loaded=True + ) + return encryption_type + + +def create_one_snapshot(attrs=None): + """Create a fake snapshot. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with id, name, description, etc. + """ + attrs = attrs or {} + + # Set default attributes. + snapshot_info = { + "id": 'snapshot-id-' + uuid.uuid4().hex, + "display_name": 'snapshot-name-' + uuid.uuid4().hex, + "display_description": 'snapshot-description-' + uuid.uuid4().hex, + "size": 10, + "status": "available", + "metadata": {"foo": "bar"}, + "created_at": "2015-06-03T18:49:19.000000", + "volume_id": 'vloume-id-' + uuid.uuid4().hex, + } + + # Overwrite default attributes. + snapshot_info.update(attrs) + + snapshot_method = {'update': None} + + snapshot = fakes.FakeResource( + info=copy.deepcopy(snapshot_info), + methods=copy.deepcopy(snapshot_method), + loaded=True, + ) + return snapshot + + +def create_snapshots(attrs=None, count=2): + """Create multiple fake snapshots. + + :param Dictionary attrs: + A dictionary with all attributes + :param int count: + The number of snapshots to fake + :return: + A list of FakeResource objects faking the snapshots + """ + snapshots = [] + for i in range(0, count): + snapshot = create_one_snapshot(attrs) + snapshots.append(snapshot) + + return snapshots + + +def get_snapshots(snapshots=None, count=2): + """Get an iterable MagicMock object with a list of faked snapshots. + + If snapshots list is provided, then initialize the Mock object with the + list. Otherwise create one. + + :param List volumes: + A list of FakeResource objects faking snapshots + :param Integer count: + The number of snapshots to be faked + :return + An iterable Mock object with side_effect set to a list of faked + snapshots + """ + if snapshots is None: + snapshots = create_snapshots(count) + + return mock.Mock(side_effect=snapshots) + + +def create_one_backup(attrs=None): + """Create a fake backup. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with id, name, volume_id, etc. + """ + attrs = attrs or {} + + # Set default attributes. + backup_info = { + "id": 'backup-id-' + uuid.uuid4().hex, + "name": 'backup-name-' + uuid.uuid4().hex, + "volume_id": 'volume-id-' + uuid.uuid4().hex, + "snapshot_id": 'snapshot-id' + uuid.uuid4().hex, + "description": 'description-' + uuid.uuid4().hex, + "object_count": None, + "container": 'container-' + uuid.uuid4().hex, + "size": random.randint(1, 20), + "status": "error", + "availability_zone": 'zone' + uuid.uuid4().hex, + "links": 'links-' + uuid.uuid4().hex, + } + + # Overwrite default attributes. + backup_info.update(attrs) + + backup = fakes.FakeResource(info=copy.deepcopy(backup_info), loaded=True) + return backup + + +def create_backups(attrs=None, count=2): + """Create multiple fake backups. + + :param Dictionary attrs: + A dictionary with all attributes + :param int count: + The number of backups to fake + :return: + A list of FakeResource objects faking the backups + """ + backups = [] + for i in range(0, count): + backup = create_one_backup(attrs) + backups.append(backup) + + return backups + + +def get_backups(backups=None, count=2): + """Get an iterable MagicMock object with a list of faked backups. + + If backups list is provided, then initialize the Mock object with the + list. Otherwise create one. + + :param List volumes: + A list of FakeResource objects faking backups + :param Integer count: + The number of backups to be faked + :return + An iterable Mock object with side_effect set to a list of faked + backups + """ + if backups is None: + backups = create_backups(count) + + return mock.Mock(side_effect=backups) diff --git a/openstackclient/tests/unit/volume/v1/test_qos_specs.py b/openstackclient/tests/unit/volume/v1/test_qos_specs.py index d66a8558..f5b35143 100644 --- a/openstackclient/tests/unit/volume/v1/test_qos_specs.py +++ b/openstackclient/tests/unit/volume/v1/test_qos_specs.py @@ -28,7 +28,7 @@ from openstackclient.volume.v1 import qos_specs class TestQos(volume_fakes.TestVolumev1): def setUp(self): - super(TestQos, self).setUp() + super().setUp() self.qos_mock = self.app.client_manager.volume.qos_specs self.qos_mock.reset_mock() @@ -39,11 +39,11 @@ class TestQos(volume_fakes.TestVolumev1): class TestQosAssociate(TestQos): - volume_type = volume_fakes.FakeVolumeType.create_one_volume_type() - qos_spec = volume_fakes.FakeQos.create_one_qos() + volume_type = volume_fakes.create_one_volume_type() + qos_spec = volume_fakes.create_one_qos() def setUp(self): - super(TestQosAssociate, self).setUp() + super().setUp() self.qos_mock.get.return_value = self.qos_spec self.types_mock.get.return_value = self.volume_type @@ -80,8 +80,8 @@ class TestQosCreate(TestQos): ) def setUp(self): - super(TestQosCreate, self).setUp() - self.new_qos_spec = volume_fakes.FakeQos.create_one_qos() + super().setUp() + self.new_qos_spec = volume_fakes.create_one_qos() self.datalist = ( self.new_qos_spec.consumer, self.new_qos_spec.id, @@ -160,13 +160,13 @@ class TestQosCreate(TestQos): class TestQosDelete(TestQos): - qos_specs = volume_fakes.FakeQos.create_qoses(count=2) + qos_specs = volume_fakes.create_qoses(count=2) def setUp(self): - super(TestQosDelete, self).setUp() + super().setUp() self.qos_mock.get = ( - volume_fakes.FakeQos.get_qoses(self.qos_specs)) + volume_fakes.get_qoses(self.qos_specs)) # Get the command object to test self.cmd = qos_specs.DeleteQos(self.app, None) @@ -263,11 +263,11 @@ class TestQosDelete(TestQos): class TestQosDisassociate(TestQos): - volume_type = volume_fakes.FakeVolumeType.create_one_volume_type() - qos_spec = volume_fakes.FakeQos.create_one_qos() + volume_type = volume_fakes.create_one_volume_type() + qos_spec = volume_fakes.create_one_qos() def setUp(self): - super(TestQosDisassociate, self).setUp() + super().setUp() self.qos_mock.get.return_value = self.qos_spec self.types_mock.get.return_value = self.volume_type @@ -311,8 +311,8 @@ class TestQosDisassociate(TestQos): class TestQosList(TestQos): - qos_specs = volume_fakes.FakeQos.create_qoses(count=2) - qos_association = volume_fakes.FakeQos.create_one_qos_association() + qos_specs = volume_fakes.create_qoses(count=2) + qos_association = volume_fakes.create_one_qos_association() columns = ( 'ID', @@ -332,7 +332,7 @@ class TestQosList(TestQos): )) def setUp(self): - super(TestQosList, self).setUp() + super().setUp() self.qos_mock.list.return_value = self.qos_specs self.qos_mock.get_associations.return_value = [self.qos_association] @@ -382,10 +382,10 @@ class TestQosList(TestQos): class TestQosSet(TestQos): - qos_spec = volume_fakes.FakeQos.create_one_qos() + qos_spec = volume_fakes.create_one_qos() def setUp(self): - super(TestQosSet, self).setUp() + super().setUp() self.qos_mock.get.return_value = self.qos_spec # Get the command object to test @@ -414,11 +414,11 @@ class TestQosSet(TestQos): class TestQosShow(TestQos): - qos_spec = volume_fakes.FakeQos.create_one_qos() - qos_association = volume_fakes.FakeQos.create_one_qos_association() + qos_spec = volume_fakes.create_one_qos() + qos_association = volume_fakes.create_one_qos_association() def setUp(self): - super(TestQosShow, self).setUp() + super().setUp() self.qos_mock.get.return_value = self.qos_spec self.qos_mock.get_associations.return_value = [self.qos_association] # Get the command object to test @@ -459,10 +459,10 @@ class TestQosShow(TestQos): class TestQosUnset(TestQos): - qos_spec = volume_fakes.FakeQos.create_one_qos() + qos_spec = volume_fakes.create_one_qos() def setUp(self): - super(TestQosUnset, self).setUp() + super().setUp() self.qos_mock.get.return_value = self.qos_spec # Get the command object to test diff --git a/openstackclient/tests/unit/volume/v1/test_service.py b/openstackclient/tests/unit/volume/v1/test_service.py index 82d21bfc..a199c913 100644 --- a/openstackclient/tests/unit/volume/v1/test_service.py +++ b/openstackclient/tests/unit/volume/v1/test_service.py @@ -14,14 +14,14 @@ from osc_lib import exceptions -from openstackclient.tests.unit.volume.v1 import fakes as service_fakes +from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes from openstackclient.volume.v1 import service -class TestService(service_fakes.TestVolumev1): +class TestService(volume_fakes.TestVolumev1): def setUp(self): - super(TestService, self).setUp() + super().setUp() # Get a shortcut to the ServiceManager Mock self.service_mock = self.app.client_manager.volume.services @@ -31,10 +31,10 @@ class TestService(service_fakes.TestVolumev1): class TestServiceList(TestService): # The service to be listed - services = service_fakes.FakeService.create_one_service() + services = volume_fakes.create_one_service() def setUp(self): - super(TestServiceList, self).setUp() + super().setUp() self.service_mock.list.return_value = [self.services] @@ -144,10 +144,10 @@ class TestServiceList(TestService): class TestServiceSet(TestService): - service = service_fakes.FakeService.create_one_service() + service = volume_fakes.create_one_service() def setUp(self): - super(TestServiceSet, self).setUp() + super().setUp() self.service_mock.enable.return_value = self.service self.service_mock.disable.return_value = self.service diff --git a/openstackclient/tests/unit/volume/v1/test_transfer_request.py b/openstackclient/tests/unit/volume/v1/test_transfer_request.py index 333bf526..97700fbb 100644 --- a/openstackclient/tests/unit/volume/v1/test_transfer_request.py +++ b/openstackclient/tests/unit/volume/v1/test_transfer_request.py @@ -18,14 +18,14 @@ from unittest.mock import call from osc_lib import exceptions from osc_lib import utils -from openstackclient.tests.unit.volume.v1 import fakes as transfer_fakes +from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes from openstackclient.volume.v1 import volume_transfer_request -class TestTransfer(transfer_fakes.TestVolumev1): +class TestTransfer(volume_fakes.TestVolumev1): def setUp(self): - super(TestTransfer, self).setUp() + super().setUp() # Get a shortcut to the TransferManager Mock self.transfer_mock = self.app.client_manager.volume.transfers @@ -45,10 +45,9 @@ class TestTransferAccept(TestTransfer): ) def setUp(self): - super(TestTransferAccept, self).setUp() + super().setUp() - self.volume_transfer = ( - transfer_fakes.FakeTransfer.create_one_transfer()) + self.volume_transfer = volume_fakes.create_one_transfer() self.data = ( self.volume_transfer.id, self.volume_transfer.name, @@ -103,7 +102,7 @@ class TestTransferAccept(TestTransfer): class TestTransferCreate(TestTransfer): - volume = transfer_fakes.FakeVolume.create_one_volume() + volume = volume_fakes.create_one_volume() columns = ( 'auth_key', @@ -114,12 +113,14 @@ class TestTransferCreate(TestTransfer): ) def setUp(self): - super(TestTransferCreate, self).setUp() - - self.volume_transfer = transfer_fakes.FakeTransfer.create_one_transfer( - attrs={'volume_id': self.volume.id, - 'auth_key': 'key', - 'created_at': 'time'} + super().setUp() + + self.volume_transfer = volume_fakes.create_one_transfer( + attrs={ + 'volume_id': self.volume.id, + 'auth_key': 'key', + 'created_at': 'time', + }, ) self.data = ( self.volume_transfer.auth_key, @@ -173,13 +174,14 @@ class TestTransferCreate(TestTransfer): class TestTransferDelete(TestTransfer): - volume_transfers = transfer_fakes.FakeTransfer.create_transfers(count=2) + volume_transfers = volume_fakes.create_transfers(count=2) def setUp(self): - super(TestTransferDelete, self).setUp() + super().setUp() - self.transfer_mock.get = ( - transfer_fakes.FakeTransfer.get_transfers(self.volume_transfers)) + self.transfer_mock.get = volume_fakes.get_transfers( + self.volume_transfers, + ) self.transfer_mock.delete.return_value = None # Get the command object to mock @@ -252,10 +254,10 @@ class TestTransferDelete(TestTransfer): class TestTransferList(TestTransfer): # The Transfers to be listed - volume_transfers = transfer_fakes.FakeTransfer.create_one_transfer() + volume_transfers = volume_fakes.create_one_transfer() def setUp(self): - super(TestTransferList, self).setUp() + super().setUp() self.transfer_mock.list.return_value = [self.volume_transfers] @@ -346,11 +348,10 @@ class TestTransferShow(TestTransfer): ) def setUp(self): - super(TestTransferShow, self).setUp() + super().setUp() - self.volume_transfer = ( - transfer_fakes.FakeTransfer.create_one_transfer( - attrs={'created_at': 'time'}) + self.volume_transfer = volume_fakes.create_one_transfer( + attrs={'created_at': 'time'} ) self.data = ( self.volume_transfer.created_at, diff --git a/openstackclient/tests/unit/volume/v1/test_type.py b/openstackclient/tests/unit/volume/v1/test_type.py index ca74c3e6..c8788249 100644 --- a/openstackclient/tests/unit/volume/v1/test_type.py +++ b/openstackclient/tests/unit/volume/v1/test_type.py @@ -27,7 +27,7 @@ from openstackclient.volume.v1 import volume_type class TestType(volume_fakes.TestVolumev1): def setUp(self): - super(TestType, self).setUp() + super().setUp() self.types_mock = self.app.client_manager.volume.volume_types self.types_mock.reset_mock() @@ -47,11 +47,11 @@ class TestTypeCreate(TestType): ) def setUp(self): - super(TestTypeCreate, self).setUp() + super().setUp() - self.new_volume_type = \ - volume_fakes.FakeVolumeType.create_one_volume_type( - methods={'set_keys': {'myprop': 'myvalue'}}) + self.new_volume_type = volume_fakes.create_one_volume_type( + methods={'set_keys': {'myprop': 'myvalue'}}, + ) self.data = ( self.new_volume_type.description, self.new_volume_type.id, @@ -87,12 +87,12 @@ class TestTypeCreate(TestType): 'key_size': '128', 'control_location': 'front-end', } - encryption_type = \ - volume_fakes.FakeVolumeType.create_one_encryption_volume_type( - attrs=encryption_info) - self.new_volume_type = \ - volume_fakes.FakeVolumeType.create_one_volume_type( - attrs={'encryption': encryption_info}) + encryption_type = volume_fakes.create_one_encryption_volume_type( + attrs=encryption_info, + ) + self.new_volume_type = volume_fakes.create_one_volume_type( + attrs={'encryption': encryption_info}, + ) self.types_mock.create.return_value = self.new_volume_type self.encryption_types_mock.create.return_value = encryption_type encryption_columns = ( @@ -145,13 +145,12 @@ class TestTypeCreate(TestType): class TestTypeDelete(TestType): - volume_types = volume_fakes.FakeVolumeType.create_volume_types(count=2) + volume_types = volume_fakes.create_volume_types(count=2) def setUp(self): - super(TestTypeDelete, self).setUp() + super().setUp() - self.types_mock.get = volume_fakes.FakeVolumeType.get_volume_types( - self.volume_types) + self.types_mock.get = volume_fakes.get_volume_types(self.volume_types) self.types_mock.delete.return_value = None # Get the command object to mock @@ -221,7 +220,7 @@ class TestTypeDelete(TestType): class TestTypeList(TestType): - volume_types = volume_fakes.FakeVolumeType.create_volume_types() + volume_types = volume_fakes.create_volume_types() columns = [ "ID", @@ -252,7 +251,7 @@ class TestTypeList(TestType): )) def setUp(self): - super(TestTypeList, self).setUp() + super().setUp() self.types_mock.list.return_value = self.volume_types self.encryption_types_mock.create.return_value = None @@ -288,9 +287,9 @@ class TestTypeList(TestType): self.assertCountEqual(self.data_long, list(data)) def test_type_list_with_encryption(self): - encryption_type = \ - volume_fakes.FakeVolumeType.create_one_encryption_volume_type( - attrs={'volume_type_id': self.volume_types[0].id}) + encryption_type = volume_fakes.create_one_encryption_volume_type( + attrs={'volume_type_id': self.volume_types[0].id}, + ) encryption_info = { 'provider': 'LuksEncryptor', 'cipher': None, @@ -335,11 +334,12 @@ class TestTypeList(TestType): class TestTypeSet(TestType): - volume_type = volume_fakes.FakeVolumeType.create_one_volume_type( - methods={'set_keys': None}) + volume_type = volume_fakes.create_one_volume_type( + methods={'set_keys': None}, + ) def setUp(self): - super(TestTypeSet, self).setUp() + super().setUp() self.types_mock.get.return_value = self.volume_type @@ -441,9 +441,9 @@ class TestTypeShow(TestType): ) def setUp(self): - super(TestTypeShow, self).setUp() + super().setUp() - self.volume_type = volume_fakes.FakeVolumeType.create_one_volume_type() + self.volume_type = volume_fakes.create_one_volume_type() self.data = ( self.volume_type.description, self.volume_type.id, @@ -474,16 +474,16 @@ class TestTypeShow(TestType): self.assertCountEqual(self.data, data) def test_type_show_with_encryption(self): - encryption_type = \ - volume_fakes.FakeVolumeType.create_one_encryption_volume_type() + encryption_type = volume_fakes.create_one_encryption_volume_type() encryption_info = { 'provider': 'LuksEncryptor', 'cipher': None, 'key_size': None, 'control_location': 'front-end', } - self.volume_type = volume_fakes.FakeVolumeType.create_one_volume_type( - attrs={'encryption': encryption_info}) + self.volume_type = volume_fakes.create_one_volume_type( + attrs={'encryption': encryption_info}, + ) self.types_mock.get.return_value = self.volume_type self.encryption_types_mock.get.return_value = encryption_type encryption_columns = ( @@ -521,11 +521,12 @@ class TestTypeShow(TestType): class TestTypeUnset(TestType): - volume_type = volume_fakes.FakeVolumeType.create_one_volume_type( - methods={'unset_keys': None}) + volume_type = volume_fakes.create_one_volume_type( + methods={'unset_keys': None}, + ) def setUp(self): - super(TestTypeUnset, self).setUp() + super().setUp() self.types_mock.get.return_value = self.volume_type @@ -599,7 +600,7 @@ class TestTypeUnset(TestType): class TestColumns(TestType): def test_encryption_info_column_with_info(self): - fake_volume_type = volume_fakes.FakeVolumeType.create_one_volume_type() + fake_volume_type = volume_fakes.create_one_volume_type() type_id = fake_volume_type.id encryption_info = { @@ -615,7 +616,7 @@ class TestColumns(TestType): self.assertEqual(encryption_info, col.machine_readable()) def test_encryption_info_column_without_info(self): - fake_volume_type = volume_fakes.FakeVolumeType.create_one_volume_type() + fake_volume_type = volume_fakes.create_one_volume_type() type_id = fake_volume_type.id col = volume_type.EncryptionInfoColumn(type_id, {}) diff --git a/openstackclient/tests/unit/volume/v1/test_volume.py b/openstackclient/tests/unit/volume/v1/test_volume.py index 584eca2a..9f16b398 100644 --- a/openstackclient/tests/unit/volume/v1/test_volume.py +++ b/openstackclient/tests/unit/volume/v1/test_volume.py @@ -31,7 +31,7 @@ from openstackclient.volume.v1 import volume class TestVolume(volume_fakes.TestVolumev1): def setUp(self): - super(TestVolume, self).setUp() + super().setUp() # Get a shortcut to the VolumeManager Mock self.volumes_mock = self.app.client_manager.volume.volumes @@ -50,11 +50,9 @@ class TestVolume(volume_fakes.TestVolumev1): self.images_mock.reset_mock() def setup_volumes_mock(self, count): - volumes = volume_fakes.FakeVolume.create_volumes(count=count) + volumes = volume_fakes.create_volumes(count=count) - self.volumes_mock.get = volume_fakes.FakeVolume.get_volumes( - volumes, - 0) + self.volumes_mock.get = volume_fakes.get_volumes(volumes, 0) return volumes @@ -79,8 +77,8 @@ class TestVolumeCreate(TestVolume): ) def setUp(self): - super(TestVolumeCreate, self).setUp() - self.new_volume = volume_fakes.FakeVolume.create_one_volume() + super().setUp() + self.new_volume = volume_fakes.create_one_volume() self.datalist = ( self.new_volume.attachments, self.new_volume.availability_zone, @@ -635,7 +633,7 @@ class TestVolumeCreate(TestVolume): class TestVolumeDelete(TestVolume): def setUp(self): - super(TestVolumeDelete, self).setUp() + super().setUp() self.volumes_mock.delete.return_value = None @@ -725,7 +723,7 @@ class TestVolumeDelete(TestVolume): class TestVolumeList(TestVolume): - _volume = volume_fakes.FakeVolume.create_one_volume() + _volume = volume_fakes.create_one_volume() columns = ( 'ID', 'Name', @@ -744,7 +742,7 @@ class TestVolumeList(TestVolume): ) def setUp(self): - super(TestVolumeList, self).setUp() + super().setUp() self.volumes_mock.list.return_value = [self._volume] @@ -921,10 +919,10 @@ class TestVolumeList(TestVolume): class TestVolumeMigrate(TestVolume): - _volume = volume_fakes.FakeVolume.create_one_volume() + _volume = volume_fakes.create_one_volume() def setUp(self): - super(TestVolumeMigrate, self).setUp() + super().setUp() self.volumes_mock.get.return_value = self._volume self.volumes_mock.migrate_volume.return_value = None @@ -983,10 +981,10 @@ class TestVolumeMigrate(TestVolume): class TestVolumeSet(TestVolume): - _volume = volume_fakes.FakeVolume.create_one_volume() + _volume = volume_fakes.create_one_volume() def setUp(self): - super(TestVolumeSet, self).setUp() + super().setUp() self.volumes_mock.get.return_value = self._volume @@ -1243,8 +1241,8 @@ class TestVolumeShow(TestVolume): ) def setUp(self): - super(TestVolumeShow, self).setUp() - self._volume = volume_fakes.FakeVolume.create_one_volume() + super().setUp() + self._volume = volume_fakes.create_one_volume() self.datalist = ( self._volume.attachments, self._volume.availability_zone, @@ -1300,10 +1298,10 @@ class TestVolumeShow(TestVolume): class TestVolumeUnset(TestVolume): - _volume = volume_fakes.FakeVolume.create_one_volume() + _volume = volume_fakes.create_one_volume() def setUp(self): - super(TestVolumeUnset, self).setUp() + super().setUp() self.volumes_mock.get.return_value = self._volume @@ -1346,7 +1344,7 @@ class TestVolumeUnset(TestVolume): class TestColumns(TestVolume): def test_attachments_column_without_server_cache(self): - _volume = volume_fakes.FakeVolume.create_one_volume() + _volume = volume_fakes.create_one_volume() server_id = _volume.attachments[0]['server_id'] device = _volume.attachments[0]['device'] @@ -1356,7 +1354,7 @@ class TestColumns(TestVolume): self.assertEqual(_volume.attachments, col.machine_readable()) def test_attachments_column_with_server_cache(self): - _volume = volume_fakes.FakeVolume.create_one_volume() + _volume = volume_fakes.create_one_volume() server_id = _volume.attachments[0]['server_id'] device = _volume.attachments[0]['device'] diff --git a/openstackclient/tests/unit/volume/v1/test_volume_backup.py b/openstackclient/tests/unit/volume/v1/test_volume_backup.py index 2f568929..b705b4b9 100644 --- a/openstackclient/tests/unit/volume/v1/test_volume_backup.py +++ b/openstackclient/tests/unit/volume/v1/test_volume_backup.py @@ -25,7 +25,7 @@ from openstackclient.volume.v1 import volume_backup class TestBackup(volume_fakes.TestVolumev1): def setUp(self): - super(TestBackup, self).setUp() + super().setUp() self.backups_mock = self.app.client_manager.volume.backups self.backups_mock.reset_mock() @@ -39,7 +39,7 @@ class TestBackup(volume_fakes.TestVolumev1): class TestBackupCreate(TestBackup): - volume = volume_fakes.FakeVolume.create_one_volume() + volume = volume_fakes.create_one_volume() columns = ( 'availability_zone', @@ -55,9 +55,10 @@ class TestBackupCreate(TestBackup): ) def setUp(self): - super(TestBackupCreate, self).setUp() - self.new_backup = volume_fakes.FakeBackup.create_one_backup( - attrs={'volume_id': self.volume.id}) + super().setUp() + self.new_backup = volume_fakes.create_one_backup( + attrs={'volume_id': self.volume.id}, + ) self.data = ( self.new_backup.availability_zone, self.new_backup.container, @@ -129,13 +130,12 @@ class TestBackupCreate(TestBackup): class TestBackupDelete(TestBackup): - backups = volume_fakes.FakeBackup.create_backups(count=2) + backups = volume_fakes.create_backups(count=2) def setUp(self): - super(TestBackupDelete, self).setUp() + super().setUp() - self.backups_mock.get = ( - volume_fakes.FakeBackup.get_backups(self.backups)) + self.backups_mock.get = volume_fakes.get_backups(self.backups) self.backups_mock.delete.return_value = None # Get the command object to mock @@ -205,9 +205,11 @@ class TestBackupDelete(TestBackup): class TestBackupList(TestBackup): - volume = volume_fakes.FakeVolume.create_one_volume() - backups = volume_fakes.FakeBackup.create_backups( - attrs={'volume_id': volume.display_name}, count=3) + volume = volume_fakes.create_one_volume() + backups = volume_fakes.create_backups( + attrs={'volume_id': volume.display_name}, + count=3, + ) columns = [ 'ID', @@ -245,7 +247,7 @@ class TestBackupList(TestBackup): )) def setUp(self): - super(TestBackupList, self).setUp() + super().setUp() self.volumes_mock.list.return_value = [self.volume] self.backups_mock.list.return_value = self.backups @@ -314,9 +316,10 @@ class TestBackupList(TestBackup): class TestBackupRestore(TestBackup): - volume = volume_fakes.FakeVolume.create_one_volume() - backup = volume_fakes.FakeBackup.create_one_backup( - attrs={'volume_id': volume.id}) + volume = volume_fakes.create_one_volume() + backup = volume_fakes.create_one_backup( + attrs={'volume_id': volume.id}, + ) def setUp(self): super().setUp() @@ -324,7 +327,7 @@ class TestBackupRestore(TestBackup): self.backups_mock.get.return_value = self.backup self.volumes_mock.get.return_value = self.volume self.restores_mock.restore.return_value = ( - volume_fakes.FakeVolume.create_one_volume( + volume_fakes.create_one_volume( {'id': self.volume['id']}, ) ) @@ -400,8 +403,8 @@ class TestBackupShow(TestBackup): ) def setUp(self): - super(TestBackupShow, self).setUp() - self.backup = volume_fakes.FakeBackup.create_one_backup() + super().setUp() + self.backup = volume_fakes.create_one_backup() self.data = ( self.backup.availability_zone, self.backup.container, |
