Django

Code

Changeset 8304

Show
Ignore:
Timestamp:
08/11/08 10:24:46 (4 months ago)
Author:
gwilson
Message:

Refs #7742 -- Got bug639 regression tests using newforms instead of oldforms.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/regressiontests/bug639/models.py

    r8244 r8304  
    33from django.db import models 
    44from django.core.files.storage import FileSystemStorage 
     5from django.forms import ModelForm 
    56 
    67temp_storage = FileSystemStorage(tempfile.gettempdir()) 
     
    910    title = models.CharField(max_length=30) 
    1011    image = models.FileField(storage=temp_storage, upload_to='tests') 
    11      
    12     # Support code for the tests; this keeps track of how many times save() gets 
    13     # 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. 
    1415    def __init__(self, *args, **kwargs): 
    1516        super(Photo, self).__init__(*args, **kwargs) 
    1617        self._savecount = 0 
    17      
     18 
    1819    def save(self): 
    1920        super(Photo, self).save() 
    2021        self._savecount += 1 
     22 
     23class PhotoForm(ModelForm): 
     24    class Meta: 
     25        model = Photo 
  • django/trunk/tests/regressiontests/bug639/tests.py

    r8244 r8304  
    11""" 
    2 Tests for file field behavior, and specifically #639, in which Model.save() gets 
    3 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. 
     2Tests for file field behavior, and specifically #639, in which Model.save() 
     3gets called *again* for each FileField. This test will fail if calling a 
     4ModelForm's save() method causes Model.save() to be called more than once. 
    55""" 
    66 
    77import os 
    88import unittest 
    9 from regressiontests.bug639.models import Photo 
    10 from django.http import QueryDict 
    11 from django.utils.datastructures import MultiValueDict 
     9 
    1210from django.core.files.uploadedfile import SimpleUploadedFile 
     11from regressiontests.bug639.models import Photo, PhotoForm 
    1312 
    1413class Bug639Test(unittest.TestCase): 
    15          
     14 
    1615    def testBug639(self): 
    1716        """ 
    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. 
    1919        """ 
    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() 
    2623 
    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). 
    3232        self.assertEqual(p._savecount, 1) 
    33          
     33 
    3434    def tearDown(self): 
    3535        """