1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #35139 -- Prevented file read after ImageField is saved to storage.

This commit is contained in:
John Parton
2024-01-24 16:22:07 -06:00
committed by Sarah Boyce
parent 4971a9afe5
commit 9c5fe93349
5 changed files with 65 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ if Image:
from .models import (
Person,
PersonDimensionsFirst,
PersonNoReadImage,
PersonTwoImages,
PersonWithHeight,
PersonWithHeightAndWidth,
@@ -30,7 +31,7 @@ else:
pass
PersonWithHeight = PersonWithHeightAndWidth = PersonDimensionsFirst = Person
PersonTwoImages = Person
PersonTwoImages = PersonNoReadImage = Person
class ImageFieldTestMixin(SerializeMixin):
@@ -469,3 +470,28 @@ class TwoImageFieldTests(ImageFieldTestMixin, TestCase):
# Dimensions were recalculated, and hence file should have opened.
self.assertIs(p.mugshot.was_opened, True)
self.assertIs(p.headshot.was_opened, True)
@skipIf(Image is None, "Pillow is required to test ImageField")
class NoReadTests(ImageFieldTestMixin, TestCase):
def test_width_height_correct_name_mangling_correct(self):
instance1 = PersonNoReadImage()
instance1.mugshot.save("mug", self.file1)
self.assertEqual(instance1.mugshot_width, 4)
self.assertEqual(instance1.mugshot_height, 8)
instance1.save()
self.assertEqual(instance1.mugshot_width, 4)
self.assertEqual(instance1.mugshot_height, 8)
instance2 = PersonNoReadImage()
instance2.mugshot.save("mug", self.file1)
instance2.save()
self.assertNotEqual(instance1.mugshot.name, instance2.mugshot.name)
self.assertEqual(instance1.mugshot_width, instance2.mugshot_width)
self.assertEqual(instance1.mugshot_height, instance2.mugshot_height)