summaryrefslogtreecommitdiff
path: root/tests/model_forms/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_forms/tests.py')
-rw-r--r--tests/model_forms/tests.py32
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)