mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Add simple tests for admin views.
Make sure the admin views load without error. (Not really trying to test content right now.) This includes failing test cases for: * brack3t/Djrill#8: admin.autodiscover() fails without django-adminplus or DjrillAdminSite * brack3t/Djrill#14: Django 1.5 doesn't support adminmedia template tag
This commit is contained in:
16
djrill/test_admin_urls.py
Normal file
16
djrill/test_admin_urls.py
Normal file
@@ -0,0 +1,16 @@
|
||||
try:
|
||||
from django.conf.urls import include, patterns, url
|
||||
except ImportError:
|
||||
# Django 1.3
|
||||
from django.conf.urls.defaults import include, patterns, url
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
from djrill import DjrillAdminSite
|
||||
|
||||
admin.site = DjrillAdminSite()
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
@@ -1,6 +1,9 @@
|
||||
from mock import patch
|
||||
import sys
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
from django.core import mail
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import TestCase
|
||||
@@ -13,8 +16,9 @@ class DjrillBackendMockAPITestCase(TestCase):
|
||||
|
||||
class MockResponse:
|
||||
"""requests.post return value mock sufficient for DjrillBackend"""
|
||||
def __init__(self, status_code=200):
|
||||
def __init__(self, status_code=200, content="{}"):
|
||||
self.status_code = status_code
|
||||
self.content = content
|
||||
|
||||
def setUp(self):
|
||||
self.patch = patch('requests.post')
|
||||
@@ -146,6 +150,71 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase):
|
||||
self.assertEqual(sent, 0)
|
||||
|
||||
|
||||
def reset_admin_site():
|
||||
"""Return the Django admin globals to their original state"""
|
||||
admin.site = admin.AdminSite() # restore default
|
||||
if 'djrill.admin' in sys.modules:
|
||||
del sys.modules['djrill.admin'] # force autodiscover to re-import
|
||||
|
||||
|
||||
class DjrillAdminTests(DjrillBackendMockAPITestCase):
|
||||
"""Test the Djrill admin site"""
|
||||
|
||||
# These tests currently just verify that the admin site pages load
|
||||
# without error -- they don't test any Mandrill-supplied content.
|
||||
# (Future improvements could mock the Mandrill responses.)
|
||||
|
||||
# These urls set up the DjrillAdminSite as suggested in the readme
|
||||
urls = 'djrill.test_admin_urls'
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# Other test cases may muck with the Django admin site globals,
|
||||
# so return it to the default state before loading test_admin_urls
|
||||
reset_admin_site()
|
||||
|
||||
def setUp(self):
|
||||
super(DjrillAdminTests, self).setUp()
|
||||
# Must be authenticated staff to access admin site...
|
||||
admin = User.objects.create_user('admin', 'admin@example.com', 'secret')
|
||||
admin.is_staff = True
|
||||
admin.save()
|
||||
self.client.login(username='admin', password='secret')
|
||||
|
||||
def test_admin_senders(self):
|
||||
response = self.client.get('/admin/djrill/senders/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Senders")
|
||||
|
||||
def test_admin_status(self):
|
||||
response = self.client.get('/admin/djrill/status/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Status")
|
||||
|
||||
def test_admin_tags(self):
|
||||
response = self.client.get('/admin/djrill/tags/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Tags")
|
||||
|
||||
def test_admin_urls(self):
|
||||
response = self.client.get('/admin/djrill/urls/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "URLs")
|
||||
|
||||
def test_admin_index(self):
|
||||
"""Make sure Djrill section is included in the admin index page"""
|
||||
response = self.client.get('/admin/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Djrill")
|
||||
|
||||
|
||||
class DjrillNoAdminTests(TestCase):
|
||||
def test_admin_autodiscover_without_djrill(self):
|
||||
"""Make sure autodiscover doesn't die without DjrillAdminSite"""
|
||||
reset_admin_site()
|
||||
admin.autodiscover() # test: this shouldn't error
|
||||
|
||||
|
||||
class DjrillMessageTests(TestCase):
|
||||
def setUp(self):
|
||||
self.subject = "Djrill baby djrill."
|
||||
|
||||
Reference in New Issue
Block a user