diff options
-rw-r--r-- | pydis_site/apps/redirect/tests.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/pydis_site/apps/redirect/tests.py b/pydis_site/apps/redirect/tests.py index 6d670a82..a4bab933 100644 --- a/pydis_site/apps/redirect/tests.py +++ b/pydis_site/apps/redirect/tests.py @@ -2,9 +2,13 @@ from django.conf import settings from django.test import TestCase from django.urls import reverse +TESTING_ARGUMENTS = {"resources_resources_redirect": ("reading",)} + class RedirectTests(TestCase): - def test_redirects(self): + """Survival tests for redirects.""" + + def test_redirects(self) -> None: """ Should redirect to given route based on redirect rules. @@ -12,9 +16,28 @@ class RedirectTests(TestCase): 1. Redirects only once. 2. Redirects to right URL. """ - for original_path, (redirect_route, name, args) in settings.REDIRECTIONS.items(): - with self.subTest(original_path=original_path, redirect_route=redirect_route, name=name, args=args): - resp = self.client.get(reverse(f"home:redirect:{name}", args=args), follow=True) + for original_path, (redirect_route, name, static_args) in settings.REDIRECTIONS.items(): + with self.subTest( + original_path=original_path, + redirect_route=redirect_route, + name=name, + static_args=static_args, + args=TESTING_ARGUMENTS.get(name, ()) + ): + resp = self.client.get( + reverse( + f"home:redirect:{name}", + args=TESTING_ARGUMENTS.get(name, ()) + ), + follow=True + ) self.assertEqual(1, len(resp.redirect_chain)) - self.assertRedirects(resp, reverse(f"home:{redirect_route}", args=args)) + self.assertRedirects( + resp, + reverse( + f"home:{redirect_route}", + args=TESTING_ARGUMENTS.get(name, ()) + static_args + ), + status_code=301 + ) |