diff options
| author | David Smith <smithdc@gmail.com> | 2020-04-07 21:38:14 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-04-09 08:45:31 +0200 |
| commit | 911545da1d8d263f650721f6985e1d43e84d68eb (patch) | |
| tree | 47275088ce35b8a6678c405fbaf87389c0dd33e5 /tests/forms_tests/field_tests/test_imagefield.py | |
| parent | 4bbe8261c402694a1da3efcaafe3332f9c57af15 (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.py | 17 |
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. |
