From 8a590c4b7bde49cb562000603c7d309bf7e0f961 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sun, 8 Feb 2015 20:09:15 -0500 Subject: [PATCH] Moved a custom admin template test to a more appropriate case. Thanks to Tim for the review. --- tests/admin_views/tests.py | 85 ++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index f4a2bc77e7..42fa378c2b 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -788,9 +788,12 @@ class AdminViewBasicTest(AdminViewBasicTestCase): @override_settings(TEMPLATES=[{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', - # Put this app's templates dir in DIRS to take precedence over the admin's - # templates dir. - 'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'templates')], + # Put this app's and the shared tests templates dirs in DIRS to take precedence + # over the admin's templates dir. + 'DIRS': [ + os.path.join(os.path.dirname(upath(__file__)), 'templates'), + os.path.join(os.path.dirname(os.path.dirname(upath(__file__))), 'templates'), + ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -802,6 +805,41 @@ class AdminViewBasicTest(AdminViewBasicTestCase): }, }]) class AdminCustomTemplateTests(AdminViewBasicTestCase): + def test_custom_model_admin_templates(self): + # Test custom change list template with custom extra context + response = self.client.get(reverse('admin:admin_views_customarticle_changelist')) + self.assertContains(response, "var hello = 'Hello!';") + self.assertTemplateUsed(response, 'custom_admin/change_list.html') + + # Test custom add form template + response = self.client.get(reverse('admin:admin_views_customarticle_add')) + self.assertTemplateUsed(response, 'custom_admin/add_form.html') + + # Add an article so we can test delete, change, and history views + post = self.client.post(reverse('admin:admin_views_customarticle_add'), { + 'content': '

great article

', + 'date_0': '2008-03-18', + 'date_1': '10:54:39' + }) + self.assertRedirects(post, reverse('admin:admin_views_customarticle_changelist')) + self.assertEqual(CustomArticle.objects.all().count(), 1) + article_pk = CustomArticle.objects.all()[0].pk + + # Test custom delete, change, and object history templates + # Test custom change form template + response = self.client.get(reverse('admin:admin_views_customarticle_change', args=(article_pk,))) + self.assertTemplateUsed(response, 'custom_admin/change_form.html') + response = self.client.get(reverse('admin:admin_views_customarticle_delete', args=(article_pk,))) + self.assertTemplateUsed(response, 'custom_admin/delete_confirmation.html') + response = self.client.post(reverse('admin:admin_views_customarticle_changelist'), data={ + 'index': 0, + 'action': ['delete_selected'], + '_selected_action': ['1'], + }) + self.assertTemplateUsed(response, 'custom_admin/delete_selected_confirmation.html') + response = self.client.get(reverse('admin:admin_views_customarticle_history', args=(article_pk,))) + self.assertTemplateUsed(response, 'custom_admin/object_history.html') + def test_extended_bodyclass_template_change_form(self): """ Ensure that the admin/change_form.html template uses block.super in the @@ -1552,47 +1590,6 @@ class AdminViewPermissionsTest(TestCase): self.assertTrue(get_delete_related(response)) self.assertContains(response, delete_link_text) - def test_custom_model_admin_templates(self): - login_url = '%s?next=%s' % (reverse('admin:login'), reverse('admin:index')) - self.client.get(self.index_url) - self.client.post(login_url, self.super_login) - - # Test custom change list template with custom extra context - response = self.client.get(reverse('admin:admin_views_customarticle_changelist')) - self.assertContains(response, "var hello = 'Hello!';") - self.assertTemplateUsed(response, 'custom_admin/change_list.html') - - # Test custom add form template - response = self.client.get(reverse('admin:admin_views_customarticle_add')) - self.assertTemplateUsed(response, 'custom_admin/add_form.html') - - # Add an article so we can test delete, change, and history views - post = self.client.post(reverse('admin:admin_views_customarticle_add'), { - 'content': '

great article

', - 'date_0': '2008-03-18', - 'date_1': '10:54:39' - }) - self.assertRedirects(post, reverse('admin:admin_views_customarticle_changelist')) - self.assertEqual(CustomArticle.objects.all().count(), 1) - article_pk = CustomArticle.objects.all()[0].pk - - # Test custom delete, change, and object history templates - # Test custom change form template - response = self.client.get(reverse('admin:admin_views_customarticle_change', args=(article_pk,))) - self.assertTemplateUsed(response, 'custom_admin/change_form.html') - response = self.client.get(reverse('admin:admin_views_customarticle_delete', args=(article_pk,))) - self.assertTemplateUsed(response, 'custom_admin/delete_confirmation.html') - response = self.client.post(reverse('admin:admin_views_customarticle_changelist'), data={ - 'index': 0, - 'action': ['delete_selected'], - '_selected_action': ['1'], - }) - self.assertTemplateUsed(response, 'custom_admin/delete_selected_confirmation.html') - response = self.client.get(reverse('admin:admin_views_customarticle_history', args=(article_pk,))) - self.assertTemplateUsed(response, 'custom_admin/object_history.html') - - self.client.get(reverse('admin:logout')) - def test_delete_view(self): """Delete view should restrict access and actually delete items."""