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

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

Test client patch to add content-type in encode_file function

  • build/site/src/django-1.0.2-1.0.0FINAL/django/test/client.py

    diff --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
    index 282e668..03d8843 100644
    a b  
    11import urllib
    22import sys
    33import os
     4import mimetypes
    45try:
    56    from cStringIO import StringIO
    67except ImportError:
    def encode_multipart(boundary, data):  
    127128    ])
    128129    return '\r\n'.join(lines)
    129130
     131
    130132def encode_file(boundary, key, file):
    131133    to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET)
    132134    return [
    133135        '--' + boundary,
    134136        'Content-Disposition: form-data; name="%s"; filename="%s"' \
    135137            % (to_str(key), to_str(os.path.basename(file.name))),
    136         'Content-Type: application/octet-stream',
     138        'Content-Type: %s' % mimetypes.guess_type(file.name)[0] or 'application/octet-stream',
    137139        '',
    138140        file.read()
    139141    ]
    140142
     143
    141144class Client(object):
    142145    """
    143146    A class that can act as a client for testing purposes.
Back to Top