diff options
| author | Clifford Gama <cliffygamy@gmail.com> | 2025-06-24 22:35:45 +0200 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2025-07-17 17:36:02 -0300 |
| commit | 04e813cd17484ba91e3fc25d5e5118ac25f47352 (patch) | |
| tree | 2afcfbcd9b25cf076a3df869dee5882f4aa6e07d /tests/test_client_regress | |
| parent | 024ea0f78322eda09e245b0facb8ba4296408e25 (diff) | |
Refs #4476 -- Added tests for assertRedirects() when following redirect chains.
Thanks Natalia Bidart for the review.
Diffstat (limited to 'tests/test_client_regress')
| -rw-r--r-- | tests/test_client_regress/tests.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index bc18b11a45..a480a2069b 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -385,7 +385,7 @@ class AssertTemplateUsedTests(TestDataMixin, TestCase): @override_settings(ROOT_URLCONF="test_client_regress.urls") -class AssertRedirectsTests(SimpleTestCase): +class AssertRedirectsTests(ExtraAssertMixin, SimpleTestCase): def test_redirect_page(self): "An assertion is raised if the original page couldn't be retrieved as expected" # This page will redirect with code 301, not 302 @@ -408,6 +408,34 @@ class AssertRedirectsTests(SimpleTestCase): str(e), ) + def test_followed_redirect_unexpected_initial_status_code(self): + response = self.client.get("/permanent_redirect_view/", follow=True) + msg = ( + "Initial response didn't redirect as expected: Response code was 301 " + "(expected 302)" + ) + self.assertRaisesPrefixedMessage( + self.assertRedirects, + response, + "/get_view/", + expected_msg=msg, + ) + + def test_followed_redirect_unexpected_final_status_code(self): + response = self.client.get("/redirect_view/", follow=True) + msg = ( + "Response didn't redirect as expected: Final Response code was 200 " + "(expected 403)" + ) + self.assertRaisesPrefixedMessage( + self.assertRedirects, + response, + "/get_view/", + status_code=302, + target_status_code=403, + expected_msg=msg, + ) + def test_lost_query(self): """ An assertion is raised if the redirect location doesn't preserve GET |
