From 917f433727b485ea3bb14bb74dcfcbcd5f789de8 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 6 Aug 2010 17:14:02 +0000 Subject: 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 --- django/test/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'django/test') 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() ] -- cgit v1.3