From 9244447cc4a91c22f8f2668f9667e92a1b2de958 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 7 Sep 2013 11:30:03 -0500 Subject: [PATCH] [1.6.x] Fixed an encoding issue in the test client. Refs #20530. Backport of 7bb62793 and 476b0764 from master. Conflicts: django/test/client.py --- django/test/client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/django/test/client.py b/django/test/client.py index 94cfada725..2196805c4c 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -335,7 +335,6 @@ class RequestFactory(object): data = force_bytes(data, settings.DEFAULT_CHARSET) r = { 'PATH_INFO': self._get_path(parsed), - 'QUERY_STRING': force_str(parsed[4]), 'REQUEST_METHOD': str(method), } if data: @@ -345,8 +344,16 @@ class RequestFactory(object): 'wsgi.input': FakePayload(data), }) r.update(extra) + # If QUERY_STRING is absent or empty, we want to extract it from the URL. + if not r.get('QUERY_STRING'): + query_string = force_bytes(parsed[4]) + # WSGI requires latin-1 encoded strings. See get_path_info(). + if six.PY3: + query_string = query_string.decode('iso-8859-1') + r['QUERY_STRING'] = query_string return self.request(**r) + class Client(RequestFactory): """ A class that can act as a client for testing purposes.