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.
This commit is contained in:
Aymeric Augustin 2012-12-17 10:47:38 +01:00
parent d19109fd37
commit d9a0b6ab36
1 changed files with 23 additions and 23 deletions

View File

@ -21,7 +21,7 @@ from django.http import SimpleCookie, HttpRequest, QueryDict
from django.template import TemplateDoesNotExist from django.template import TemplateDoesNotExist
from django.test import signals from django.test import signals
from django.utils.functional import curry 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.http import urlencode
from django.utils.importlib import import_module from django.utils.importlib import import_module
from django.utils.itercompat import is_iterable from django.utils.itercompat import is_iterable
@ -205,15 +205,15 @@ class RequestFactory(object):
# See http://www.python.org/dev/peps/pep-3333/#environ-variables # See http://www.python.org/dev/peps/pep-3333/#environ-variables
environ = { environ = {
'HTTP_COOKIE': self.cookies.output(header='', sep='; '), 'HTTP_COOKIE': self.cookies.output(header='', sep='; '),
'PATH_INFO': '/', 'PATH_INFO': str('/'),
'REMOTE_ADDR': '127.0.0.1', 'REMOTE_ADDR': str('127.0.0.1'),
'REQUEST_METHOD': 'GET', 'REQUEST_METHOD': str('GET'),
'SCRIPT_NAME': '', 'SCRIPT_NAME': str(''),
'SERVER_NAME': 'testserver', 'SERVER_NAME': str('testserver'),
'SERVER_PORT': '80', 'SERVER_PORT': str('80'),
'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_PROTOCOL': str('HTTP/1.1'),
'wsgi.version': (1, 0), 'wsgi.version': (1, 0),
'wsgi.url_scheme': 'http', 'wsgi.url_scheme': str('http'),
'wsgi.input': FakePayload(b''), 'wsgi.input': FakePayload(b''),
'wsgi.errors': self.errors, 'wsgi.errors': self.errors,
'wsgi.multiprocess': True, 'wsgi.multiprocess': True,
@ -241,21 +241,21 @@ class RequestFactory(object):
return force_bytes(data, encoding=charset) return force_bytes(data, encoding=charset)
def _get_path(self, parsed): def _get_path(self, parsed):
path = force_str(parsed[2])
# If there are parameters, add them # If there are parameters, add them
if parsed[3]: if parsed[3]:
return unquote(parsed[2] + ";" + parsed[3]) path += str(";") + force_str(parsed[3])
else: return unquote(path)
return unquote(parsed[2])
def get(self, path, data={}, **extra): def get(self, path, data={}, **extra):
"Construct a GET request." "Construct a GET request."
parsed = urlparse(path) parsed = urlparse(path)
r = { r = {
'CONTENT_TYPE': 'text/html; charset=utf-8', 'CONTENT_TYPE': str('text/html; charset=utf-8'),
'PATH_INFO': self._get_path(parsed), 'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4], 'QUERY_STRING': urlencode(data, doseq=True) or force_str(parsed[4]),
'REQUEST_METHOD': 'GET', 'REQUEST_METHOD': str('GET'),
} }
r.update(extra) r.update(extra)
return self.request(**r) return self.request(**r)
@ -271,8 +271,8 @@ class RequestFactory(object):
'CONTENT_LENGTH': len(post_data), 'CONTENT_LENGTH': len(post_data),
'CONTENT_TYPE': content_type, 'CONTENT_TYPE': content_type,
'PATH_INFO': self._get_path(parsed), 'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': parsed[4], 'QUERY_STRING': force_str(parsed[4]),
'REQUEST_METHOD': 'POST', 'REQUEST_METHOD': str('POST'),
'wsgi.input': FakePayload(post_data), 'wsgi.input': FakePayload(post_data),
} }
r.update(extra) r.update(extra)
@ -283,10 +283,10 @@ class RequestFactory(object):
parsed = urlparse(path) parsed = urlparse(path)
r = { r = {
'CONTENT_TYPE': 'text/html; charset=utf-8', 'CONTENT_TYPE': str('text/html; charset=utf-8'),
'PATH_INFO': self._get_path(parsed), 'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4], 'QUERY_STRING': urlencode(data, doseq=True) or force_str(parsed[4]),
'REQUEST_METHOD': 'HEAD', 'REQUEST_METHOD': str('HEAD'),
} }
r.update(extra) r.update(extra)
return self.request(**r) return self.request(**r)
@ -312,13 +312,13 @@ class RequestFactory(object):
data = force_bytes(data, settings.DEFAULT_CHARSET) data = force_bytes(data, settings.DEFAULT_CHARSET)
r = { r = {
'PATH_INFO': self._get_path(parsed), 'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': parsed[4], 'QUERY_STRING': force_str(parsed[4]),
'REQUEST_METHOD': method, 'REQUEST_METHOD': str(method),
} }
if data: if data:
r.update({ r.update({
'CONTENT_LENGTH': len(data), 'CONTENT_LENGTH': len(data),
'CONTENT_TYPE': content_type, 'CONTENT_TYPE': str(content_type),
'wsgi.input': FakePayload(data), 'wsgi.input': FakePayload(data),
}) })
r.update(extra) r.update(extra)