dav_base.emails: make coverage happy
Run tests / Execute tox to run the test suite (push) Successful in 3m33s
Run tests / Execute tox to run the test suite (push) Successful in 3m33s
This commit is contained in:
+3
-6
@@ -48,7 +48,7 @@ class AbstractMail: # pylint: disable=too-few-public-methods
|
||||
def _get_reply_to(self):
|
||||
return None
|
||||
|
||||
def send(self, fail_silently=False):
|
||||
def send(self):
|
||||
subject = self._get_subject()
|
||||
body = self._get_body()
|
||||
sender = self._get_sender()
|
||||
@@ -56,8 +56,5 @@ class AbstractMail: # pylint: disable=too-few-public-methods
|
||||
reply_to = self._get_reply_to()
|
||||
|
||||
email = EmailMessage(subject=subject, body=body, from_email=sender, to=recipients, reply_to=reply_to)
|
||||
if fail_silently:
|
||||
logger.info('Fake sending %s to %s', self.__class__.__name__, recipients)
|
||||
else:
|
||||
logger.info('Send %s to %s', self.__class__.__name__, recipients)
|
||||
email.send(fail_silently=fail_silently)
|
||||
logger.info('Send %s to %s', self.__class__.__name__, recipients)
|
||||
email.send()
|
||||
|
||||
@@ -1 +1 @@
|
||||
{# This template is used by software tests #}MAILBODY
|
||||
{# This template is used by software tests #}{{ var1 }}{{ var2 }}MAILBODY
|
||||
|
||||
@@ -43,4 +43,24 @@ class TestCase(EmailTestMixin, SimpleTestCase):
|
||||
self.assertSender(mail)
|
||||
self.assertRecipients(mail, [recipient])
|
||||
self.assertSubject(mail, '')
|
||||
self.assertBody(mail, 'MAILBODY')
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user