UPD: improved email tests.

This commit is contained in:
2019-03-28 10:29:36 +01:00
parent 5cd22bd122
commit 303560bb63
4 changed files with 36 additions and 34 deletions

View File

@@ -1,20 +1,30 @@
from django.core.exceptions import ImproperlyConfigured
from django.core import mail as django_mail
from django.test import SimpleTestCase
from ..emails import AbstractMail
from .generic import EmailTestMixin
class EmailsTestCase(SimpleTestCase):
def setUp(self):
self.email = AbstractMail()
class ConcreteMail(AbstractMail):
_subject = u'No subject'
_template_name = 'dav_base/base.html'
def __init__(self, recipient, *args, **kwargs):
self._recipient = recipient
def _get_recipients(self):
return [self._recipient]
class TestCase(EmailTestMixin, SimpleTestCase):
def test_send(self):
try:
self.email.send()
self.fail('AbstractEmail.send() does not raise an Exception')
except NotImplementedError:
pass
except ImproperlyConfigured:
pass
except Exception:
self.fail('AbstractEmail.send() raised unexpected Exception')
recipient = 'root@localhost'
email = ConcreteMail(recipient)
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'No subject')