Merge "Provide a Location on HTTP 300"

This commit is contained in:
Zuul 2018-11-09 23:20:30 +00:00 committed by Gerrit Code Review
commit a633001b20
2 changed files with 18 additions and 2 deletions

View File

@ -68,12 +68,20 @@ def get_versions():
else:
identity_url = '%s/' % ks_flask.base_url()
versions = _get_versions_list(identity_url)
return flask.Response(
# Set the preferred version to the latest "stable" version.
# TODO(morgan): If we ever have more API versions find the latest
# stable version instead of just using the "base_url", for now we
# simply have a single version so use it as the preferred location.
preferred_location = identity_url
response = flask.Response(
response=jsonutils.dumps(
{'versions': {
'values': list(versions.values())}}),
mimetype=MimeTypes.JSON,
status=http_client.MULTIPLE_CHOICES)
response.headers['Location'] = preferred_location
return response
@_DISCOVERY_BLUEPRINT.route('/v3')

View File

@ -907,10 +907,18 @@ class VersionSingleAppTestCase(unit.TestCase):
self.assertEqual(300, resp.status_int)
data = jsonutils.loads(resp.body)
expected = VERSIONS_RESPONSE
url_with_port = 'http://localhost:%s/v3/' % self.public_port
for version in expected['versions']['values']:
# TODO(morgan): Eliminate the need to do the "paste-in-port" part
# of the tests. Ultimately, this is very hacky and shows we are
# not setting up the test case sanely.
if version['id'].startswith('v3'):
self._paste_in_port(
version, 'http://localhost:%s/v3/' % self.public_port)
version, url_with_port)
# Explicitly check that a location header is set and it is pointing
# to v3 (The preferred location for now)!
self.assertIn('Location', resp.headers)
self.assertEqual(url_with_port, resp.headers['Location'])
self.assertThat(data, _VersionsEqual(expected))
def test_public(self):