diff --git a/wagtail/contrib/redirects/tests/test_signal_handlers.py b/wagtail/contrib/redirects/tests/test_signal_handlers.py index 859f5c21f9..9c99486ae7 100644 --- a/wagtail/contrib/redirects/tests/test_signal_handlers.py +++ b/wagtail/contrib/redirects/tests/test_signal_handlers.py @@ -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 diff --git a/wagtail/tests/routablepage/models.py b/wagtail/tests/routablepage/models.py index 44ff93ef26..58a7586cd9 100644 --- a/wagtail/tests/routablepage/models.py +++ b/wagtail/tests/routablepage/models.py @@ -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'^$')