diff options
| author | Michael Scott <michael.scott250@gmail.com> | 2016-11-12 19:09:15 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-14 18:10:56 -0500 |
| commit | 1e629928e9257da5ec37a65784c0f68889d3edf4 (patch) | |
| tree | 4de99f56c508a22484ab98bedcf4c833dc582417 /tests | |
| parent | fb1349ce8cfd207ec5bbdb617dad75a73caee33b (diff) | |
Fixed #27313 -- Allowed overriding admin popup response template.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_views/admin.py | 1 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 47 | ||||
| -rw-r--r-- | tests/templates/custom_admin/popup_response.html | 1 |
3 files changed, 47 insertions, 2 deletions
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index cdb32a2825..bc4c7e647f 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -162,6 +162,7 @@ class CustomArticleAdmin(admin.ModelAdmin): object_history_template = 'custom_admin/object_history.html' delete_confirmation_template = 'custom_admin/delete_confirmation.html' delete_selected_confirmation_template = 'custom_admin/delete_selected_confirmation.html' + popup_response_template = 'custom_admin/popup_response.html' def changelist_view(self, request): return super(CustomArticleAdmin, self).changelist_view( diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index e8e8d1c2d4..b65439f8ac 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -969,6 +969,16 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase): response = self.client.get(reverse('admin:admin_views_customarticle_history', args=(article_pk,))) self.assertTemplateUsed(response, 'custom_admin/object_history.html') + # A custom popup response template may be specified by + # ModelAdmin.popup_response_template. + response = self.client.post(reverse('admin:admin_views_customarticle_add') + '?%s=1' % IS_POPUP_VAR, { + 'content': '<p>great article</p>', + 'date_0': '2008-03-18', + 'date_1': '10:54:39', + IS_POPUP_VAR: '1' + }) + self.assertEqual(response.template_name, 'custom_admin/popup_response.html') + def test_extended_bodyclass_template_change_form(self): """ The admin/change_form.html template uses block.super in the @@ -3433,7 +3443,7 @@ action)</option> reverse('admin:admin_views_subscriber_changelist') + '?%s' % IS_POPUP_VAR) self.assertIsNone(response.context["action_form"]) - def test_popup_template_response(self): + def test_popup_template_response_on_add(self): """ Success on popups shall be rendered from template in order to allow easy customization. @@ -3442,7 +3452,40 @@ action)</option> reverse('admin:admin_views_actor_add') + '?%s=1' % IS_POPUP_VAR, {'name': 'Troy McClure', 'age': '55', IS_POPUP_VAR: '1'}) self.assertEqual(response.status_code, 200) - self.assertEqual(response.template_name, 'admin/popup_response.html') + self.assertListEqual(response.template_name, [ + 'admin/admin_views/actor/popup_response.html', + 'admin/admin_views/popup_response.html', + 'admin/popup_response.html', + ]) + self.assertTemplateUsed(response, 'admin/popup_response.html') + + def test_popup_template_response_on_change(self): + instance = Actor.objects.create(name='David Tennant', age=45) + response = self.client.post( + reverse('admin:admin_views_actor_change', args=(instance.pk,)) + '?%s=1' % IS_POPUP_VAR, + {'name': 'David Tennant', 'age': '46', IS_POPUP_VAR: '1'} + ) + self.assertEqual(response.status_code, 200) + self.assertListEqual(response.template_name, [ + 'admin/admin_views/actor/popup_response.html', + 'admin/admin_views/popup_response.html', + 'admin/popup_response.html', + ]) + self.assertTemplateUsed(response, 'admin/popup_response.html') + + def test_popup_template_response_on_delete(self): + instance = Actor.objects.create(name='David Tennant', age=45) + response = self.client.post( + reverse('admin:admin_views_actor_delete', args=(instance.pk,)) + '?%s=1' % IS_POPUP_VAR, + {IS_POPUP_VAR: '1'} + ) + self.assertEqual(response.status_code, 200) + self.assertListEqual(response.template_name, [ + 'admin/admin_views/actor/popup_response.html', + 'admin/admin_views/popup_response.html', + 'admin/popup_response.html', + ]) + self.assertTemplateUsed(response, 'admin/popup_response.html') def test_popup_template_escaping(self): popup_response_data = json.dumps({ diff --git a/tests/templates/custom_admin/popup_response.html b/tests/templates/custom_admin/popup_response.html new file mode 100644 index 0000000000..fd21d13d14 --- /dev/null +++ b/tests/templates/custom_admin/popup_response.html @@ -0,0 +1 @@ +{% extends "admin/popup_response.html" %} |
