UPD: improved email tests.
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user