Ticket #7812: r8161-seek-testcase-fixed.patch
File r8161-seek-testcase-fixed.patch, 2.5 KB (added by , 16 years ago) |
---|
-
tests/regressiontests/file_uploads/views.py
78 78 for key in request.FILES.keys(): 79 79 file_counts[key] = len(request.FILES.getlist(key)) 80 80 return HttpResponse(simplejson.dumps(file_counts)) 81 82 def 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
187 187 self.assertEqual(got.get('file1'), 1) 188 188 self.assertEqual(got.get('file2'), 2) 189 189 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 190 211 class DirectoryCreationTests(unittest.TestCase): 191 212 """ 192 213 Tests for error handling during directory creation -
tests/regressiontests/file_uploads/urls.py
8 8 (r'^quota/$', views.file_upload_quota), 9 9 (r'^quota/broken/$', views.file_upload_quota_broken), 10 10 (r'^getlist_count/$', views.file_upload_getlist_count), 11 (r'^notempty/$', views.file_upload_not_empty_read), 11 12 )