From fc62e17778dad9eab9e507d90d85a33d415f64a7 Mon Sep 17 00:00:00 2001 From: Mariana Date: Wed, 26 Oct 2022 16:01:33 -0700 Subject: Fixed #12241 -- Preserved query strings when using "Save and continue/add another" in admin. Co-authored-by: Grady Yu Co-authored-by: David Sanders Co-authored-by: Matthew Newton --- tests/admin_views/tests.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests/admin_views/tests.py') diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index b2a5fe2ccd..87174dc100 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -328,6 +328,66 @@ class AdminViewBasicTest(AdminViewBasicTestCase): msg_prefix="Couldn't find an input with the right value in the response", ) + def test_add_query_string_persists(self): + save_options = [ + {"_addanother": "1"}, # "Save and add another". + {"_continue": "1"}, # "Save and continue editing". + {"_saveasnew": "1"}, # "Save as new". + ] + other_options = [ + "", + "_changelist_filters=is_staff__exact%3D0", + f"{IS_POPUP_VAR}=1", + f"{TO_FIELD_VAR}=id", + ] + url = reverse("admin:auth_user_add") + for i, save_option in enumerate(save_options): + for j, other_option in enumerate(other_options): + with self.subTest(save_option=save_option, other_option=other_option): + qsl = "username=newuser" + if other_option: + qsl = f"{qsl}&{other_option}" + response = self.client.post( + f"{url}?{qsl}", + { + "username": f"newuser{i}{j}", + "password1": "newpassword", + "password2": "newpassword", + **save_option, + }, + ) + parsed_url = urlparse(response.url) + self.assertEqual(parsed_url.query, qsl) + + def test_change_query_string_persists(self): + save_options = [ + {"_addanother": "1"}, # "Save and add another". + {"_continue": "1"}, # "Save and continue editing". + ] + other_options = [ + "", + "_changelist_filters=warm%3D1", + f"{IS_POPUP_VAR}=1", + f"{TO_FIELD_VAR}=id", + ] + url = reverse("admin:admin_views_color_change", args=(self.color1.pk,)) + for save_option in save_options: + for other_option in other_options: + with self.subTest(save_option=save_option, other_option=other_option): + qsl = "value=blue" + if other_option: + qsl = f"{qsl}&{other_option}" + response = self.client.post( + f"{url}?{qsl}", + { + "value": "gold", + "warm": True, + **save_option, + }, + ) + parsed_url = urlparse(response.url) + self.assertEqual(parsed_url.query, qsl) + def test_basic_edit_GET(self): """ A smoke test to ensure GET on the change_view works. -- cgit v1.3