Merge "Add content-type to responses" into redux
This commit is contained in:
commit
738e2ec8e4
|
@ -180,10 +180,13 @@ class Application(BaseApplication):
|
|||
elif isinstance(result, webob.exc.WSGIHTTPException):
|
||||
return result
|
||||
|
||||
return self._serialize(result)
|
||||
response = webob.Response()
|
||||
self._serialize(response, result)
|
||||
return response
|
||||
|
||||
def _serialize(self, result):
|
||||
return json.dumps(result, cls=utils.SmarterEncoder)
|
||||
def _serialize(self, response, result):
|
||||
response.content_type = 'application/json'
|
||||
response.body = json.dumps(result, cls=utils.SmarterEncoder)
|
||||
|
||||
def _normalize_arg(self, arg):
|
||||
return str(arg).replace(':', '_').replace('-', '_')
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import webob
|
||||
|
||||
from keystone import test
|
||||
from keystone.common import wsgi
|
||||
|
||||
|
||||
class FakeApp(wsgi.Application):
|
||||
def index(self, context):
|
||||
return {'a': 'b'}
|
||||
|
||||
|
||||
class ApplicationTest(test.TestCase):
|
||||
def setUp(self):
|
||||
self.app = FakeApp()
|
||||
|
||||
def _make_request(self):
|
||||
req = webob.Request.blank('/')
|
||||
args = {'action': 'index', 'controller': self.app}
|
||||
req.environ['wsgiorg.routing_args'] = [None, args]
|
||||
return req
|
||||
|
||||
def test_response_content_type(self):
|
||||
req = self._make_request()
|
||||
resp = req.get_response(self.app)
|
||||
self.assertEqual(resp.content_type, 'application/json')
|
Loading…
Reference in New Issue