summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-09-07 11:30:03 -0500
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-09-07 12:06:19 -0500
commit9244447cc4a91c22f8f2668f9667e92a1b2de958 (patch)
treec256c71ecf79e035962e31790665ba83dc5634f7
parenta357c854c91b513e3713f2eb72e9742d49c2e701 (diff)
[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
-rw-r--r--django/test/client.py9
1 files changed, 8 insertions, 1 deletions
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.