summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2011-08-23 00:52:45 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2011-08-23 00:52:45 +0000
commitd310f91ee7cb76db4d3dd2d1d2304a561cca3a29 (patch)
tree4ff7785c566560f14b093cc38276a771f536e1bf /django
parent0f767f9a993f5834f7a2004bf4c440a126a73d06 (diff)
Fixed #10571 -- Factored out the payload encoding code to make sure it is used for PUT requests. Thanks to kennu for the report, pterk for the patch, and wildfire for the review comments.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16651 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/test/client.py40
1 files changed, 17 insertions, 23 deletions
diff --git a/django/test/client.py b/django/test/client.py
index 10d87279d0..e143c748b9 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -207,6 +207,18 @@ class RequestFactory(object):
"Construct a generic request object."
return WSGIRequest(self._base_environ(**request))
+ def _encode_data(self, data, content_type, ):
+ if content_type is MULTIPART_CONTENT:
+ return encode_multipart(BOUNDARY, data)
+ else:
+ # Encode the content so that the byte representation is correct.
+ match = CONTENT_TYPE_RE.match(content_type)
+ if match:
+ charset = match.group(1)
+ else:
+ charset = settings.DEFAULT_CHARSET
+ return smart_str(data, encoding=charset)
+
def _get_path(self, parsed):
# If there are parameters, add them
if parsed[3]:
@@ -232,16 +244,7 @@ class RequestFactory(object):
**extra):
"Construct a POST request."
- if content_type is MULTIPART_CONTENT:
- post_data = encode_multipart(BOUNDARY, data)
- else:
- # Encode the content so that the byte representation is correct.
- match = CONTENT_TYPE_RE.match(content_type)
- if match:
- charset = match.group(1)
- else:
- charset = settings.DEFAULT_CHARSET
- post_data = smart_str(data, encoding=charset)
+ post_data = self._encode_data(data, content_type)
parsed = urlparse(path)
r = {
@@ -286,25 +289,16 @@ class RequestFactory(object):
**extra):
"Construct a PUT request."
- if content_type is MULTIPART_CONTENT:
- post_data = encode_multipart(BOUNDARY, data)
- else:
- post_data = data
-
- # Make `data` into a querystring only if it's not already a string. If
- # it is a string, we'll assume that the caller has already encoded it.
- query_string = None
- if not isinstance(data, basestring):
- query_string = urlencode(data, doseq=True)
+ put_data = self._encode_data(data, content_type)
parsed = urlparse(path)
r = {
- 'CONTENT_LENGTH': len(post_data),
+ 'CONTENT_LENGTH': len(put_data),
'CONTENT_TYPE': content_type,
'PATH_INFO': self._get_path(parsed),
- 'QUERY_STRING': query_string or parsed[4],
+ 'QUERY_STRING': parsed[4],
'REQUEST_METHOD': 'PUT',
- 'wsgi.input': FakePayload(post_data),
+ 'wsgi.input': FakePayload(put_data),
}
r.update(extra)
return self.request(**r)