Files
django-dav-events/dav_base/tests/test_emails.py
heinzel 98a6fc3ce7
All checks were successful
buildbot/tox Build done.
try to make pylint happy
2022-06-08 00:08:09 +02:00

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')