UPD: improved tests.

This commit is contained in:
2019-03-21 20:28:46 +01:00
parent 1bcd479304
commit dc37c110df
4 changed files with 62 additions and 35 deletions

View File

@@ -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
@@ -10,6 +11,12 @@ from .. import emails
class EmailsTestCase(TestCase):
def setUp(self):
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
model = get_user_model()
self.recipient = model.objects.create_user(username='recipient@example.com',
email='recipient@example.com',
@@ -50,10 +57,18 @@ Line 3 END"""
self.assertEqual(len(django_mail.outbox), 1)
mail = django_mail.outbox[0]
recipient = u'"%s" <%s>' % (self.recipient.get_full_name(), self.recipient.email)
recipients = mail.recipients()
self.assertIn(recipient, recipients)
self.assertEqual(len(recipients), 1)
self.assertEqual(mail.from_email, self.email_sender)
subject = u'Veranstaltung geändert'
subject = u'{} {}'.format(self.email_subject_prefix, subject)
self.assertEqual(mail.subject, subject)
self.assertIn(self.recipient.first_name, mail.body)
self.assertIn(self.editor.get_full_name(), mail.body)
self.assertIn(unicode(self.event), mail.body)