kopia lustrzana https://github.com/wagtail/wagtail
Add unit test for rendering image tag with a missing image
rodzic
c3b98e4467
commit
ff0c6db322
|
@ -81,7 +81,8 @@
|
|||
"audience": "public",
|
||||
"location": "The North Pole",
|
||||
"body": "<p>Chestnuts roasting on an open fire</p>",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load wagtailcore_tags %}
|
||||
{% load wagtailcore_tags wagtailimages_tags %}
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
@ -8,6 +8,9 @@
|
|||
<body>
|
||||
<h1>{{ self.title }}</h1>
|
||||
<h2>Event</h2>
|
||||
{% if self.feed_image %}
|
||||
{% image self.feed_image width-200 class="feed-image" %}
|
||||
{% endif %}
|
||||
<p><a href="{% slugurl 'events' %}">Back to events index</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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, '<img src="/media/not-found" width="0" height="0" alt="A missing image" class="feed-image">', html=True)
|
||||
|
||||
|
||||
class TestFormat(TestCase):
|
||||
def setUp(self):
|
||||
# test format
|
||||
|
|
Ładowanie…
Reference in New Issue