Add call to get specific image member
Fixes bug 1233806 Add GET call to get a specific image member. Makes it easier to check image member status DocImpact Change-Id: I63039bc15d2045fbceb71cae56225a9ee9eecd51
This commit is contained in:
parent
3021172d9f
commit
233290f4a6
@ -136,6 +136,29 @@ class ImageMembersController(object):
|
||||
except exception.Forbidden as e:
|
||||
raise webob.exc.HTTPForbidden(explanation=unicode(e))
|
||||
|
||||
def show(self, req, image_id, member_id):
|
||||
"""
|
||||
Returns the membership of the tenant wrt to the image_id specified.
|
||||
|
||||
:param req: the Request object coming from the wsgi layer
|
||||
:param image_id: The image identifier
|
||||
:retval The response body is a mapping of the following form::
|
||||
|
||||
{'member_id': <MEMBER>,
|
||||
'image_id': <IMAGE>,
|
||||
'status': <MEMBER_STATUS>
|
||||
'created_at': ..,
|
||||
'updated_at': ..}
|
||||
"""
|
||||
image_repo = self.gateway.get_repo(req.context)
|
||||
try:
|
||||
image = image_repo.get(image_id)
|
||||
member_repo = image.get_member_repo()
|
||||
member = member_repo.get(member_id)
|
||||
return member
|
||||
except (exception.NotFound, exception.Forbidden) as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=unicode(e))
|
||||
|
||||
@utils.mutating
|
||||
def delete(self, req, image_id, member_id):
|
||||
"""
|
||||
@ -231,6 +254,12 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
||||
response.unicode_body = unicode(body)
|
||||
response.content_type = 'application/json'
|
||||
|
||||
def show(self, response, image_member):
|
||||
image_member_view = self._format_image_member(image_member)
|
||||
body = json.dumps(image_member_view, ensure_ascii=False)
|
||||
response.unicode_body = unicode(body)
|
||||
response.content_type = 'application/json'
|
||||
|
||||
|
||||
_MEMBER_SCHEMA = {
|
||||
'member_id': {
|
||||
|
@ -95,6 +95,10 @@ class API(wsgi.Router):
|
||||
controller=image_members_resource,
|
||||
action='index',
|
||||
conditions={'method': ['GET']})
|
||||
mapper.connect('/images/{image_id}/members/{member_id}',
|
||||
controller=image_members_resource,
|
||||
action='show',
|
||||
conditions={'method': ['GET']})
|
||||
mapper.connect('/images/{image_id}/members/{member_id}',
|
||||
controller=image_members_resource,
|
||||
action='update',
|
||||
|
@ -1130,14 +1130,40 @@ class TestImageMembers(functional.FunctionalTest):
|
||||
body = json.loads(response.text)
|
||||
self.assertEqual(0, len(body['members']))
|
||||
|
||||
# Tenant 1, who is the owner cannot change status of image
|
||||
# Tenant 1, who is the owner cannot change status of image member
|
||||
path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'],
|
||||
TENANT3))
|
||||
body = json.dumps({'status': 'accepted'})
|
||||
response = requests.put(path, headers=get_header('tenant1'), data=body)
|
||||
self.assertEqual(403, response.status_code)
|
||||
|
||||
# Tenant 3 can change status of image
|
||||
# Tenant 1, who is the owner can get status of its own image member
|
||||
path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'],
|
||||
TENANT3))
|
||||
response = requests.get(path, headers=get_header('tenant1'))
|
||||
self.assertEqual(200, response.status_code)
|
||||
body = json.loads(response.text)
|
||||
self.assertEqual(body['status'], 'pending')
|
||||
self.assertEqual(body['image_id'], image_fixture[1]['id'])
|
||||
self.assertEqual(body['member_id'], TENANT3)
|
||||
|
||||
# Tenant 3, who is the member can get status of its own status
|
||||
path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'],
|
||||
TENANT3))
|
||||
response = requests.get(path, headers=get_header(TENANT3))
|
||||
self.assertEqual(200, response.status_code)
|
||||
body = json.loads(response.text)
|
||||
self.assertEqual(body['status'], 'pending')
|
||||
self.assertEqual(body['image_id'], image_fixture[1]['id'])
|
||||
self.assertEqual(body['member_id'], TENANT3)
|
||||
|
||||
# Tenant 2, who not the owner cannot get status of image member
|
||||
path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'],
|
||||
TENANT3))
|
||||
response = requests.get(path, headers=get_header('tenant2'))
|
||||
self.assertEqual(404, response.status_code)
|
||||
|
||||
# Tenant 3 can change status of image member
|
||||
path = self._url('/v2/images/%s/members/%s' % (image_fixture[1]['id'],
|
||||
TENANT3))
|
||||
body = json.dumps({'status': 'accepted'})
|
||||
|
@ -72,6 +72,7 @@ def _db_image_member_fixture(image_id, member_id, **kwargs):
|
||||
obj = {
|
||||
'image_id': image_id,
|
||||
'member': member_id,
|
||||
'status': 'pending',
|
||||
}
|
||||
obj.update(kwargs)
|
||||
return obj
|
||||
@ -188,6 +189,34 @@ class TestImageMembersController(test_utils.BaseTestCase):
|
||||
self.assertRaises(webob.exc.HTTPForbidden, self.controller.index,
|
||||
request, image_id=UUID2)
|
||||
|
||||
def test_show(self):
|
||||
request = unit_test_utils.get_fake_request(tenant=TENANT1)
|
||||
output = self.controller.show(request, UUID2, TENANT4)
|
||||
expected = self.image_members[0]
|
||||
self.assertEqual(output.image_id, expected['image_id'])
|
||||
self.assertEqual(output.member_id, expected['member'])
|
||||
self.assertEqual(output.status, expected['status'])
|
||||
|
||||
def test_show_by_member(self):
|
||||
request = unit_test_utils.get_fake_request(tenant=TENANT4)
|
||||
output = self.controller.show(request, UUID2, TENANT4)
|
||||
expected = self.image_members[0]
|
||||
self.assertEqual(output.image_id, expected['image_id'])
|
||||
self.assertEqual(output.member_id, expected['member'])
|
||||
self.assertEqual(output.status, expected['status'])
|
||||
|
||||
def test_show_forbidden(self):
|
||||
request = unit_test_utils.get_fake_request(tenant=TENANT2)
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
|
||||
request, UUID2, TENANT4)
|
||||
|
||||
def test_show_not_found(self):
|
||||
# one member should not be able to view status of another member
|
||||
# of the same image
|
||||
request = unit_test_utils.get_fake_request(tenant=TENANT2)
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
|
||||
request, UUID3, TENANT4)
|
||||
|
||||
def test_create(self):
|
||||
request = unit_test_utils.get_fake_request()
|
||||
image_id = UUID2
|
||||
@ -405,6 +434,24 @@ class TestImageMembersSerializer(test_utils.BaseTestCase):
|
||||
self.assertEqual(expected, actual)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
|
||||
def test_show(self):
|
||||
expected = {
|
||||
'image_id': UUID2,
|
||||
'member_id': TENANT1,
|
||||
'status': 'accepted',
|
||||
'created_at': ISOTIME,
|
||||
'updated_at': ISOTIME,
|
||||
'schema': '/v2/schemas/member',
|
||||
}
|
||||
request = webob.Request.blank('/v2/images/%s/members/%s'
|
||||
% (UUID2, TENANT1))
|
||||
response = webob.Response(request=request)
|
||||
result = self.fixtures[0]
|
||||
self.serializer.show(response, result)
|
||||
actual = json.loads(response.body)
|
||||
self.assertEqual(expected, actual)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
|
||||
def test_create(self):
|
||||
expected = {'image_id': UUID2,
|
||||
'member_id': TENANT1,
|
||||
|
Loading…
Reference in New Issue
Block a user