summaryrefslogtreecommitdiff
path: root/tests/generic_views/test_base.py
diff options
context:
space:
mode:
authorSamriddha9619 <sumitkumartripathi0@gmail.com>2025-09-08 18:26:32 +0530
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-09-22 08:54:08 +0200
commita36df6890d8995480f2e95ba556b77cef975d4f6 (patch)
tree46d0d5afd2c751fc5f4befe40af3d4da1a88baf8 /tests/generic_views/test_base.py
parent336e713e2a1ac143eeec021d66a6f3168f983183 (diff)
Fixed #36488 -- Fixed merging of query strings in RedirectView.
Co-authored-by: Ethan Jucovy <ethan.jucovy@gmail.com> Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Diffstat (limited to 'tests/generic_views/test_base.py')
-rw-r--r--tests/generic_views/test_base.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/generic_views/test_base.py b/tests/generic_views/test_base.py
index cc5dcf4e39..9d6cef8a46 100644
--- a/tests/generic_views/test_base.py
+++ b/tests/generic_views/test_base.py
@@ -587,6 +587,31 @@ class RedirectViewTest(LoggingAssertionMixin, SimpleTestCase):
handler, f"Gone: {escaped}", logging.WARNING, 410, request
)
+ def test_redirect_with_querry_string_in_destination(self):
+ response = RedirectView.as_view(url="/bar/?pork=spam", query_string=True)(
+ self.rf.get("/foo")
+ )
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.headers["Location"], "/bar/?pork=spam")
+
+ def test_redirect_with_query_string_in_destination_and_request(self):
+ response = RedirectView.as_view(url="/bar/?pork=spam", query_string=True)(
+ self.rf.get("/foo/?utm_source=social")
+ )
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(
+ response.headers["Location"], "/bar/?pork=spam&utm_source=social"
+ )
+
+ def test_redirect_with_same_query_string_param_will_append_not_replace(self):
+ response = RedirectView.as_view(url="/bar/?pork=spam", query_string=True)(
+ self.rf.get("/foo/?utm_source=social&pork=ham")
+ )
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(
+ response.headers["Location"], "/bar/?pork=spam&utm_source=social&pork=ham"
+ )
+
class GetContextDataTest(SimpleTestCase):
def test_get_context_data_super(self):