UPD: improved email tests.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import datetime
|
||||
import os
|
||||
import sys
|
||||
import urllib
|
||||
from unittest import skip, SkipTest
|
||||
from django.apps import apps
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
||||
from django.test import SimpleTestCase, TestCase, tag
|
||||
from django.urls import reverse
|
||||
@@ -12,13 +11,6 @@ from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
|
||||
def skip_unless_tag_option():
|
||||
if '--tag' in sys.argv:
|
||||
return lambda func: func
|
||||
else:
|
||||
return skip('Skipped unless --tag option is used')
|
||||
|
||||
|
||||
class AppSetting(object):
|
||||
def __init__(self, name, of=None):
|
||||
self.name = name
|
||||
@@ -47,7 +39,7 @@ class AppsTestCase(SimpleTestCase):
|
||||
self.assertIsInstance(value, of)
|
||||
|
||||
|
||||
class EmailTestCase(TestCase):
|
||||
class EmailTestMixin(object):
|
||||
email_sender = 'Automatic Software Test <root@localhost>'
|
||||
email_base_url = 'http://localhost'
|
||||
email_subject_prefix = '[Test]'
|
||||
@@ -57,8 +49,9 @@ class EmailTestCase(TestCase):
|
||||
|
||||
def assertRecipients(self, mail, recipients):
|
||||
self.assertEqual(len(mail.recipients()), len(recipients))
|
||||
for recipient in recipients:
|
||||
expected_recipient = u'"%s" <%s>' % (recipient.get_full_name(), recipient.email)
|
||||
for expected_recipient in recipients:
|
||||
if isinstance(expected_recipient, AbstractUser):
|
||||
expected_recipient = u'"%s" <%s>' % (expected_recipient.get_full_name(), expected_recipient.email)
|
||||
recipients = mail.recipients()
|
||||
self.assertIn(expected_recipient, recipients)
|
||||
|
||||
@@ -83,7 +76,6 @@ class EmailTestCase(TestCase):
|
||||
self.assertEqual(mail.body, body)
|
||||
|
||||
def setUp(self):
|
||||
super(EmailTestCase, self).setUp()
|
||||
app_config = apps.get_app_config('dav_base')
|
||||
app_config.settings.email_sender = self.email_sender
|
||||
app_config.settings.email_base_url = self.email_base_url
|
||||
|
||||
Reference in New Issue
Block a user