summaryrefslogtreecommitdiff
path: root/tests/admin_views
diff options
context:
space:
mode:
authorMariana <mmariana.pereira.20@gmail.com>2022-10-26 16:01:33 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-10-11 12:46:10 +0200
commit0bbe6ca2ac3d70e44081e54c235ff21568bf832c (patch)
tree440b9d459b222d8ce5ef0525967b3ba95cbdeebe /tests/admin_views
parentbcc6a8ee88ade98aa5ca9cb22b6646c85ef2dbc2 (diff)
[5.0.x] Fixed #12241 -- Preserved query strings when using "Save and continue/add another" in admin.
Co-authored-by: Grady Yu <gradyy@users.noreply.github.com> Co-authored-by: David Sanders <shang.xiao.sanders@gmail.com> Co-authored-by: Matthew Newton <matthewn@berkeley.edu> Backport of fc62e17778dad9eab9e507d90d85a33d415f64a7 from main
Diffstat (limited to 'tests/admin_views')
-rw-r--r--tests/admin_views/tests.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 4ea261b347..2e91e9d859 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.