Changeset 8304
- Timestamp:
- 08/11/08 10:24:46 (4 months ago)
- Files:
-
- django/trunk/tests/regressiontests/bug639/models.py (modified) (2 diffs)
- django/trunk/tests/regressiontests/bug639/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/tests/regressiontests/bug639/models.py
r8244 r8304 3 3 from django.db import models 4 4 from django.core.files.storage import FileSystemStorage 5 from django.forms import ModelForm 5 6 6 7 temp_storage = FileSystemStorage(tempfile.gettempdir()) … … 9 10 title = models.CharField(max_length=30) 10 11 image = models.FileField(storage=temp_storage, upload_to='tests') 11 12 # Support code for the tests; this keeps track of how many times save() gets13 # called on each instance.12 13 # Support code for the tests; this keeps track of how many times save() 14 # gets called on each instance. 14 15 def __init__(self, *args, **kwargs): 15 16 super(Photo, self).__init__(*args, **kwargs) 16 17 self._savecount = 0 17 18 18 19 def save(self): 19 20 super(Photo, self).save() 20 21 self._savecount += 1 22 23 class PhotoForm(ModelForm): 24 class Meta: 25 model = Photo django/trunk/tests/regressiontests/bug639/tests.py
r8244 r8304 1 1 """ 2 Tests for file field behavior, and specifically #639, in which Model.save() gets3 called *again* for each FileField. This test will fail if calling an 4 auto-manipulator's save() method causes Model.save() to be called more than once.2 Tests for file field behavior, and specifically #639, in which Model.save() 3 gets called *again* for each FileField. This test will fail if calling a 4 ModelForm's save() method causes Model.save() to be called more than once. 5 5 """ 6 6 7 7 import os 8 8 import unittest 9 from regressiontests.bug639.models import Photo 10 from django.http import QueryDict 11 from django.utils.datastructures import MultiValueDict 9 12 10 from django.core.files.uploadedfile import SimpleUploadedFile 11 from regressiontests.bug639.models import Photo, PhotoForm 13 12 14 13 class Bug639Test(unittest.TestCase): 15 14 16 15 def testBug639(self): 17 16 """ 18 Simulate a file upload and check how many times Model.save() gets called. 17 Simulate a file upload and check how many times Model.save() gets 18 called. 19 19 """ 20 # Grab an image for testing 21 img = open(os.path.join(os.path.dirname(__file__), "test.jpg"), "rb").read() 22 23 # Fake a request query dict with the file 24 qd = QueryDict("title=Testing&image=", mutable=True) 25 qd["image_file"] = SimpleUploadedFile('test.jpg', img, 'image/jpeg') 20 # Grab an image for testing. 21 filename = os.path.join(os.path.dirname(__file__), "test.jpg") 22 img = open(filename, "rb").read() 26 23 27 manip = Photo.AddManipulator() 28 manip.do_html2python(qd) 29 p = manip.save(qd) 30 31 # Check the savecount stored on the object (see the model) 24 # Fake a POST QueryDict and FILES MultiValueDict. 25 data = {'title': 'Testing'} 26 files = {"image": SimpleUploadedFile('test.jpg', img, 'image/jpeg')} 27 28 form = PhotoForm(data=data, files=files) 29 p = form.save() 30 31 # Check the savecount stored on the object (see the model). 32 32 self.assertEqual(p._savecount, 1) 33 33 34 34 def tearDown(self): 35 35 """
