From ff0c6db3223339f98893907be219c7b635f92943 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Thu, 13 Nov 2014 15:15:25 +0000 Subject: [PATCH] Add unit test for rendering image tag with a missing image --- wagtail/tests/fixtures/test.json | 14 +++++++++++++- wagtail/tests/templates/tests/event_page.html | 5 ++++- wagtail/wagtailimages/tests/tests.py | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/wagtail/tests/fixtures/test.json b/wagtail/tests/fixtures/test.json index d16affe480..b2e0d6f4f5 100644 --- a/wagtail/tests/fixtures/test.json +++ b/wagtail/tests/fixtures/test.json @@ -81,7 +81,8 @@ "audience": "public", "location": "The North Pole", "body": "

Chestnuts roasting on an open fire

", - "cost": "Free" + "cost": "Free", + "feed_image": 1 } }, @@ -625,5 +626,16 @@ "page": 11, "password": "swordfish" } +}, +{ + "pk": 1, + "model": "wagtailimages.image", + "fields": { + "title": "A missing image", + "file": "original_images/missing.jpg", + "width": 1000, + "height": 1000, + "created_at": "2014-01-01T12:00:00.000Z" + } } ] diff --git a/wagtail/tests/templates/tests/event_page.html b/wagtail/tests/templates/tests/event_page.html index 795b7bf0a7..fd8f9bd757 100644 --- a/wagtail/tests/templates/tests/event_page.html +++ b/wagtail/tests/templates/tests/event_page.html @@ -1,4 +1,4 @@ -{% load wagtailcore_tags %} +{% load wagtailcore_tags wagtailimages_tags %} @@ -8,6 +8,9 @@

{{ self.title }}

Event

+ {% if self.feed_image %} + {% image self.feed_image width-200 class="feed-image" %} + {% endif %}

Back to events index

diff --git a/wagtail/wagtailimages/tests/tests.py b/wagtail/wagtailimages/tests/tests.py index 1030a3b7ef..2c75b0611f 100644 --- a/wagtail/wagtailimages/tests/tests.py +++ b/wagtail/wagtailimages/tests/tests.py @@ -63,6 +63,20 @@ class TestImageTag(TestCase): self.assertTrue('title="my wonderful title"' in result) +class TestMissingImage(TestCase): + """ + Missing image files in media/original_images should be handled gracefully, to cope with + pulling live databases to a development instance without copying the corresponding image files. + In this case, it's acceptable to render broken images, but not to fail rendering the page outright. + """ + fixtures = ['test.json'] + + def test_image_tag_with_missing_image(self): + # the page /events/christmas/ has a missing image as the feed image + response = self.client.get('/events/christmas/') + self.assertContains(response, 'A missing image', html=True) + + class TestFormat(TestCase): def setUp(self): # test format