kopia lustrzana https://github.com/wagtail/wagtail
get_willow_image now raises SourceImageIOError
... when the source image cannot be found in the filesystempull/898/merge
rodzic
aa9e6ce7bf
commit
d751e76298
|
@ -82,7 +82,13 @@ class AbstractImage(models.Model, TagSearchable):
|
|||
return self.title
|
||||
|
||||
def get_willow_image(self):
|
||||
image_file = self.file.file
|
||||
try:
|
||||
image_file = self.file.file # triggers a call to self.storage.open, so IOErrors from missing files will be raised at this point
|
||||
except IOError as e:
|
||||
# re-throw this as a SourceImageIOError so that calling code can distinguish
|
||||
# these from IOErrors elsewhere in the process
|
||||
raise SourceImageIOError(text_type(e))
|
||||
|
||||
image_file.open('rb')
|
||||
image_file.seek(0)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ from django.db import connection
|
|||
from wagtail.tests.utils import WagtailTestUtils, test_concurrently
|
||||
from wagtail.wagtailcore.models import Page
|
||||
from wagtail.tests.models import EventPage, EventPageCarouselItem
|
||||
from wagtail.wagtailimages.models import Rendition, Filter
|
||||
from wagtail.wagtailimages.models import Rendition, Filter, SourceImageIOError
|
||||
from wagtail.wagtailimages.backends import get_image_backend
|
||||
from wagtail.wagtailimages.backends.pillow import PillowBackend
|
||||
from wagtail.wagtailimages.rect import Rect
|
||||
|
@ -269,7 +269,9 @@ class TestGetUsage(TestCase):
|
|||
self.assertTrue(issubclass(Page, type(self.image.get_usage()[0])))
|
||||
|
||||
|
||||
def TestGetWillowImage(TestCase):
|
||||
class TestGetWillowImage(TestCase):
|
||||
fixtures = ['test.json']
|
||||
|
||||
def setUp(self):
|
||||
self.image = Image.objects.create(
|
||||
title="Test image",
|
||||
|
@ -281,6 +283,14 @@ def TestGetWillowImage(TestCase):
|
|||
|
||||
self.assertIsInstance(willow_image, WillowImage)
|
||||
|
||||
def test_with_missing_image(self):
|
||||
# Image id=1 in test fixtures has a missing image file
|
||||
bad_image = Image.objects.get(id=1)
|
||||
|
||||
# Attempting to get the Willow image for images without files
|
||||
# should raise a SourceImageIOError
|
||||
self.assertRaises(SourceImageIOError, bad_image.get_willow_image)
|
||||
|
||||
|
||||
class TestIssue573(TestCase):
|
||||
"""
|
||||
|
|
Ładowanie…
Reference in New Issue