summaryrefslogtreecommitdiff
path: root/tests/admin_views/tests.py
diff options
context:
space:
mode:
authorKamil Braun <kb346840@students.mimuw.edu.pl>2014-11-27 19:34:14 +0100
committerTim Graham <timograham@gmail.com>2014-12-02 08:43:59 -0500
commitccc30ffe57e5f1e4dbda371b8a1d00c19a3150aa (patch)
tree6e75016a6a99b24135263fadc27d4a804981c7b7 /tests/admin_views/tests.py
parent3a42d9730cbb07ffbb983791e631f5d0a6746f68 (diff)
[1.7.x] Fixed #23934 -- Fixed regression in admin views obj parameter.
Backport of 0623f4dea46eefba46efde6c6528f7d813ef4391 from master
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)