summaryrefslogtreecommitdiff
path: root/tests/forms_tests/field_tests/test_imagefield.py
diff options
context:
space:
mode:
authorDavid Smith <smithdc@gmail.com>2020-04-07 21:38:14 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-04-09 08:45:31 +0200
commit911545da1d8d263f650721f6985e1d43e84d68eb (patch)
tree47275088ce35b8a6678c405fbaf87389c0dd33e5 /tests/forms_tests/field_tests/test_imagefield.py
parent4bbe8261c402694a1da3efcaafe3332f9c57af15 (diff)
Increased test coverage for forms.ImageField.to_python().
Diffstat (limited to 'tests/forms_tests/field_tests/test_imagefield.py')
-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.