Merge "[placement] Avoid error log on 405 response"
This commit is contained in:
commit
cf5126a992
@ -158,9 +158,11 @@ def handle_405(environ, start_response):
|
||||
# In the process done by Routes to save the allowed methods
|
||||
# to its routing table they become unicode in py2.
|
||||
headers['allow'] = str(_methods)
|
||||
raise webob.exc.HTTPMethodNotAllowed(
|
||||
# Use Exception class as WSGI Application. We don't want to raise here.
|
||||
response = webob.exc.HTTPMethodNotAllowed(
|
||||
_('The method specified is not allowed for this resource.'),
|
||||
headers=headers, json_formatter=util.json_error_formatter)
|
||||
return response(environ, start_response)
|
||||
|
||||
|
||||
def make_map(declarations):
|
||||
|
@ -101,11 +101,17 @@ class MapperTest(test.NoDBTestCase):
|
||||
|
||||
def test_405_headers(self):
|
||||
environ = _environ(path='/hello', method='POST')
|
||||
error = self.assertRaises(webob.exc.HTTPMethodNotAllowed,
|
||||
handler.dispatch,
|
||||
environ, start_response,
|
||||
self.mapper)
|
||||
allow_header = error.headers['allow']
|
||||
global headers, status
|
||||
headers = status = None
|
||||
|
||||
def local_start_response(*args, **kwargs):
|
||||
global headers, status
|
||||
status = args[0]
|
||||
headers = {header[0]: header[1] for header in args[1]}
|
||||
|
||||
handler.dispatch(environ, local_start_response, self.mapper)
|
||||
allow_header = headers['allow']
|
||||
self.assertEqual('405 Method Not Allowed', status)
|
||||
self.assertEqual('GET', allow_header)
|
||||
# PEP 3333 requires that headers be whatever the native str
|
||||
# is in that version of Python. Never unicode.
|
||||
|
Loading…
x
Reference in New Issue
Block a user