Changed an HTTP exception to return proper code

POSTing to /servers with a content-type of text/plain
and a text/plain body results in a response code of 400.
It should be 415. I found this line in the code that
appears to handle this singular case and modified
the HTTP exception used to the correct one. Tests were
also updated accordingly.

Change-Id: I5fa1fdba56803b2ef63b1efaaeeced6ceb7779d9
Closes-Bug: 1567977
(cherry picked from commit a7019a87ba)
This commit is contained in:
Brandon Irizarry 2016-04-13 05:18:25 +00:00 committed by Matt Riedemann
parent 9eed73f871
commit d627ae8526
4 changed files with 7 additions and 7 deletions

View File

@ -661,7 +661,7 @@ class Resource(wsgi.Application):
accept = request.best_match_content_type()
except exception.InvalidContentType:
msg = _("Unsupported Content-Type")
return Fault(webob.exc.HTTPBadRequest(explanation=msg))
return Fault(webob.exc.HTTPUnsupportedMediaType(explanation=msg))
# NOTE(Vek): Splitting the function up this way allows for
# auditing by external tools that wrap the existing

View File

@ -1362,7 +1362,7 @@ class ServersControllerUpdateTest(ControllerTest):
key="Label"></meta>"""
req = self._get_request(body, content_type='xml')
res = req.get_response(self.wsgi_app)
self.assertEqual(400, res.status_int)
self.assertEqual(415, res.status_int)
def test_update_server_invalid_xml_raises_expat(self):
body = """<?xml version="1.0" encoding="UTF-8"?>
@ -1371,7 +1371,7 @@ class ServersControllerUpdateTest(ControllerTest):
key="Label"></meta>"""
req = self._get_request(body, content_type='xml')
res = req.get_response(self.wsgi_app)
self.assertEqual(400, res.status_int)
self.assertEqual(415, res.status_int)
def test_update_server_name(self):
body = {'server': {'name': 'server_test'}}

View File

@ -59,7 +59,7 @@ class APITest(test.NoDBTestCase):
req.headers["content-type"] = "application/xml"
res = req.get_response(self.wsgi_app)
self.assertEqual(res.status_int, 400)
self.assertEqual(res.status_int, 415)
def test_vendor_content_type_json(self):
ctype = 'application/vnd.openstack.compute+json'

View File

@ -409,9 +409,9 @@ class ResourceTest(test.NoDBTestCase):
req.content_type = 'application/xml'
req.body = b'{"body": {"key": "value"}}'
response = req.get_response(app)
expected_unsupported_type_body = {'badRequest':
{'message': 'Unsupported Content-Type', 'code': 400}}
self.assertEqual(response.status_int, 400)
expected_unsupported_type_body = {'badMediaType':
{'message': 'Unsupported Content-Type', 'code': 415}}
self.assertEqual(response.status_int, 415)
self.assertEqual(expected_unsupported_type_body,
jsonutils.loads(response.body))