Ticket #9591: 9591-test.diff

File 9591-test.diff, 2.2 KB (added by mmarshall, 16 years ago)

Simple test

  • tests/regressiontests/file_uploads/views.py

     
    44from django.utils import simplejson
    55from models import FileModel
    66from uploadhandler import QuotaUploadHandler, ErroringUploadHandler
     7from django.core.files.uploadhandler import MemoryFileUploadHandler
    78from django.utils.hashcompat import sha_constructor
    89from tests import UNICODE_FILENAME
    910
     
    111112def file_upload_errors(request):
    112113    request.upload_handlers.insert(0, ErroringUploadHandler())
    113114    return file_upload_echo(request)
     115
     116def file_upload_memory_position(request):
     117    request.upload_handlers.insert(0, MemoryFileUploadHandler())
     118    return HttpResponse(str(request.FILES['file_field'].tell()))
     119
  • tests/regressiontests/file_uploads/tests.py

     
    249249            # CustomUploadError is the error that should have been raised
    250250            self.assertEqual(err.__class__, uploadhandler.CustomUploadError)
    251251
     252    def test_memory_position(self):
     253        post_data = {
     254            'name': 'Ringo',
     255            'file_field': open(__file__),
     256        }
     257        response = self.client.post('/file_uploads/memory_position/', post_data)
     258        self.assertEqual(response.content, "0")
     259
    252260class DirectoryCreationTests(unittest.TestCase):
    253261    """
    254262    Tests for error handling during directory creation
  • tests/regressiontests/file_uploads/urls.py

     
    1010    (r'^quota/broken/$',    views.file_upload_quota_broken),
    1111    (r'^getlist_count/$',   views.file_upload_getlist_count),
    1212    (r'^upload_errors/$',   views.file_upload_errors),
     13    (r'^memory_position/$', views.file_upload_memory_position),
    1314)
     15
Back to Top