diff options
| author | Tushar Bhatia <tushar747@gmail.com> | 2014-07-26 09:23:01 +0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-07-26 21:10:03 -0400 |
| commit | df0d5ea7bc9821923c70e7bf06d3646598cf019d (patch) | |
| tree | 88fe0569b34b169e09454095b31bb082923549e0 /tests/model_forms/tests.py | |
| parent | 30ccb36cb9c1bc9bd30edb2b67f26ef2a1e4fb53 (diff) | |
[1.7.x] Fixed #22979 -- Moved bug* tests
Backport of 11181a64f from master.
Diffstat (limited to 'tests/model_forms/tests.py')
| -rw-r--r-- | tests/model_forms/tests.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index dc912c0cd6..f05307851f 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -22,7 +22,7 @@ from django.utils import six from .models import (Article, ArticleStatus, Author, Author1, BetterWriter, BigInt, Book, Category, CommaSeparatedInteger, CustomFF, CustomFieldForExclusionModel, DerivedBook, DerivedPost, Document, ExplicitPK, FilePathModel, FlexibleDatePost, Homepage, - ImprovedArticle, ImprovedArticleWithParentLink, Inventory, Person, Post, Price, + ImprovedArticle, ImprovedArticleWithParentLink, Inventory, Person, Photo, Post, Price, Product, Publication, TextFile, Triple, Writer, WriterProfile, Colour, ColourfulItem, ArticleStatusNote, DateTimePost, CustomErrorMessage, test_images, StumpJoke, Character) @@ -1838,6 +1838,36 @@ class FileAndImageFieldTests(TestCase): form = CFFForm(data={'f': None}) form.save() + def test_file_field_multiple_save(self): + """ + Simulate a file upload and check how many times Model.save() gets + called. Test for bug #639. + """ + class PhotoForm(forms.ModelForm): + class Meta: + model = Photo + fields = '__all__' + + # Grab an image for testing. + filename = os.path.join(os.path.dirname(upath(__file__)), "test.png") + with open(filename, "rb") as fp: + img = fp.read() + + # Fake a POST QueryDict and FILES MultiValueDict. + data = {'title': 'Testing'} + files = {"image": SimpleUploadedFile('test.png', img, 'image/png')} + + form = PhotoForm(data=data, files=files) + p = form.save() + + try: + # Check the savecount stored on the object (see the model). + self.assertEqual(p._savecount, 1) + finally: + # Delete the "uploaded" file to avoid clogging /tmp. + p = Photo.objects.get() + p.image.delete(save=False) + def test_file_path_field_blank(self): """ Regression test for #8842: FilePathField(blank=True) |
