Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #19487 -- Used str in the test client's WSGI environ.

This regression was introduced by the unicode_literals patch. The WSGI
spec mandates that environ contains native strings.
  • Loading branch information...
commit d9a0b6ab36b6beb4251acf1de1fdf255e1223e02 1 parent d19109f
@aaugustin aaugustin authored
Showing with 23 additions and 23 deletions.
  1. +23 −23 django/test/client.py
View
46 django/test/client.py
@@ -21,7 +21,7 @@
from django.template import TemplateDoesNotExist
from django.test import signals
from django.utils.functional import curry
-from django.utils.encoding import force_bytes
+from django.utils.encoding import force_bytes, force_str
from django.utils.http import urlencode
from django.utils.importlib import import_module
from django.utils.itercompat import is_iterable
@@ -205,15 +205,15 @@ def _base_environ(self, **request):
# See http://www.python.org/dev/peps/pep-3333/#environ-variables
environ = {
'HTTP_COOKIE': self.cookies.output(header='', sep='; '),
- 'PATH_INFO': '/',
- 'REMOTE_ADDR': '127.0.0.1',
- 'REQUEST_METHOD': 'GET',
- 'SCRIPT_NAME': '',
- 'SERVER_NAME': 'testserver',
- 'SERVER_PORT': '80',
- 'SERVER_PROTOCOL': 'HTTP/1.1',
+ 'PATH_INFO': str('/'),
+ 'REMOTE_ADDR': str('127.0.0.1'),
+ 'REQUEST_METHOD': str('GET'),
+ 'SCRIPT_NAME': str(''),
+ 'SERVER_NAME': str('testserver'),
+ 'SERVER_PORT': str('80'),
+ 'SERVER_PROTOCOL': str('HTTP/1.1'),
'wsgi.version': (1, 0),
- 'wsgi.url_scheme': 'http',
+ 'wsgi.url_scheme': str('http'),
'wsgi.input': FakePayload(b''),
'wsgi.errors': self.errors,
'wsgi.multiprocess': True,
@@ -241,21 +241,21 @@ def _encode_data(self, data, content_type, ):
return force_bytes(data, encoding=charset)
def _get_path(self, parsed):
+ path = force_str(parsed[2])
# If there are parameters, add them
if parsed[3]:
- return unquote(parsed[2] + ";" + parsed[3])
- else:
- return unquote(parsed[2])
+ path += str(";") + force_str(parsed[3])
+ return unquote(path)
def get(self, path, data={}, **extra):
"Construct a GET request."
parsed = urlparse(path)
r = {
- 'CONTENT_TYPE': 'text/html; charset=utf-8',
+ 'CONTENT_TYPE': str('text/html; charset=utf-8'),
'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
- 'REQUEST_METHOD': 'GET',
+ 'QUERY_STRING': urlencode(data, doseq=True) or force_str(parsed[4]),
+ 'REQUEST_METHOD': str('GET'),
}
r.update(extra)
return self.request(**r)
@@ -271,8 +271,8 @@ def post(self, path, data={}, content_type=MULTIPART_CONTENT,
'CONTENT_LENGTH': len(post_data),
'CONTENT_TYPE': content_type,
'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': parsed[4],
- 'REQUEST_METHOD': 'POST',
+ 'QUERY_STRING': force_str(parsed[4]),
+ 'REQUEST_METHOD': str('POST'),
'wsgi.input': FakePayload(post_data),
}
r.update(extra)
@@ -283,10 +283,10 @@ def head(self, path, data={}, **extra):
parsed = urlparse(path)
r = {
- 'CONTENT_TYPE': 'text/html; charset=utf-8',
+ 'CONTENT_TYPE': str('text/html; charset=utf-8'),
'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
- 'REQUEST_METHOD': 'HEAD',
+ 'QUERY_STRING': urlencode(data, doseq=True) or force_str(parsed[4]),
+ 'REQUEST_METHOD': str('HEAD'),
}
r.update(extra)
return self.request(**r)
@@ -312,13 +312,13 @@ def generic(self, method, path,
data = force_bytes(data, settings.DEFAULT_CHARSET)
r = {
'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': parsed[4],
- 'REQUEST_METHOD': method,
+ 'QUERY_STRING': force_str(parsed[4]),
+ 'REQUEST_METHOD': str(method),
}
if data:
r.update({
'CONTENT_LENGTH': len(data),
- 'CONTENT_TYPE': content_type,
+ 'CONTENT_TYPE': str(content_type),
'wsgi.input': FakePayload(data),
})
r.update(extra)
Please sign in to comment.
Something went wrong with that request. Please try again.