Skip to content

Commit 6f60817

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Refactor image v1 unit tests with FakeImage class"
2 parents 2bbb482 + 407e164 commit 6f60817

2 files changed

Lines changed: 185 additions & 95 deletions

File tree

openstackclient/tests/unit/image/v1/fakes.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# under the License.
1414
#
1515

16+
import copy
1617
import mock
18+
import uuid
1719

1820
from openstackclient.tests.unit import fakes
1921
from openstackclient.tests.unit import utils
@@ -74,3 +76,45 @@ def setUp(self):
7476
endpoint=fakes.AUTH_URL,
7577
token=fakes.AUTH_TOKEN,
7678
)
79+
80+
81+
class FakeImage(object):
82+
"""Fake one or more images."""
83+
84+
@staticmethod
85+
def create_one_image(attrs=None):
86+
"""Create a fake image.
87+
88+
:param Dictionary attrs:
89+
A dictionary with all attrbutes of image
90+
:return:
91+
A FakeResource object with id, name, owner, protected,
92+
visibility and tags attrs
93+
"""
94+
attrs = attrs or {}
95+
96+
# Set default attribute
97+
image_info = {
98+
'id': str(uuid.uuid4()),
99+
'name': 'image-name' + uuid.uuid4().hex,
100+
'owner': 'image-owner' + uuid.uuid4().hex,
101+
'container_format': '',
102+
'disk_format': '',
103+
'min_disk': 0,
104+
'min_ram': 0,
105+
'is_public': True,
106+
'protected': False,
107+
'properties': {
108+
'Alpha': 'a',
109+
'Beta': 'b',
110+
'Gamma': 'g'},
111+
}
112+
113+
# Overwrite default attributes if there are some attributes set
114+
image_info.update(attrs)
115+
116+
image = fakes.FakeResource(
117+
info=copy.deepcopy(image_info),
118+
loaded=True)
119+
120+
return image

0 commit comments

Comments
 (0)