diff --git a/pydotorg/tests/test_views.py b/pydotorg/tests/test_views.py index b21c54b57..997b60f39 100644 --- a/pydotorg/tests/test_views.py +++ b/pydotorg/tests/test_views.py @@ -34,3 +34,20 @@ def test_download_index(self): self.assertContains(response, "Browse Python 3.6.0 Documentation") self.assertContains(response, "https://docs.python.org/3/whatsnew/3.6.html") self.assertContains(response, "What's new in Python 3.6") + + def test_legacy_sponsor_redirects(self): + """Test that old sponsorship pages correctly redirect to modern active ones.""" + redirect_cases = ( + ("/psf/sponsorship-old/", "psf-sponsors"), + ("/psf/forms/sponsor-application/", "new_sponsorship_application"), + ) + + for source_path, target_name in redirect_cases: + with self.subTest(source_path=source_path, target_name=target_name): + response = self.client.get(source_path) + self.assertRedirects( + response, + reverse(target_name), + status_code=301, + fetch_redirect_response=False, + ) diff --git a/pydotorg/urls.py b/pydotorg/urls.py index 3cb9f32ea..5cbeab864 100644 --- a/pydotorg/urls.py +++ b/pydotorg/urls.py @@ -5,7 +5,7 @@ from django.contrib import admin from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.urls import include, path, re_path -from django.views.generic.base import TemplateView +from django.views.generic.base import RedirectView, TemplateView from apps.cms.views import custom_404 from apps.downloads.views import ReleaseEditButton @@ -35,6 +35,14 @@ path("blogs/", include("apps.blogs.urls")), path("inner/", TemplateView.as_view(template_name="python/inner.html"), name="inner"), # other section landing pages + path( + "psf/sponsorship-old/", + RedirectView.as_view(url="/psf/sponsorship/", permanent=True), + ), + path( + "psf/forms/sponsor-application/", + RedirectView.as_view(pattern_name="new_sponsorship_application", permanent=True), + ), path("psf-landing/", TemplateView.as_view(template_name="psf/index.html"), name="psf-landing"), path("psf/sponsors/", TemplateView.as_view(template_name="psf/sponsors-list.html"), name="psf-sponsors"), path("docs-landing/", TemplateView.as_view(template_name="docs/index.html"), name="docs-landing"),