Code

Ticket #11159: test-client-content-type.diff

File test-client-content-type.diff, 1.1 KB (added by notanumber, 5 years ago)

Test client patch to add content-type in encode_file function

Line 
1diff --git a/build/site/src/django-1.0.2-1.0.0FINAL/django/test/client.py b/build/site/src/django-1.0.2-1.0.0FINAL/django/test/client.py
2index 282e668..03d8843 100644
3--- a/build/site/src/django-1.0.2-1.0.0FINAL/django/test/client.py
4+++ b/build/site/src/django-1.0.2-1.0.0FINAL/django/test/client.py
5@@ -1,6 +1,7 @@
6 import urllib
7 import sys
8 import os
9+import mimetypes
10 try:
11     from cStringIO import StringIO
12 except ImportError:
13@@ -127,17 +128,19 @@ def encode_multipart(boundary, data):
14     ])
15     return '\r\n'.join(lines)
16 
17+
18 def encode_file(boundary, key, file):
19     to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET)
20     return [
21         '--' + boundary,
22         'Content-Disposition: form-data; name="%s"; filename="%s"' \
23             % (to_str(key), to_str(os.path.basename(file.name))),
24-        'Content-Type: application/octet-stream',
25+        'Content-Type: %s' % mimetypes.guess_type(file.name)[0] or 'application/octet-stream',
26         '',
27         file.read()
28     ]
29 
30+
31 class Client(object):
32     """
33     A class that can act as a client for testing purposes.