Merge "Updates for version list to show correct references"

This commit is contained in:
Jenkins 2014-01-21 15:16:40 +00:00 committed by Gerrit Code Review
commit f67050b501
3 changed files with 26 additions and 16 deletions

View File

@ -38,7 +38,8 @@ class ViewBuilder(object):
"id": version['id'],
"status": version['status'],
"links": [{"rel": "self",
"href": self.generate_href(req.path), }, ],
"href": self.generate_href(version['id'],
req.path), }, ],
"media-types": version['media-types'], })
return dict(choices=version_objs)
@ -64,16 +65,20 @@ class ViewBuilder(object):
def _build_links(self, version_data):
"""Generate a container of links that refer to the provided version."""
href = self.generate_href()
href = self.generate_href(version_data['id'])
links = [{'rel': 'self',
'href': href, }, ]
return links
def generate_href(self, path=None):
def generate_href(self, version, path=None):
"""Create an url that refers to a specific version_number."""
version_number = 'v1'
if version.find('v1.') == 0:
version_number = 'v1'
else:
version_number = 'v2'
if path:
path = path.strip('/')
return os.path.join(self.base_url, version_number, path)

View File

@ -133,7 +133,12 @@ class HTTPRequest(webob.Request):
@classmethod
def blank(cls, *args, **kwargs):
kwargs['base_url'] = 'http://localhost/v1'
if args != None:
if args[0].find('v1') == 0:
kwargs['base_url'] = 'http://localhost/v1'
else:
kwargs['base_url'] = 'http://localhost/v2'
use_admin_context = kwargs.pop('use_admin_context', False)
out = os_wsgi.Request.blank(*args, **kwargs)
out.environ['cinder.context'] = FakeRequestContext(

View File

@ -94,7 +94,7 @@ class VolumeApiTest(test.TestCase):
'description': 'Volume Test Desc',
'id': '1',
'links':
[{'href': 'http://localhost/v1/fake/volumes/1',
[{'href': 'http://localhost/v2/fake/volumes/1',
'rel': 'self'},
{'href': 'http://localhost/fake/volumes/1',
'rel': 'bookmark'}],
@ -196,7 +196,7 @@ class VolumeApiTest(test.TestCase):
'description': 'Volume Test Desc',
'id': '1',
'links':
[{'href': 'http://localhost/v1/fake/volumes/1',
[{'href': 'http://localhost/v2/fake/volumes/1',
'rel': 'self'},
{'href': 'http://localhost/fake/volumes/1',
'rel': 'bookmark'}],
@ -284,7 +284,7 @@ class VolumeApiTest(test.TestCase):
'size': 1,
'links': [
{
'href': 'http://localhost/v1/fake/volumes/1',
'href': 'http://localhost/v2/fake/volumes/1',
'rel': 'self'
},
{
@ -331,7 +331,7 @@ class VolumeApiTest(test.TestCase):
'size': 1,
'links': [
{
'href': 'http://localhost/v1/fake/volumes/1',
'href': 'http://localhost/v2/fake/volumes/1',
'rel': 'self'
},
{
@ -388,7 +388,7 @@ class VolumeApiTest(test.TestCase):
'size': 1,
'links': [
{
'href': 'http://localhost/v1/fake/volumes/1',
'href': 'http://localhost/v2/fake/volumes/1',
'rel': 'self'
},
{
@ -440,7 +440,7 @@ class VolumeApiTest(test.TestCase):
'id': '1',
'links': [
{
'href': 'http://localhost/v1/fake/volumes/1',
'href': 'http://localhost/v2/fake/volumes/1',
'rel': 'self'
},
{
@ -489,7 +489,7 @@ class VolumeApiTest(test.TestCase):
'size': 1,
'links': [
{
'href': 'http://localhost/v1/fake/volumes/1',
'href': 'http://localhost/v2/fake/volumes/1',
'rel': 'self'
},
{
@ -547,7 +547,7 @@ class VolumeApiTest(test.TestCase):
'size': 1,
'links': [
{
'href': 'http://localhost/v1/fakeproject'
'href': 'http://localhost/v2/fakeproject'
'/volumes/1',
'rel': 'self'
},
@ -879,7 +879,7 @@ class VolumeApiTest(test.TestCase):
'size': 1,
'links': [
{
'href': 'http://localhost/v1/fake/volumes/1',
'href': 'http://localhost/v2/fake/volumes/1',
'rel': 'self'
},
{
@ -919,7 +919,7 @@ class VolumeApiTest(test.TestCase):
'size': 1,
'links': [
{
'href': 'http://localhost/v1/fake/volumes/1',
'href': 'http://localhost/v2/fake/volumes/1',
'rel': 'self'
},
{
@ -984,7 +984,7 @@ class VolumeApiTest(test.TestCase):
'size': 1,
'links': [
{
'href': 'http://localhost/v1/fakeproject/volumes/1',
'href': 'http://localhost/v2/fakeproject/volumes/1',
'rel': 'self'
},
{