diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-05-08 12:53:14 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-05-08 12:53:14 +0000 |
| commit | 23fa913676d66ce4d32501618b1b74e8b2dca5fc (patch) | |
| tree | 10f069413200a2c06ccc795c40f1b8a406eb9f47 /tests/regressiontests/admin_views | |
| parent | 38a6c48878c4318fac404e6ee2454d78b26c098b (diff) | |
Fixed #10448: correcting errors on "save as new" now correctly create a new object instead of modifying the old one. Thanks, bastih.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10713 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/admin_views')
| -rw-r--r-- | tests/regressiontests/admin_views/models.py | 1 | ||||
| -rw-r--r-- | tests/regressiontests/admin_views/tests.py | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index 1aeaea1b1d..f09190b013 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -174,6 +174,7 @@ class PersonAdmin(admin.ModelAdmin): list_filter = ('gender',) search_fields = (u'name',) ordering = ["id"] + save_as = True class Persona(models.Model): """ diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 774f79f1b1..8844713dba 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -234,6 +234,34 @@ class AdminViewBasicTest(TestCase): "Changelist filter isn't showing options contained inside a model field 'choices' option named group." ) +class SaveAsTests(TestCase): + fixtures = ['admin-views-users.xml','admin-views-person.xml'] + + def setUp(self): + self.client.login(username='super', password='secret') + + def tearDown(self): + self.client.logout() + + def test_save_as_duplication(self): + """Ensure save as actually creates a new person""" + post_data = {'_saveasnew':'', 'name':'John M', 'gender':1} + response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data) + self.assertEqual(len(Person.objects.filter(name='John M')), 1) + self.assertEqual(len(Person.objects.filter(id=1)), 1) + + def test_save_as_display(self): + """ + Ensure that 'save as' is displayed when activated and after submitting + invalid data aside save_as_new will not show us a form to overwrite the + initial model. + """ + response = self.client.get('/test_admin/admin/admin_views/person/1/') + self.assert_(response.context['save_as']) + post_data = {'_saveasnew':'', 'name':'John M', 'gender':3, 'alive':'checked'} + response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data) + self.assertEqual(response.context['form_url'], '../add/') + class CustomModelAdminTest(AdminViewBasicTest): urlbit = "admin2" |
