Skip to content

Commit dcc8256

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add FakeBackup class and updata backup unittest in volumeV2"
2 parents 5dfedd6 + 4956c35 commit dcc8256

2 files changed

Lines changed: 193 additions & 113 deletions

File tree

openstackclient/tests/volume/v2/fakes.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,57 @@ def create_availability_zones(attrs=None, count=2):
498498
availability_zones.append(availability_zone)
499499

500500
return availability_zones
501+
502+
503+
class FakeBackup(object):
504+
"""Fake one or more backup."""
505+
506+
@staticmethod
507+
def create_one_backup(attrs=None):
508+
"""Create a fake backup.
509+
510+
:param Dictionary attrs:
511+
A dictionary with all attributes
512+
:return:
513+
A FakeResource object with id, name, volume_id, etc.
514+
"""
515+
attrs = attrs or {}
516+
517+
# Set default attributes.
518+
backup_info = {
519+
"id": 'backup-id-' + uuid.uuid4().hex,
520+
"name": 'backup-name-' + uuid.uuid4().hex,
521+
"volume_id": 'volume-id-' + uuid.uuid4().hex,
522+
"description": 'description-' + uuid.uuid4().hex,
523+
"object_count": None,
524+
"container": 'container-' + uuid.uuid4().hex,
525+
"size": random.randint(1, 20),
526+
"status": "error",
527+
"availability_zone": 'zone' + uuid.uuid4().hex,
528+
}
529+
530+
# Overwrite default attributes.
531+
backup_info.update(attrs)
532+
533+
backup = fakes.FakeResource(
534+
info=copy.deepcopy(backup_info),
535+
loaded=True)
536+
return backup
537+
538+
@staticmethod
539+
def create_backups(attrs=None, count=2):
540+
"""Create multiple fake backups.
541+
542+
:param Dictionary attrs:
543+
A dictionary with all attributes
544+
:param int count:
545+
The number of backups to fake
546+
:return:
547+
A list of FakeResource objects faking the backups
548+
"""
549+
backups = []
550+
for i in range(0, count):
551+
backup = FakeBackup.create_one_backup(attrs)
552+
backups.append(backup)
553+
554+
return backups

0 commit comments

Comments
 (0)