Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.x] 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.

Backport of d9a0b6a.
  • Loading branch information...
commit db22145afb9623fdcaa4269b5eefa045320e028e 1 parent 91af923
Aymeric Augustin authored December 17, 2012

Showing 1 changed file with 23 additions and 23 deletions. Show diff stats Hide diff stats

  1. 46  django/test/client.py
46  django/test/client.py
@@ -21,7 +21,7 @@
21 21
 from django.template import TemplateDoesNotExist
22 22
 from django.test import signals
23 23
 from django.utils.functional import curry
24  
-from django.utils.encoding import force_bytes
  24
+from django.utils.encoding import force_bytes, force_str
25 25
 from django.utils.http import urlencode
26 26
 from django.utils.importlib import import_module
27 27
 from django.utils.itercompat import is_iterable
@@ -205,15 +205,15 @@ def _base_environ(self, **request):
205 205
         # See http://www.python.org/dev/peps/pep-3333/#environ-variables
206 206
         environ = {
207 207
             'HTTP_COOKIE':       self.cookies.output(header='', sep='; '),
208  
-            'PATH_INFO':         '/',
209  
-            'REMOTE_ADDR':       '127.0.0.1',
210  
-            'REQUEST_METHOD':    'GET',
211  
-            'SCRIPT_NAME':       '',
212  
-            'SERVER_NAME':       'testserver',
213  
-            'SERVER_PORT':       '80',
214  
-            'SERVER_PROTOCOL':   'HTTP/1.1',
  208
+            'PATH_INFO':         str('/'),
  209
+            'REMOTE_ADDR':       str('127.0.0.1'),
  210
+            'REQUEST_METHOD':    str('GET'),
  211
+            'SCRIPT_NAME':       str(''),
  212
+            'SERVER_NAME':       str('testserver'),
  213
+            'SERVER_PORT':       str('80'),
  214
+            'SERVER_PROTOCOL':   str('HTTP/1.1'),
215 215
             'wsgi.version':      (1, 0),
216  
-            'wsgi.url_scheme':   'http',
  216
+            'wsgi.url_scheme':   str('http'),
217 217
             'wsgi.input':        FakePayload(b''),
218 218
             'wsgi.errors':       self.errors,
219 219
             'wsgi.multiprocess': True,
@@ -241,21 +241,21 @@ def _encode_data(self, data, content_type, ):
241 241
             return force_bytes(data, encoding=charset)
242 242
 
243 243
     def _get_path(self, parsed):
  244
+        path = force_str(parsed[2])
244 245
         # If there are parameters, add them
245 246
         if parsed[3]:
246  
-            return unquote(parsed[2] + ";" + parsed[3])
247  
-        else:
248  
-            return unquote(parsed[2])
  247
+            path += str(";") + force_str(parsed[3])
  248
+        return unquote(path)
249 249
 
250 250
     def get(self, path, data={}, **extra):
251 251
         "Construct a GET request."
252 252
 
253 253
         parsed = urlparse(path)
254 254
         r = {
255  
-            'CONTENT_TYPE':    'text/html; charset=utf-8',
  255
+            'CONTENT_TYPE':    str('text/html; charset=utf-8'),
256 256
             'PATH_INFO':       self._get_path(parsed),
257  
-            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
258  
-            'REQUEST_METHOD': 'GET',
  257
+            'QUERY_STRING':    urlencode(data, doseq=True) or force_str(parsed[4]),
  258
+            'REQUEST_METHOD':  str('GET'),
259 259
         }
260 260
         r.update(extra)
261 261
         return self.request(**r)
@@ -271,8 +271,8 @@ def post(self, path, data={}, content_type=MULTIPART_CONTENT,
271 271
             'CONTENT_LENGTH': len(post_data),
272 272
             'CONTENT_TYPE':   content_type,
273 273
             'PATH_INFO':      self._get_path(parsed),
274  
-            'QUERY_STRING':   parsed[4],
275  
-            'REQUEST_METHOD': 'POST',
  274
+            'QUERY_STRING':   force_str(parsed[4]),
  275
+            'REQUEST_METHOD': str('POST'),
276 276
             'wsgi.input':     FakePayload(post_data),
277 277
         }
278 278
         r.update(extra)
@@ -283,10 +283,10 @@ def head(self, path, data={}, **extra):
283 283
 
284 284
         parsed = urlparse(path)
285 285
         r = {
286  
-            'CONTENT_TYPE':    'text/html; charset=utf-8',
  286
+            'CONTENT_TYPE':    str('text/html; charset=utf-8'),
287 287
             'PATH_INFO':       self._get_path(parsed),
288  
-            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
289  
-            'REQUEST_METHOD': 'HEAD',
  288
+            'QUERY_STRING':    urlencode(data, doseq=True) or force_str(parsed[4]),
  289
+            'REQUEST_METHOD':  str('HEAD'),
290 290
         }
291 291
         r.update(extra)
292 292
         return self.request(**r)
@@ -312,13 +312,13 @@ def generic(self, method, path,
312 312
         data = force_bytes(data, settings.DEFAULT_CHARSET)
313 313
         r = {
314 314
             'PATH_INFO':      self._get_path(parsed),
315  
-            'QUERY_STRING':   parsed[4],
316  
-            'REQUEST_METHOD': method,
  315
+            'QUERY_STRING':   force_str(parsed[4]),
  316
+            'REQUEST_METHOD': str(method),
317 317
         }
318 318
         if data:
319 319
             r.update({
320 320
                 'CONTENT_LENGTH': len(data),
321  
-                'CONTENT_TYPE':   content_type,
  321
+                'CONTENT_TYPE':   str(content_type),
322 322
                 'wsgi.input':     FakePayload(data),
323 323
             })
324 324
         r.update(extra)

0 notes on commit db22145

Please sign in to comment.
Something went wrong with that request. Please try again.