Merge "Remove last parts of query_string from context"

This commit is contained in:
Jenkins 2016-07-08 15:29:44 +00:00 committed by Gerrit Code Review
commit c7b72705b1
2 changed files with 8 additions and 7 deletions

View File

@ -33,11 +33,12 @@ class Request(webob.Request):
# allow middleware up the stack to provide context, params and headers.
context = self.environ.get(CONTEXT_ENV, {})
# NOTE(jamielennox): The webob package throws UnicodeError when a
# param cannot be decoded. If we make webob iterate them now we can
# catch this and throw an error early rather than on access.
try:
context['query_string'] = dict(self.params.items())
self.params.items()
except UnicodeDecodeError:
# The webob package throws UnicodeError when a request cannot be
# decoded. Raise ValidationError instead to avoid an UnknownError.
msg = _('Query string is not UTF-8 encoded')
raise exception.ValidationError(msg)

View File

@ -39,7 +39,7 @@ class FakeApp(wsgi.Application):
class FakeAttributeCheckerApp(wsgi.Application):
def index(self, request):
return request.context_dict['query_string']
return request.params.mixed()
def assert_attribute(self, body, attr):
"""Assert that the given request has a certain attribute."""
@ -89,7 +89,7 @@ class ApplicationTest(BaseWSGITest):
def test_query_string_available(self):
class FakeApp(wsgi.Application):
def index(self, request):
return request.context_dict['query_string']
return request.params.mixed()
req = self._make_request(url='/?1=2')
resp = req.get_response(FakeApp())
self.assertEqual({'1': '2'}, jsonutils.loads(resp.body))
@ -211,7 +211,7 @@ class ApplicationTest(BaseWSGITest):
def test_improperly_encoded_params(self):
class FakeApp(wsgi.Application):
def index(self, request):
return request.context_dict['query_string']
return request.params.mixed()
# this is high bit set ASCII, copy & pasted from Windows.
# aka code page 1252. It is not valid UTF8.
req = self._make_request(url='/?name=nonexit%E8nt')
@ -221,7 +221,7 @@ class ApplicationTest(BaseWSGITest):
def test_properly_encoded_params(self):
class FakeApp(wsgi.Application):
def index(self, request):
return request.context_dict['query_string']
return request.params.mixed()
# nonexitènt encoded as UTF-8
req = self._make_request(url='/?name=nonexit%C3%A8nt')
resp = req.get_response(FakeApp())