summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/forms_tests/field_tests/test_imagefield.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/forms_tests/field_tests/test_imagefield.py b/tests/forms_tests/field_tests/test_imagefield.py
index a1faefa2df..b134fedefc 100644
--- a/tests/forms_tests/field_tests/test_imagefield.py
+++ b/tests/forms_tests/field_tests/test_imagefield.py
@@ -1,7 +1,9 @@
import os
import unittest
-from django.core.files.uploadedfile import SimpleUploadedFile
+from django.core.files.uploadedfile import (
+ SimpleUploadedFile, TemporaryUploadedFile,
+)
from django.forms import (
ClearableFileInput, FileInput, ImageField, ValidationError, Widget,
)
@@ -69,6 +71,19 @@ class ImageFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
with self.assertRaisesMessage(ValidationError, 'File extension “txt” is not allowed.'):
f.clean(img_file)
+ def test_corrupted_image(self):
+ f = ImageField()
+ img_file = SimpleUploadedFile('not_an_image.jpg', b'not an image')
+ msg = (
+ 'Upload a valid image. The file you uploaded was either not an '
+ 'image or a corrupted image.'
+ )
+ with self.assertRaisesMessage(ValidationError, msg):
+ f.clean(img_file)
+ with TemporaryUploadedFile('not_an_image_tmp.png', 'text/plain', 1, 'utf-8') as tmp_file:
+ with self.assertRaisesMessage(ValidationError, msg):
+ f.clean(tmp_file)
+
def test_widget_attrs_default_accept(self):
f = ImageField()
# Nothing added for non-FileInput widgets.