summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-08-06 17:14:02 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-08-06 17:14:02 +0000
commit917f433727b485ea3bb14bb74dcfcbcd5f789de8 (patch)
tree2a5740658f1757a08abaedc4ca8fb35b17dbcaa6 /django
parent7c03f1c97a7d4829db4d7a921d6db7471f7d3453 (diff)
Fixed #11159 -- Added mimetype detection to the test client for file uploads. Thanks to notanumber for the report and patch, and lomin for the test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13517 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/test/client.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/test/client.py b/django/test/client.py
index e5a16b6e79..498af5c344 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -3,6 +3,7 @@ from urlparse import urlparse, urlunparse, urlsplit
import sys
import os
import re
+import mimetypes
try:
from cStringIO import StringIO
except ImportError:
@@ -138,11 +139,14 @@ def encode_multipart(boundary, data):
def encode_file(boundary, key, file):
to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET)
+ content_type = mimetypes.guess_type(file.name)[0]
+ if content_type is None:
+ content_type = 'application/octet-stream'
return [
'--' + boundary,
'Content-Disposition: form-data; name="%s"; filename="%s"' \
% (to_str(key), to_str(os.path.basename(file.name))),
- 'Content-Type: application/octet-stream',
+ 'Content-Type: %s' % content_type,
'',
file.read()
]