Ticket #7812: inmemoryupload_fileseek_testcases-r7977.patch

File inmemoryupload_fileseek_testcases-r7977.patch, 2.2 KB (added by Ivan Giuliani, 16 years ago)

Test cases for this ticket

  • tests/regressiontests/file_uploads/views.py

     
    7878    for key in request.FILES.keys():
    7979        file_counts[key] = len(request.FILES.getlist(key))
    8080    return HttpResponse(simplejson.dumps(file_counts))
     81
     82def file_upload_not_empty_read(request):
     83    "Check that the .read() doesn't return an empty string over uploaded files"
     84    for key in request.FILES.keys():
     85        if request.FILES[key].read() == '':
     86            return HttpResponseServerError()
     87
     88    return HttpResponse('')
  • tests/regressiontests/file_uploads/tests.py

     
    179179
    180180        self.assertEqual(got.get('file1'), 1)
    181181        self.assertEqual(got.get('file2'), 2)
     182
     183    def test_fileupload_seek(self):
     184        # small file (under the 5M quota)
     185        small_f = tempfile.NamedTemporaryFile()
     186        small_f.write('a' * (2 ** 10))
     187
     188        response = self.client.post('/file_uploads/notempty/', {
     189            'small_f': open(small_f.name)
     190        })
     191        self.assertEqual(response.status_code, 200)
     192
     193        # big file (over the 5M quota)
     194        big_f = tempfile.NamedTemporaryFile()
     195        big_f.write('a' * (10 * 2 ** 20))
     196
     197        response = self.client.post('/file_uploads/notempty/', {
     198            'big_': open(big_f.name)
     199        })
     200        self.assertEqual(response.status_code, 200)
  • tests/regressiontests/file_uploads/urls.py

     
    88    (r'^quota/$',           views.file_upload_quota),
    99    (r'^quota/broken/$',    views.file_upload_quota_broken),
    1010    (r'^getlist_count/$',   views.file_upload_getlist_count),
     11    (r'^notempty/$',        views.file_upload_not_empty_read),
    1112)
Back to Top