Add test case for `pageurl` not being called with a page

pull/9845/head
Jake Howard 2022-12-16 12:34:35 +00:00 zatwierdzone przez Matt Westcott
rodzic 14be13391d
commit 0b44b20367
1 zmienionych plików z 16 dodań i 2 usunięć

Wyświetl plik

@ -204,12 +204,12 @@ class TestPageUrlTags(TestCase):
def test_fullpageurl(self):
tpl = template.Template(
"""{% load wagtailcore_tags %}<a href="{% fullpageurl page %}">Fallback</a>"""
"""{% load wagtailcore_tags %}<a href="{% fullpageurl page %}">Events</a>"""
)
page = Page.objects.get(url_path="/home/events/")
with self.assertNumQueries(7):
result = tpl.render(template.Context({"page": page}))
self.assertIn('<a href="http://localhost/events/">Fallback</a>', result)
self.assertIn('<a href="http://localhost/events/">Events</a>', result)
def test_fullpageurl_with_named_url_fallback(self):
tpl = template.Template(
@ -229,6 +229,20 @@ class TestPageUrlTags(TestCase):
)
self.assertIn('<a href="http://localhost/fallback/">Fallback</a>', result)
def test_fullpageurl_with_invalid_page(self):
tpl = template.Template(
"""{% load wagtailcore_tags %}<a href="{% fullpageurl page %}">Events</a>"""
)
with self.assertRaises(ValueError):
tpl.render(template.Context({"page": 123}))
def test_pageurl_with_invalid_page(self):
tpl = template.Template(
"""{% load wagtailcore_tags %}<a href="{% pageurl page %}">Events</a>"""
)
with self.assertRaises(ValueError):
tpl.render(template.Context({"page": 123}))
class TestWagtailSiteTag(TestCase):
fixtures = ["test.json"]