From cca1e03df157ffad0aa73c49273288ade6b7a80d Mon Sep 17 00:00:00 2001
From: Felix Dreissig <f30@f30.me>
Date: Tue, 26 Mar 2019 12:47:54 +0100
Subject: [PATCH 1/2] Refs #30252 -- Added test demonstrating the issue
Added regression test demonstrating that the `image` attribute of a file
uploaded using ImageField does not contain a usable Image object at the
moment.
---
tests/forms_tests/field_tests/test_imagefield.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tests/forms_tests/field_tests/test_imagefield.py b/tests/forms_tests/field_tests/test_imagefield.py
index e38abc332d..5535508ad8 100644
a
|
b
|
class ImageFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
|
86 | 86 | f = ImageField(widget=FileInput(attrs={'accept': False})) |
87 | 87 | self.assertEqual(f.widget_attrs(f.widget), {}) |
88 | 88 | self.assertWidgetRendersTo(f, '<input type="file" name="f" required id="id_f" />') |
| 89 | |
| 90 | def test_image_attr_of_file(self): |
| 91 | """ |
| 92 | Checks if the `image` attribute of the uploaded file contains a usable |
| 93 | Image object after cleaning. Regression test for #30252. |
| 94 | """ |
| 95 | f = ImageField() |
| 96 | img_path = get_img_path('filepath_test_files/1x1.png') |
| 97 | with open(img_path, 'rb') as img_file: |
| 98 | img_data = img_file.read() |
| 99 | img_file = SimpleUploadedFile('1x1.png', img_data) |
| 100 | self.assertFalse(hasattr(img_file, 'image')) |
| 101 | f.clean(img_file) |
| 102 | self.assertIsNotNone(img_file.image.getpixel((0, 0))) |