Add image access records schema for image resources
Implements blueprint api-v2-refactor-schemas Change-Id: Ic79d6661d44976057016e1a570674f47a962a3db
This commit is contained in:
parent
0a7473bb10
commit
2f3d054616
@ -37,7 +37,10 @@ class Controller(object):
|
|||||||
|
|
||||||
#TODO(bcwaldon): We have to filter on non-deleted members
|
#TODO(bcwaldon): We have to filter on non-deleted members
|
||||||
# manually. This should be done for us in the db api
|
# manually. This should be done for us in the db api
|
||||||
return filter(lambda m: not m['deleted'], members)
|
return {
|
||||||
|
'access_records': filter(lambda m: not m['deleted'], members),
|
||||||
|
'image_id': image_id,
|
||||||
|
}
|
||||||
|
|
||||||
def show(self, req, image_id, tenant_id):
|
def show(self, req, image_id, tenant_id):
|
||||||
members = self.db_api.image_member_find(req.context,
|
members = self.db_api.image_member_find(req.context,
|
||||||
@ -110,31 +113,28 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
|||||||
link = '%s/%s' % (link, tenant_id)
|
link = '%s/%s' % (link, tenant_id)
|
||||||
return link
|
return link
|
||||||
|
|
||||||
def _get_access_links(self, access):
|
|
||||||
self_link = self._get_access_href(access['image_id'], access['member'])
|
|
||||||
return [
|
|
||||||
{'rel': 'self', 'href': self_link},
|
|
||||||
{'rel': 'describedby', 'href': '/v2/schemas/image/access'},
|
|
||||||
]
|
|
||||||
|
|
||||||
def _format_access(self, access):
|
def _format_access(self, access):
|
||||||
|
self_link = self._get_access_href(access['image_id'], access['member'])
|
||||||
return {
|
return {
|
||||||
'tenant_id': access['member'],
|
'tenant_id': access['member'],
|
||||||
'can_share': access['can_share'],
|
'can_share': access['can_share'],
|
||||||
'links': self._get_access_links(access),
|
'self': self_link,
|
||||||
|
'schema': '/v2/schemas/image/access',
|
||||||
|
'image': '/v2/images/%s' % access['image_id'],
|
||||||
}
|
}
|
||||||
|
|
||||||
def _get_container_links(self, image_id):
|
|
||||||
return [{'rel': 'self', 'href': self._get_access_href(image_id)}]
|
|
||||||
|
|
||||||
def show(self, response, access):
|
def show(self, response, access):
|
||||||
record = {'access_record': self._format_access(access)}
|
record = {'access_record': self._format_access(access)}
|
||||||
response.body = json.dumps(record)
|
response.body = json.dumps(record)
|
||||||
|
|
||||||
def index(self, response, access_records):
|
def index(self, response, result):
|
||||||
|
access_records = result['access_records']
|
||||||
|
first_link = '/v2/images/%s/access' % result['image_id']
|
||||||
body = {
|
body = {
|
||||||
'access_records': [self._format_access(a) for a in access_records],
|
'access_records': [self._format_access(a)
|
||||||
'links': [],
|
for a in access_records],
|
||||||
|
'first': first_link,
|
||||||
|
'schema': '/v2/schemas/image/accesses',
|
||||||
}
|
}
|
||||||
response.body = json.dumps(body)
|
response.body = json.dumps(body)
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ class TestImageAccessController(test_utils.BaseTestCase):
|
|||||||
def test_index(self):
|
def test_index(self):
|
||||||
req = unit_test_utils.get_fake_request()
|
req = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.index(req, unit_test_utils.UUID1)
|
output = self.controller.index(req, unit_test_utils.UUID1)
|
||||||
expected = [
|
expected = {
|
||||||
|
'access_records': [
|
||||||
{
|
{
|
||||||
'image_id': unit_test_utils.UUID1,
|
'image_id': unit_test_utils.UUID1,
|
||||||
'member': unit_test_utils.TENANT1,
|
'member': unit_test_utils.TENANT1,
|
||||||
@ -48,13 +49,18 @@ class TestImageAccessController(test_utils.BaseTestCase):
|
|||||||
'can_share': False,
|
'can_share': False,
|
||||||
'deleted': False,
|
'deleted': False,
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
|
'image_id': unit_test_utils.UUID1,
|
||||||
|
}
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_index_zero_records(self):
|
def test_index_zero_records(self):
|
||||||
req = unit_test_utils.get_fake_request()
|
req = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.index(req, unit_test_utils.UUID2)
|
output = self.controller.index(req, unit_test_utils.UUID2)
|
||||||
expected = []
|
expected = {
|
||||||
|
'access_records': [],
|
||||||
|
'image_id': unit_test_utils.UUID2,
|
||||||
|
}
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_index_nonexistant_image(self):
|
def test_index_nonexistant_image(self):
|
||||||
@ -145,10 +151,9 @@ class TestImageAccessSerializer(test_utils.BaseTestCase):
|
|||||||
'access_record': {
|
'access_record': {
|
||||||
'tenant_id': unit_test_utils.TENANT1,
|
'tenant_id': unit_test_utils.TENANT1,
|
||||||
'can_share': False,
|
'can_share': False,
|
||||||
'links': [
|
'self': self_href,
|
||||||
{'rel': 'self', 'href': self_href},
|
'schema': '/v2/schemas/image/access',
|
||||||
{'rel': 'describedby', 'href': '/v2/schemas/image/access'},
|
'image': '/v2/images/%s' % unit_test_utils.UUID1,
|
||||||
],
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
@ -168,45 +173,52 @@ class TestImageAccessSerializer(test_utils.BaseTestCase):
|
|||||||
'can_share': True,
|
'can_share': True,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
result = {
|
||||||
|
'access_records': fixtures,
|
||||||
|
'image_id': unit_test_utils.UUID1,
|
||||||
|
}
|
||||||
expected = {
|
expected = {
|
||||||
'access_records': [
|
'access_records': [
|
||||||
{
|
{
|
||||||
'tenant_id': unit_test_utils.TENANT1,
|
'tenant_id': unit_test_utils.TENANT1,
|
||||||
'can_share': False,
|
'can_share': False,
|
||||||
'links': [
|
'self': ('/v2/images/%s/access/%s' %
|
||||||
{
|
|
||||||
'rel': 'self',
|
|
||||||
'href': ('/v2/images/%s/access/%s' %
|
|
||||||
(unit_test_utils.UUID1,
|
(unit_test_utils.UUID1,
|
||||||
unit_test_utils.TENANT1))
|
unit_test_utils.TENANT1)),
|
||||||
},
|
'schema': '/v2/schemas/image/access',
|
||||||
{
|
'image': '/v2/images/%s' % unit_test_utils.UUID1,
|
||||||
'rel': 'describedby',
|
|
||||||
'href': '/v2/schemas/image/access',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'tenant_id': unit_test_utils.TENANT2,
|
'tenant_id': unit_test_utils.TENANT2,
|
||||||
'can_share': True,
|
'can_share': True,
|
||||||
'links': [
|
'self': ('/v2/images/%s/access/%s' %
|
||||||
{
|
|
||||||
'rel': 'self',
|
|
||||||
'href': ('/v2/images/%s/access/%s' %
|
|
||||||
(unit_test_utils.UUID1,
|
(unit_test_utils.UUID1,
|
||||||
unit_test_utils.TENANT2))
|
unit_test_utils.TENANT2)),
|
||||||
},
|
'schema': '/v2/schemas/image/access',
|
||||||
{
|
'image': '/v2/images/%s' % unit_test_utils.UUID1,
|
||||||
'rel': 'describedby',
|
|
||||||
'href': '/v2/schemas/image/access',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
'first': '/v2/images/%s/access' % unit_test_utils.UUID1,
|
||||||
],
|
'schema': '/v2/schemas/image/accesses',
|
||||||
'links': [],
|
|
||||||
}
|
}
|
||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
self.serializer.index(response, fixtures)
|
self.serializer.index(response, result)
|
||||||
|
self.assertEqual(expected, json.loads(response.body))
|
||||||
|
|
||||||
|
def test_index_zero_access_records(self):
|
||||||
|
result = {
|
||||||
|
'access_records': [],
|
||||||
|
'image_id': unit_test_utils.UUID1,
|
||||||
|
}
|
||||||
|
response = webob.Response()
|
||||||
|
self.serializer.index(response, result)
|
||||||
|
first_link = '/v2/images/%s/access' % unit_test_utils.UUID1
|
||||||
|
expected = {
|
||||||
|
'access_records': [],
|
||||||
|
'first': first_link,
|
||||||
|
'schema': '/v2/schemas/image/accesses',
|
||||||
|
}
|
||||||
self.assertEqual(expected, json.loads(response.body))
|
self.assertEqual(expected, json.loads(response.body))
|
||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
@ -221,10 +233,9 @@ class TestImageAccessSerializer(test_utils.BaseTestCase):
|
|||||||
'access': {
|
'access': {
|
||||||
'tenant_id': unit_test_utils.TENANT1,
|
'tenant_id': unit_test_utils.TENANT1,
|
||||||
'can_share': False,
|
'can_share': False,
|
||||||
'links': [
|
'self': self_href,
|
||||||
{'rel': 'self', 'href': self_href},
|
'schema': '/v2/schemas/image/access',
|
||||||
{'rel': 'describedby', 'href': '/v2/schemas/image/access'},
|
'image': '/v2/images/%s' % unit_test_utils.UUID1,
|
||||||
],
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
response = webob.Response()
|
response = webob.Response()
|
||||||
|
Loading…
Reference in New Issue
Block a user