Ticket #422: empty_file_field_error.patch

File empty_file_field_error.patch, 1.8 KB (added by al, 2 years ago)
  • tests/test_file_upload.py

    diff -r e695e5b1ed4d tests/test_file_upload.py
    a b  
    136136 
    137137def test_no_uploads_error(): 
    138138    app = webtest.TestApp(single_upload_file_app) 
    139     uploads = app.get('/').forms["file_upload_form"].upload_fields() 
     139    single_form = app.get('/').forms["file_upload_form"] 
     140    single_form.submit("button") 
    140141 
    141142 
    142143def test_file_upload_with_filename_only(): 
  • webtest/__init__.py

    diff -r e695e5b1ed4d webtest/__init__.py
    a b  
    252252            lines.append('') 
    253253            lines.append(value) 
    254254        for file_info in files: 
    255             key, filename, value = self._get_file_info(file_info) 
    256             lines.append('--'+boundary) 
    257             lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' 
    258                          % (key, filename)) 
    259             fcontent = mimetypes.guess_type(filename)[0] 
    260             lines.append('Content-Type: %s' % 
    261                          fcontent or 'application/octet-stream') 
    262             lines.append('') 
    263             lines.append(value) 
     255            if len(file_info) > 1: 
     256                key, filename, value = self._get_file_info(file_info) 
     257                lines.append('--'+boundary) 
     258                lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' 
     259                             % (key, filename)) 
     260                fcontent = mimetypes.guess_type(filename)[0] 
     261                lines.append('Content-Type: %s' % 
     262                             fcontent or 'application/octet-stream') 
     263                lines.append('') 
     264                lines.append(value) 
    264265        lines.append('--' + boundary + '--') 
    265266        lines.append('') 
    266267        body = '\r\n'.join(lines)