Code

Ticket #7812: r8161-seek-testcase-fixed.patch

File r8161-seek-testcase-fixed.patch, 2.5 KB (added by kratorius, 6 years ago)

Fixed testcase

  • 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    """ 
     84    Check that the first .read() returns the whole file (because we don't specify 
     85    the size to read, so we read the entire file), while the second returns an 
     86    empty string 
     87    """ 
     88    for key in request.FILES.keys(): 
     89        if request.FILES[key].read() == '': 
     90            return HttpResponseServerError() 
     91        if request.FILES[key].read() != '': 
     92            return HttpResponseServerError() 
     93 
     94    return HttpResponse('') 
  • tests/regressiontests/file_uploads/tests.py

     
    187187        self.assertEqual(got.get('file1'), 1) 
    188188        self.assertEqual(got.get('file2'), 2) 
    189189 
     190    def test_fileupload_seek(self): 
     191        # small file (under the 5M quota) 
     192        small_f = tempfile.NamedTemporaryFile() 
     193        small_f.write('a' * (2 ** 10)) 
     194        small_f.seek(0) 
     195 
     196        response = self.client.post('/file_uploads/notempty/', { 
     197            'small_f': open(small_f.name) 
     198        }) 
     199        self.assertEqual(response.status_code, 200) 
     200 
     201        # big file (over the 5M quota) 
     202        big_f = tempfile.NamedTemporaryFile() 
     203        big_f.write('a' * (10 * 2 ** 20)) 
     204        big_f.seek(0) 
     205 
     206        response = self.client.post('/file_uploads/notempty/', { 
     207            'big_f': open(big_f.name) 
     208        }) 
     209        self.assertEqual(response.status_code, 200) 
     210 
    190211class DirectoryCreationTests(unittest.TestCase): 
    191212    """ 
    192213    Tests for error handling during directory creation 
  • 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)