1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[1.7.x] Fixed #23934 -- Fixed regression in admin views obj parameter.

Backport of 0623f4dea4 from master
This commit is contained in:
Kamil Braun
2014-11-27 19:34:14 +01:00
committed by Tim Graham
parent 3a42d9730c
commit ccc30ffe57
5 changed files with 92 additions and 7 deletions

View File

@@ -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)