diff options
-rw-r--r-- | keystone/common/wsgi.py | 25 | ||||
-rw-r--r-- | keystone/service.py | 5 | ||||
-rw-r--r-- | tests/test_versions.py | 2 |
3 files changed, 20 insertions, 12 deletions
diff --git a/keystone/common/wsgi.py b/keystone/common/wsgi.py index 7b6926d0..c176ec64 100644 --- a/keystone/common/wsgi.py +++ b/keystone/common/wsgi.py @@ -183,6 +183,8 @@ class Application(BaseApplication): if result is None or type(result) is str or type(result) is unicode: return result + elif isinstance(result, webob.Response): + return result elif isinstance(result, webob.exc.WSGIHTTPException): return result @@ -455,20 +457,23 @@ class ExtensionRouter(Router): return _factory -def render_exception(error): - """Forms a WSGI response based on the current error.""" +def render_response(body, status=(200, 'OK'), headers=None): + """Forms a WSGI response""" resp = webob.Response() - resp.status = '%s %s' % (error.code, error.title) - resp.headerlist = [('Content-Type', 'application/json')] + resp.status = '%s %s' % status + resp.headerlist = headers or [('Content-Type', 'application/json')] + + resp.body = json.dumps(body) + + return resp - body = { + +def render_exception(error): + """Forms a WSGI response based on the current error.""" + return render_response(status=(error.code, error.title), body={ 'error': { 'code': error.code, 'title': error.title, 'message': str(error), } - } - - resp.body = json.dumps(body) - - return resp + }) diff --git a/keystone/service.py b/keystone/service.py index e2755e48..aa3c9c8b 100644 --- a/keystone/service.py +++ b/keystone/service.py @@ -137,7 +137,8 @@ class VersionController(wsgi.Application): identity_url = self._get_identity_url(context) if not identity_url.endswith('/'): identity_url = identity_url + '/' - return { + + return wsgi.render_response(status=(300, 'Multiple Choices'), body={ "versions": { "values": [{ "id": "v2.0", @@ -165,7 +166,7 @@ class VersionController(wsgi.Application): }] }] } - } + }) class NoopController(wsgi.Application): diff --git a/tests/test_versions.py b/tests/test_versions.py index 2fef3cf0..4d302bf3 100644 --- a/tests/test_versions.py +++ b/tests/test_versions.py @@ -51,6 +51,7 @@ class VersionTestCase(test.TestCase): def test_public_versions(self): client = self.client(self.public_app) resp = client.get('/') + self.assertEqual(resp.status_int, 300) data = json.loads(resp.body) expected = { "versions": { @@ -87,6 +88,7 @@ class VersionTestCase(test.TestCase): def test_admin_versions(self): client = self.client(self.admin_app) resp = client.get('/') + self.assertEqual(resp.status_int, 300) data = json.loads(resp.body) expected = { "versions": { |