Files
django-dav-events/dav_base/tests/test_emails.py

47 lines
1.3 KiB
Python

from django.core import mail as django_mail
from django.core.exceptions import ImproperlyConfigured
from django.test import SimpleTestCase
from ..emails import AbstractMail
from .generic import EmailTestMixin
MAIL_TEMPLATE = 'dav_base/tests/mail.txt'
class TestCase(EmailTestMixin, SimpleTestCase):
def test_no_template_configured(self):
class ConcreteMail(AbstractMail):
pass
email = ConcreteMail()
with self.assertRaises(ImproperlyConfigured):
email.send()
def test_no_get_recipients_implemented(self):
class ConcreteMail(AbstractMail):
_template_name = MAIL_TEMPLATE
email = ConcreteMail()
with self.assertRaises(NotImplementedError):
email.send()
def test_send(self):
recipient = 'root@localhost'
class ConcreteMail(AbstractMail):
_template_name = MAIL_TEMPLATE
def _get_recipients(self):
return [recipient]
email = ConcreteMail()
email.send()
self.assertEqual(len(django_mail.outbox), 1)
mail = django_mail.outbox[0]
self.assertSender(mail)
self.assertRecipients(mail, [recipient])
self.assertSubject(mail, u'')
self.assertBody(mail, 'MAILBODY')