mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Also test that get_route_paths() overrides are respected
This commit is contained in:
parent
dc62aeed02
commit
5f28eb6e4d
@ -5,6 +5,7 @@ from django.test import TestCase, override_settings
|
||||
from wagtail.contrib.redirects.models import Redirect
|
||||
from wagtail.core.models import Page, Site
|
||||
from wagtail.core.utils import get_dummy_request
|
||||
from wagtail.tests.routablepage.models import RoutablePageTest
|
||||
from wagtail.tests.testapp.models import EventIndex
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
|
||||
@ -134,6 +135,27 @@ class TestAutocreateRedirects(TestCase, WagtailTestUtils):
|
||||
).exists()
|
||||
)
|
||||
|
||||
def test_redirect_creation_for_custom_route_paths(self):
|
||||
# Add a page that has overridden get_route_paths()
|
||||
homepage = Page.objects.get(id=2)
|
||||
routable_page = homepage.add_child(instance=RoutablePageTest(
|
||||
title="Routable Page",
|
||||
live=True,
|
||||
))
|
||||
|
||||
# Move from below the homepage to below the event index
|
||||
routable_page.move(self.event_index, pos="last-child")
|
||||
|
||||
# Redirects should have been created for each path returned by get_route_paths()
|
||||
self.assertEqual(
|
||||
list(Redirect.objects.all().values_list("old_path", "redirect_page", "redirect_page_route_path").order_by("redirect_page_route_path")),
|
||||
[
|
||||
("/routable-page", routable_page.id, ""),
|
||||
("/routable-page/not-a-valid-route", routable_page.id, "/not-a-valid-route"),
|
||||
("/routable-page/render-method-test", routable_page.id, "/render-method-test/"),
|
||||
]
|
||||
)
|
||||
|
||||
def test_no_redirects_created_when_pages_are_moved_to_a_different_site(self):
|
||||
|
||||
# Add a new home page
|
||||
|
@ -47,6 +47,13 @@ class RoutablePageTest(RoutablePage):
|
||||
template="routablepagetests/routable_page_test_alternate.html"
|
||||
)
|
||||
|
||||
def get_route_paths(self):
|
||||
return [
|
||||
"/",
|
||||
"/render-method-test/",
|
||||
"not-a-valid-route",
|
||||
]
|
||||
|
||||
|
||||
class RoutablePageWithOverriddenIndexRouteTest(RoutablePage):
|
||||
@route(r'^$')
|
||||
|
Loading…
Reference in New Issue
Block a user