Merge "Add create_one_image_member() in FakeImage class and update test"
This commit is contained in:
commit
5b0f87ff1f
@ -49,13 +49,6 @@ IMAGE_SHOW = copy.copy(IMAGE)
|
||||
IMAGE_SHOW['tags'] = ''
|
||||
IMAGE_SHOW_data = tuple((IMAGE_SHOW[x] for x in sorted(IMAGE_SHOW)))
|
||||
|
||||
member_status = 'pending'
|
||||
MEMBER = {
|
||||
'member_id': identity_fakes.project_id,
|
||||
'image_id': image_id,
|
||||
'status': member_status,
|
||||
}
|
||||
|
||||
# Just enough v2 schema to do some testing
|
||||
IMAGE_schema = {
|
||||
"additionalProperties": {
|
||||
@ -288,3 +281,29 @@ class FakeImage(object):
|
||||
else:
|
||||
data_list.append(getattr(image, x))
|
||||
return tuple(data_list)
|
||||
|
||||
@staticmethod
|
||||
def create_one_image_member(attrs=None):
|
||||
"""Create a fake image member.
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attrbutes of image member
|
||||
:return:
|
||||
A FakeResource object with member_id, image_id and so on
|
||||
"""
|
||||
attrs = attrs or {}
|
||||
|
||||
# Set default attribute
|
||||
image_member_info = {
|
||||
'member_id': 'member-id-' + uuid.uuid4().hex,
|
||||
'image_id': 'image-id-' + uuid.uuid4().hex,
|
||||
'status': 'pending',
|
||||
}
|
||||
|
||||
# Overwrite default attributes if there are some attributes set
|
||||
image_member_info.update(attrs)
|
||||
|
||||
image_member = fakes.FakeModel(
|
||||
copy.deepcopy(image_member_info))
|
||||
|
||||
return image_member
|
||||
|
@ -347,6 +347,10 @@ class TestImageCreate(TestImage):
|
||||
class TestAddProjectToImage(TestImage):
|
||||
|
||||
_image = image_fakes.FakeImage.create_one_image()
|
||||
new_member = image_fakes.FakeImage.create_one_image_member(
|
||||
attrs={'image_id': _image.id,
|
||||
'member_id': identity_fakes.project_id}
|
||||
)
|
||||
|
||||
columns = (
|
||||
'image_id',
|
||||
@ -357,7 +361,7 @@ class TestAddProjectToImage(TestImage):
|
||||
datalist = (
|
||||
_image.id,
|
||||
identity_fakes.project_id,
|
||||
image_fakes.member_status
|
||||
new_member.status
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
@ -367,11 +371,7 @@ class TestAddProjectToImage(TestImage):
|
||||
self.images_mock.get.return_value = self._image
|
||||
|
||||
# Update the image_id in the MEMBER dict
|
||||
self.new_member = copy.deepcopy(image_fakes.MEMBER)
|
||||
self.new_member['image_id'] = self._image.id
|
||||
self.image_members_mock.create.return_value = fakes.FakeModel(
|
||||
self.new_member,
|
||||
)
|
||||
self.image_members_mock.create.return_value = self.new_member
|
||||
self.project_mock.get.return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(identity_fakes.PROJECT),
|
||||
|
Loading…
x
Reference in New Issue
Block a user