mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -4,7 +4,6 @@ from django.core.mail.backends.base import BaseEmailBackend
|
||||
|
||||
|
||||
class EmailBackend(BaseEmailBackend):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.test_outbox = []
|
||||
|
||||
@@ -4,8 +4,14 @@ from django.test import SimpleTestCase, override_settings
|
||||
|
||||
|
||||
@override_settings(
|
||||
ADMINS=(('Admin', 'admin@example.com'), ('Admin and Manager', 'admin_and_manager@example.com')),
|
||||
MANAGERS=(('Manager', 'manager@example.com'), ('Admin and Manager', 'admin_and_manager@example.com')),
|
||||
ADMINS=(
|
||||
("Admin", "admin@example.com"),
|
||||
("Admin and Manager", "admin_and_manager@example.com"),
|
||||
),
|
||||
MANAGERS=(
|
||||
("Manager", "manager@example.com"),
|
||||
("Admin and Manager", "admin_and_manager@example.com"),
|
||||
),
|
||||
)
|
||||
class SendTestEmailManagementCommand(SimpleTestCase):
|
||||
"""
|
||||
@@ -16,67 +22,82 @@ class SendTestEmailManagementCommand(SimpleTestCase):
|
||||
"""
|
||||
The mail is sent with the correct subject and recipient.
|
||||
"""
|
||||
recipient = 'joe@example.com'
|
||||
call_command('sendtestemail', recipient)
|
||||
recipient = "joe@example.com"
|
||||
call_command("sendtestemail", recipient)
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
mail_message = mail.outbox[0]
|
||||
self.assertEqual(mail_message.subject[0:15], 'Test email from')
|
||||
self.assertEqual(mail_message.subject[0:15], "Test email from")
|
||||
self.assertEqual(mail_message.recipients(), [recipient])
|
||||
|
||||
def test_multiple_receivers(self):
|
||||
"""
|
||||
The mail may be sent with multiple recipients.
|
||||
"""
|
||||
recipients = ['joe@example.com', 'jane@example.com']
|
||||
call_command('sendtestemail', recipients[0], recipients[1])
|
||||
recipients = ["joe@example.com", "jane@example.com"]
|
||||
call_command("sendtestemail", recipients[0], recipients[1])
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
mail_message = mail.outbox[0]
|
||||
self.assertEqual(mail_message.subject[0:15], 'Test email from')
|
||||
self.assertEqual(sorted(mail_message.recipients()), [
|
||||
'jane@example.com',
|
||||
'joe@example.com',
|
||||
])
|
||||
self.assertEqual(mail_message.subject[0:15], "Test email from")
|
||||
self.assertEqual(
|
||||
sorted(mail_message.recipients()),
|
||||
[
|
||||
"jane@example.com",
|
||||
"joe@example.com",
|
||||
],
|
||||
)
|
||||
|
||||
def test_manager_receivers(self):
|
||||
"""
|
||||
The mail should be sent to the email addresses specified in
|
||||
settings.MANAGERS.
|
||||
"""
|
||||
call_command('sendtestemail', '--managers')
|
||||
call_command("sendtestemail", "--managers")
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
mail_message = mail.outbox[0]
|
||||
self.assertEqual(sorted(mail_message.recipients()), [
|
||||
'admin_and_manager@example.com',
|
||||
'manager@example.com',
|
||||
])
|
||||
self.assertEqual(
|
||||
sorted(mail_message.recipients()),
|
||||
[
|
||||
"admin_and_manager@example.com",
|
||||
"manager@example.com",
|
||||
],
|
||||
)
|
||||
|
||||
def test_admin_receivers(self):
|
||||
"""
|
||||
The mail should be sent to the email addresses specified in
|
||||
settings.ADMIN.
|
||||
"""
|
||||
call_command('sendtestemail', '--admins')
|
||||
call_command("sendtestemail", "--admins")
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
mail_message = mail.outbox[0]
|
||||
self.assertEqual(sorted(mail_message.recipients()), [
|
||||
'admin@example.com',
|
||||
'admin_and_manager@example.com',
|
||||
])
|
||||
self.assertEqual(
|
||||
sorted(mail_message.recipients()),
|
||||
[
|
||||
"admin@example.com",
|
||||
"admin_and_manager@example.com",
|
||||
],
|
||||
)
|
||||
|
||||
def test_manager_and_admin_receivers(self):
|
||||
"""
|
||||
The mail should be sent to the email addresses specified in both
|
||||
settings.MANAGERS and settings.ADMINS.
|
||||
"""
|
||||
call_command('sendtestemail', '--managers', '--admins')
|
||||
call_command("sendtestemail", "--managers", "--admins")
|
||||
self.assertEqual(len(mail.outbox), 2)
|
||||
manager_mail = mail.outbox[0]
|
||||
self.assertEqual(sorted(manager_mail.recipients()), [
|
||||
'admin_and_manager@example.com',
|
||||
'manager@example.com',
|
||||
])
|
||||
self.assertEqual(
|
||||
sorted(manager_mail.recipients()),
|
||||
[
|
||||
"admin_and_manager@example.com",
|
||||
"manager@example.com",
|
||||
],
|
||||
)
|
||||
admin_mail = mail.outbox[1]
|
||||
self.assertEqual(sorted(admin_mail.recipients()), [
|
||||
'admin@example.com',
|
||||
'admin_and_manager@example.com',
|
||||
])
|
||||
self.assertEqual(
|
||||
sorted(admin_mail.recipients()),
|
||||
[
|
||||
"admin@example.com",
|
||||
"admin_and_manager@example.com",
|
||||
],
|
||||
)
|
||||
|
||||
1432
tests/mail/tests.py
1432
tests/mail/tests.py
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user