Files
django-dav-events/dav_base/tests/test_emails.py
T
heinzel 6b9c490f92
Run tests / Execute tox to run the test suite (push) Successful in 3m33s
dav_base.emails: make coverage happy
2026-05-21 16:29:37 +02:00

67 lines
2.1 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\n')
def test_send_extra_context(self):
recipient = 'root@localhost'
class ConcreteMail(AbstractMail): # pylint: disable=too-few-public-methods
_template_name = MAIL_TEMPLATE
def _get_recipients(self):
return [recipient]
def _get_body(self, context=None):
context = {'var1': 'Here is',
'var2': ' extra context. '}
return super()._get_body(context)
email = ConcreteMail()
email.send()
mail = django_mail.outbox[0]
self.assertBody(mail, 'Here is extra context. MAILBODY\n')