summaryrefslogtreecommitdiff
path: root/tests/admin_views/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/admin_views/tests.py')
-rw-r--r--tests/admin_views/tests.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 50d68df2a2..b801fedbbb 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -5056,3 +5056,51 @@ class AdminGenericRelationTests(TestCase):
validator.validate_list_filter(GenericFKAdmin, Plot)
except ImproperlyConfigured:
self.fail("Couldn't validate a GenericRelation -> FK path in ModelAdmin.list_filter")
+
+
+@override_settings(
+ PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
+ ROOT_URLCONF="admin_views.urls",
+)
+class GetFormsetsWithInlinesArgumentTest(TestCase):
+ """
+ #23934 - When adding a new model instance in the admin, the 'obj' argument
+ of get_formsets_with_inlines() should be None. When changing, it should be
+ equal to the existing model instance.
+ The GetFormsetsArgumentCheckingAdmin ModelAdmin throws an exception
+ if obj is not None during add_view or obj is None during change_view.
+ """
+ fixtures = ['admin-views-users.xml']
+
+ def setUp(self):
+ self.client.login(username='super', password='secret')
+
+ def test_explicitly_provided_pk(self):
+ post_data = {'name': '1'}
+ try:
+ response = self.client.post('/test_admin/admin/admin_views/explicitlyprovidedpk/add/', post_data)
+ except Exception as e:
+ self.fail(e)
+ self.assertEqual(response.status_code, 302)
+
+ post_data = {'name': '2'}
+ try:
+ response = self.client.post('/test_admin/admin/admin_views/explicitlyprovidedpk/1/', post_data)
+ except Exception as e:
+ self.fail(e)
+ self.assertEqual(response.status_code, 302)
+
+ def test_implicitly_generated_pk(self):
+ post_data = {'name': '1'}
+ try:
+ response = self.client.post('/test_admin/admin/admin_views/implicitlygeneratedpk/add/', post_data)
+ except Exception as e:
+ self.fail(e)
+ self.assertEqual(response.status_code, 302)
+
+ post_data = {'name': '2'}
+ try:
+ response = self.client.post('/test_admin/admin/admin_views/implicitlygeneratedpk/1/', post_data)
+ except Exception as e:
+ self.fail(e)
+ self.assertEqual(response.status_code, 302)