Increased test coverage for forms.ImageField.to_python().
This commit is contained in:
parent
4bbe8261c4
commit
911545da1d
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue