Ticket #13750: regression_13750.diff

File regression_13750.diff, 1.3 KB (added by Aksel, 9 years ago)

Test to replicate the behaviour described in the ticket

  • tests/model_fields/models.py

    diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py
    index 4208454..daf9ea8 100644
    a b class AbstractForeignFieldsModel(models.Model):  
    384384
    385385    class Meta:
    386386        abstract = True
     387
     388
     389class Profile(models.Model):
     390    image = models.ImageField()
  • tests/model_fields/test_imagefield.py

    diff --git a/tests/model_fields/test_imagefield.py b/tests/model_fields/test_imagefield.py
    index 7389573..e0c229a 100644
    a b class ImageFieldTests(ImageFieldTestMixin, TestCase):  
    181181        loaded_p = pickle.loads(dump)
    182182        self.assertEqual(p.mugshot, loaded_p.mugshot)
    183183
     184    def test_image_field_io_closed_file(self):
     185        """
     186        Opening 'image' property as Image object of a model's ImageField will fail
     187        with an 'I/O operation on closed file' error. Regression for #13750
     188        """
     189        from .models import Profile
     190        profile = Profile()
     191        profile.image.save("test", self.file1)
     192
     193        w = profile.image.width
     194        h = profile.image.height
     195
     196        original = Image.open(profile.image)
     197
    184198
    185199@skipIf(Image is None, "Pillow is required to test ImageField")
    186200class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
Back to Top