summaryrefslogtreecommitdiff
path: root/tests/admin_views/tests.py
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 11:00:25 +0200
commitfc62e17778dad9eab9e507d90d85a33d415f64a7 (patch)
tree996285e9afc06ceb623a294ab4596af303e50af3 /tests/admin_views/tests.py
parent6e369f36f2def929525e524f621eead4b041d1cf (diff)
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>
Diffstat (limited to 'tests/admin_views/tests.py')
-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 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.