Fix link's href to consider osapi_compute_link_prefix
Version show request for both v2 and v2.1 (/v2 and /v2.1) does not consider the CONF.osapi_compute_link_prefix for buidling links's href. Above should prepare href using CONF.osapi_compute_link_prefix as done for other links. Previously functional tests of specific versions were not present so it was not caught. Closes-Bug: 1480009 Change-Id: I54a09d2c56efb0a05832e57313917177b770c8cb
This commit is contained in:
parent
72e568af11
commit
bf83370ce0
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"version": {
|
||||
"id": "v2.0",
|
||||
"links": [
|
||||
{
|
||||
"href": "http://openstack.example.com/v2/",
|
||||
"rel": "self"
|
||||
},
|
||||
{
|
||||
"href": "http://docs.openstack.org/",
|
||||
"rel": "describedby",
|
||||
"type": "text/html"
|
||||
}
|
||||
],
|
||||
"media-types": [
|
||||
{
|
||||
"base": "application/json",
|
||||
"type": "application/vnd.openstack.compute+json;version=2"
|
||||
}
|
||||
],
|
||||
"status": "SUPPORTED",
|
||||
"version": "",
|
||||
"min_version": "",
|
||||
"updated": "2011-01-21T11:33:21Z"
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ class ViewBuilder(common.ViewBuilder):
|
|||
|
||||
def __init__(self, base_url):
|
||||
""":param base_url: url of the root wsgi application."""
|
||||
self.prefix = self._update_compute_link_prefix(base_url)
|
||||
self.base_url = base_url
|
||||
|
||||
def build_choices(self, VERSIONS, req):
|
||||
|
@ -67,7 +68,7 @@ class ViewBuilder(common.ViewBuilder):
|
|||
reval = copy.deepcopy(version)
|
||||
reval['links'].insert(0, {
|
||||
"rel": "self",
|
||||
"href": self.base_url.rstrip('/') + '/',
|
||||
"href": self.prefix.rstrip('/') + '/',
|
||||
})
|
||||
return dict(version=reval)
|
||||
|
||||
|
@ -86,7 +87,6 @@ class ViewBuilder(common.ViewBuilder):
|
|||
|
||||
def generate_href(self, version, path=None):
|
||||
"""Create an url that refers to a specific version_number."""
|
||||
prefix = self._update_compute_link_prefix(self.base_url)
|
||||
if version.find('v2.1') == 0:
|
||||
version_number = 'v2.1'
|
||||
else:
|
||||
|
@ -94,6 +94,6 @@ class ViewBuilder(common.ViewBuilder):
|
|||
|
||||
if path:
|
||||
path = path.strip('/')
|
||||
return os.path.join(prefix, version_number, path)
|
||||
return os.path.join(self.prefix, version_number, path)
|
||||
else:
|
||||
return os.path.join(prefix, version_number) + '/'
|
||||
return os.path.join(self.prefix, version_number) + '/'
|
||||
|
|
|
@ -140,6 +140,11 @@ class VersionsSampleJsonTest(ApiSampleTestBaseV2):
|
|||
subs = self._get_regexes()
|
||||
self._verify_response('versions-get-resp', subs, response, 200)
|
||||
|
||||
def test_versions_get_v2(self):
|
||||
response = self._do_get('/v2', strip_version=True)
|
||||
subs = self._get_regexes()
|
||||
self._verify_response('v2-version-get-resp', subs, response, 200)
|
||||
|
||||
|
||||
class ServersSampleBase(ApiSampleTestBaseV2):
|
||||
def _post_server(self, use_common_server_api_samples=True):
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"version": {
|
||||
"id": "v2.0",
|
||||
"links": [
|
||||
{
|
||||
"href": "http://openstack.example.com/v2/",
|
||||
"rel": "self"
|
||||
},
|
||||
{
|
||||
"href": "http://docs.openstack.org/",
|
||||
"rel": "describedby",
|
||||
"type": "text/html"
|
||||
}
|
||||
],
|
||||
"media-types": [
|
||||
{
|
||||
"base": "application/json",
|
||||
"type": "application/vnd.openstack.compute+json;version=2"
|
||||
}
|
||||
],
|
||||
"min_version": "",
|
||||
"status": "SUPPORTED",
|
||||
"updated": "2011-01-21T11:33:21Z",
|
||||
"version": ""
|
||||
}
|
||||
}
|
|
@ -344,6 +344,51 @@ class VersionsViewBuilderTests(test.NoDBTestCase):
|
|||
|
||||
self.assertEqual(output, expected)
|
||||
|
||||
def _test_view_builder_osapi_compute_link_prefix(self,
|
||||
href=None):
|
||||
base_url = "http://example.org/v2.1/"
|
||||
if href is None:
|
||||
href = base_url
|
||||
|
||||
version_data = {
|
||||
"id": "v2.1",
|
||||
"status": "CURRENT",
|
||||
"version": "2.8",
|
||||
"min_version": "2.1",
|
||||
"updated": "2013-07-23T11:33:21Z",
|
||||
"links": [
|
||||
{
|
||||
"rel": "describedby",
|
||||
"type": "text/html",
|
||||
"href": EXP_LINKS['v2.1']['html'],
|
||||
}
|
||||
],
|
||||
"media-types": [
|
||||
{
|
||||
"base": "application/json",
|
||||
"type": ("application/vnd.openstack."
|
||||
"compute+json;version=2.1")
|
||||
}
|
||||
],
|
||||
}
|
||||
expected_data = copy.deepcopy(version_data)
|
||||
expected = {'version': expected_data}
|
||||
expected['version']['links'].insert(0, {
|
||||
"rel": "self",
|
||||
"href": href,
|
||||
})
|
||||
builder = views.versions.ViewBuilder(base_url)
|
||||
output = builder.build_version(version_data)
|
||||
self.assertEqual(expected, output)
|
||||
|
||||
def test_view_builder_with_osapi_compute_link_prefix(self):
|
||||
self.flags(osapi_compute_link_prefix='http://zoo.com:42')
|
||||
href = "http://zoo.com:42/v2.1/"
|
||||
self._test_view_builder_osapi_compute_link_prefix(href)
|
||||
|
||||
def test_view_builder_without_osapi_compute_link_prefix(self):
|
||||
self._test_view_builder_osapi_compute_link_prefix()
|
||||
|
||||
def test_generate_href(self):
|
||||
base_url = "http://example.org/app/"
|
||||
|
||||
|
|
Loading…
Reference in New Issue