UPD: improved tests.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django.apps import apps
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core import mail as django_mail
|
||||
from django.test import TestCase
|
||||
@@ -16,6 +17,12 @@ class EmailsTestCase(TestCase):
|
||||
model = get_user_model()
|
||||
self.user = model.objects.create_user(username=TEST_USERNAME, password=TEST_PASSWORD, email=TEST_EMAIL)
|
||||
|
||||
self.email_sender = 'Automatic Software Test <root@localhost>'
|
||||
self.email_subject_prefix = '[Test]'
|
||||
app_config = apps.get_app_config('dav_base')
|
||||
app_config.settings.email_sender = self.email_sender
|
||||
app_config.settings.email_subject_prefix = self.email_subject_prefix
|
||||
|
||||
def test_send(self):
|
||||
password = TEST_PASSWORD[::-1]
|
||||
|
||||
@@ -24,8 +31,16 @@ class EmailsTestCase(TestCase):
|
||||
|
||||
self.assertEqual(len(django_mail.outbox), 1)
|
||||
mail = django_mail.outbox[0]
|
||||
|
||||
recipient = u'"%s" <%s>' % (self.user.get_full_name(), self.user.email)
|
||||
recipients = mail.recipients()
|
||||
self.assertIn(recipient, recipients)
|
||||
self.assertEqual(len(recipients), 1)
|
||||
|
||||
self.assertEqual(mail.from_email, self.email_sender)
|
||||
|
||||
subject = u'Zugangsdaten'
|
||||
subject = u'{} {}'.format(self.email_subject_prefix, subject)
|
||||
self.assertEqual(mail.subject, subject)
|
||||
|
||||
self.assertIn(password, mail.body)
|
||||
|
||||
Reference in New Issue
Block a user