47 lines
1.4 KiB
Python
47 lines
1.4 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): # pylint: disable=abstract-method disable=too-few-public-methods
|
|
pass
|
|
|
|
email = ConcreteMail()
|
|
with self.assertRaises(ImproperlyConfigured):
|
|
email.send()
|
|
|
|
def test_no_get_recipients_implemented(self):
|
|
class ConcreteMail(AbstractMail): # pylint: disable=abstract-method disable=too-few-public-methods
|
|
_template_name = MAIL_TEMPLATE
|
|
|
|
email = ConcreteMail()
|
|
with self.assertRaises(NotImplementedError):
|
|
email.send()
|
|
|
|
def test_send(self):
|
|
recipient = 'root@localhost'
|
|
|
|
class ConcreteMail(AbstractMail): # pylint: disable=too-few-public-methods
|
|
_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, '')
|
|
self.assertBody(mail, 'MAILBODY')
|