diff options
| author | Andriy Sokolovskiy <me@asokolovskiy.com> | 2015-06-16 18:24:59 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-06-16 14:38:25 -0400 |
| commit | 8abe2d0643a9ad9986e5b12644dbe0d0fc8b5f5d (patch) | |
| tree | 3a0b1df6c9e9cc7470e4fd4f4d5dba32415e26f1 /tests | |
| parent | 8050e6282e4daee24758a4a1c6c2fa938957bef2 (diff) | |
[1.8.x] Fixed #24948 -- Fixed crash when uploading bitmap images in forms.ImageField
Backport of cf6ce279c7671a4c83c960c5c526f92679a4fac8 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/forms_tests/tests/filepath_test_files/1x1.bmp | bin | 0 -> 58 bytes | |||
| -rw-r--r-- | tests/forms_tests/tests/test_fields.py | 21 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/filepath_test_files/1x1.bmp b/tests/forms_tests/tests/filepath_test_files/1x1.bmp Binary files differnew file mode 100644 index 0000000000..021d5fa928 --- /dev/null +++ b/tests/forms_tests/tests/filepath_test_files/1x1.bmp diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py index 1d09b1a8b3..b082701c11 100644 --- a/tests/forms_tests/tests/test_fields.py +++ b/tests/forms_tests/tests/test_fields.py @@ -806,6 +806,26 @@ class FieldsTests(SimpleTestCase): self.assertEqual('PNG', uploaded_file.image.format) self.assertEqual('image/png', uploaded_file.content_type) + @skipIf(Image is None, "Pillow is required to test ImageField") + def test_imagefield_annotate_with_bitmap_image_after_clean(self): + """ + This also tests the situation when Pillow doesn't detect the MIME type + of the image (#24948). + """ + f = ImageField() + + img_path = os.path.dirname(upath(__file__)) + '/filepath_test_files/1x1.bmp' + with open(img_path, 'rb') as img_file: + img_data = img_file.read() + + img_file = SimpleUploadedFile('1x1.bmp', img_data) + img_file.content_type = 'text/plain' + + uploaded_file = f.clean(img_file) + + self.assertEqual('BMP', uploaded_file.image.format) + self.assertIsNone(uploaded_file.content_type) + # URLField ################################################################## def test_urlfield_1(self): @@ -1347,6 +1367,7 @@ class FieldsTests(SimpleTestCase): f.choices.sort() expected = [ ('/tests/forms_tests/tests/filepath_test_files/.dot-file', '.dot-file'), + ('/tests/forms_tests/tests/filepath_test_files/1x1.bmp', '1x1.bmp'), ('/tests/forms_tests/tests/filepath_test_files/1x1.png', '1x1.png'), ('/tests/forms_tests/tests/filepath_test_files/directory', 'directory'), ('/tests/forms_tests/tests/filepath_test_files/fake-image.jpg', 'fake-image.jpg'), |
