diff options
| author | Julien Phalip <jphalip@gmail.com> | 2012-12-30 21:33:21 -0800 |
|---|---|---|
| committer | Julien Phalip <jphalip@gmail.com> | 2012-12-30 21:33:21 -0800 |
| commit | cee40c7d79930ff42bde4730f43e68a624e47b0f (patch) | |
| tree | 3e25c340c81f26eeb5f1ace204382d00c1824480 /tests | |
| parent | f80a1934cdb465c70ecc215fdf867e555a670623 (diff) | |
Added further flexibility to ModelAdmin for controlling post-save redirections.
Refs #19505.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/admin_custom_urls/models.py | 6 | ||||
| -rw-r--r-- | tests/regressiontests/admin_custom_urls/tests.py | 23 |
2 files changed, 25 insertions, 4 deletions
diff --git a/tests/regressiontests/admin_custom_urls/models.py b/tests/regressiontests/admin_custom_urls/models.py index 45b6ed57a9..ef04c2aa09 100644 --- a/tests/regressiontests/admin_custom_urls/models.py +++ b/tests/regressiontests/admin_custom_urls/models.py @@ -56,10 +56,14 @@ class Person(models.Model): class PersonAdmin(admin.ModelAdmin): - def response_post_save(self, request, obj): + def response_post_save_add(self, request, obj): return HttpResponseRedirect( reverse('admin:admin_custom_urls_person_history', args=[obj.pk])) + def response_post_save_change(self, request, obj): + return HttpResponseRedirect( + reverse('admin:admin_custom_urls_person_delete', args=[obj.pk])) + class Car(models.Model): name = models.CharField(max_length=20) diff --git a/tests/regressiontests/admin_custom_urls/tests.py b/tests/regressiontests/admin_custom_urls/tests.py index a7edc77c38..31c93410f4 100644 --- a/tests/regressiontests/admin_custom_urls/tests.py +++ b/tests/regressiontests/admin_custom_urls/tests.py @@ -94,10 +94,11 @@ class CustomRedirects(TestCase): def tearDown(self): self.client.logout() - def test_post_save_redirect(self): + def test_post_save_add_redirect(self): """ - Ensures that ModelAdmin.response_post_save() controls the redirection - after the 'Save' button has been pressed. + Ensures that ModelAdmin.response_post_save_add() controls the + redirection after the 'Save' button has been pressed when adding a + new object. Refs 8001, 18310, 19505. """ post_data = { 'name': 'John Doe', } @@ -109,6 +110,22 @@ class CustomRedirects(TestCase): self.assertRedirects( response, reverse('admin:admin_custom_urls_person_history', args=[persons[0].pk])) + def test_post_save_change_redirect(self): + """ + Ensures that ModelAdmin.response_post_save_change() controls the + redirection after the 'Save' button has been pressed when editing an + existing object. + Refs 8001, 18310, 19505. + """ + Person.objects.create(name='John Doe') + self.assertEqual(Person.objects.count(), 1) + person = Person.objects.all()[0] + post_data = { 'name': 'Jack Doe', } + response = self.client.post( + reverse('admin:admin_custom_urls_person_change', args=[person.pk]), post_data) + self.assertRedirects( + response, reverse('admin:admin_custom_urls_person_delete', args=[person.pk])) + def test_post_url_continue(self): """ Ensures that the ModelAdmin.response_add()'s parameter `post_url_continue` |
