summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2015-02-08 20:09:15 -0500
committerSimon Charette <charette.s@gmail.com>2015-02-09 15:07:49 -0500
commit8a590c4b7bde49cb562000603c7d309bf7e0f961 (patch)
tree37f0165d49a50b395719603eafc57930be0599e3
parent2ee9bce654f940a8de5ef121f39b6fcb6d09741a (diff)
Moved a custom admin template test to a more appropriate case.
Thanks to Tim for the review.
-rw-r--r--tests/admin_views/tests.py85
1 files 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': '<p>great article</p>',
+ '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': '<p>great article</p>',
- '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."""