Django

Code

Changeset 7577

Show
Ignore:
Timestamp:
06/06/08 08:39:42 (6 months ago)
Author:
russellm
Message:

Fixed #7143 -- Modified the test client to better match (most) real browser behavior when uploading files. Now, only the file name is sent, rather than the full path. Thanks for the report, cpinto.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/test/client.py

    r7330 r7577  
    11import urllib 
    22import sys 
     3import os 
    34from cStringIO import StringIO 
    45from django.conf import settings 
     
    6869            lines.extend([ 
    6970                '--' + boundary, 
    70                 'Content-Disposition: form-data; name="%s"; filename="%s"' % (to_str(key), to_str(value.name)), 
     71                'Content-Disposition: form-data; name="%s"; filename="%s"' % (to_str(key), to_str(os.path.basename(value.name))), 
    7172                'Content-Type: application/octet-stream', 
    7273                '', 
  • django/trunk/tests/regressiontests/test_client_regress/views.py

    r7330 r7577  
     1import os 
     2 
    13from django.contrib.auth.decorators import login_required 
    24from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError 
     
    1416    form_data.update(request.FILES) 
    1517    if isinstance(form_data['file_field'], dict) and isinstance(form_data['name'], unicode): 
     18        # If a file is posted, the dummy client should only post the file name, 
     19        # not the full path. 
     20        if os.path.dirname(form_data['file_field']['filename']) != '': 
     21            return HttpResponseServerError()             
    1622        return HttpResponse('') 
    1723    else: