diff options
| author | Lorenzo Peña <lorinkoz@gmail.com> | 2024-11-14 19:53:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-14 15:53:49 -0300 |
| commit | 91c879eda595c12477bbfa6f51115e88b75ddf88 (patch) | |
| tree | 544ce7be64975158b6d3f0d0a8ea693ab7188aca /tests | |
| parent | 8590d05d44a4f3df56d988229e43d66c37df79da (diff) | |
Fixed #35784 -- Added support for preserving the HTTP request method in HttpResponseRedirectBase.
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/httpwrappers/tests.py | 21 | ||||
| -rw-r--r-- | tests/shortcuts/tests.py | 21 |
2 files changed, 42 insertions, 0 deletions
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index 3774ff2d67..f85d33e823 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -566,6 +566,27 @@ class HttpResponseSubclassesTests(SimpleTestCase): r = HttpResponseRedirect(lazystr("/redirected/")) self.assertEqual(r.url, "/redirected/") + def test_redirect_modifiers(self): + cases = [ + (HttpResponseRedirect, "Moved temporarily", False, 302), + (HttpResponseRedirect, "Moved temporarily preserve method", True, 307), + (HttpResponsePermanentRedirect, "Moved permanently", False, 301), + ( + HttpResponsePermanentRedirect, + "Moved permanently preserve method", + True, + 308, + ), + ] + for response_class, content, preserve_request, expected_status_code in cases: + with self.subTest(status_code=expected_status_code): + response = response_class( + "/redirected/", content=content, preserve_request=preserve_request + ) + self.assertEqual(response.status_code, expected_status_code) + self.assertEqual(response.content.decode(), content) + self.assertEqual(response.url, response.headers["Location"]) + def test_redirect_repr(self): response = HttpResponseRedirect("/redirected/") expected = ( diff --git a/tests/shortcuts/tests.py b/tests/shortcuts/tests.py index 8e9c13d206..b80b8f5951 100644 --- a/tests/shortcuts/tests.py +++ b/tests/shortcuts/tests.py @@ -1,3 +1,5 @@ +from django.http.response import HttpResponseRedirectBase +from django.shortcuts import redirect from django.test import SimpleTestCase, override_settings from django.test.utils import require_jinja2 @@ -35,3 +37,22 @@ class RenderTests(SimpleTestCase): self.assertEqual(response.content, b"DTL\n") response = self.client.get("/render/using/?using=jinja2") self.assertEqual(response.content, b"Jinja2\n") + + +class RedirectTests(SimpleTestCase): + def test_redirect_response_status_code(self): + tests = [ + (True, False, 301), + (False, False, 302), + (False, True, 307), + (True, True, 308), + ] + for permanent, preserve_request, expected_status_code in tests: + with self.subTest(permanent=permanent, preserve_request=preserve_request): + response = redirect( + "/path/is/irrelevant/", + permanent=permanent, + preserve_request=preserve_request, + ) + self.assertIsInstance(response, HttpResponseRedirectBase) + self.assertEqual(response.status_code, expected_status_code) |
