mirror of
https://github.com/django/django.git
synced 2025-10-26 23:26:08 +00:00
Fixed #11400 -- Passed kwargs from AbstractUser.email_user() to send_mail()
Thanks Jug_ for suggestion, john_scott for the initial patch, and Tim Graham for code review.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group, User, UserManager
|
||||
from django.contrib.auth.models import AbstractUser, Group, User, UserManager
|
||||
from django.contrib.auth.tests.utils import skipIfCustomUser
|
||||
from django.core import mail
|
||||
from django.db.models.signals import post_save
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
@@ -73,6 +74,29 @@ class UserManagerTestCase(TestCase):
|
||||
User.objects.create_user, username='')
|
||||
|
||||
|
||||
class AbstractUserTestCase(TestCase):
|
||||
def test_email_user(self):
|
||||
# valid send_mail parameters
|
||||
kwargs = {
|
||||
"fail_silently": False,
|
||||
"auth_user": None,
|
||||
"auth_password": None,
|
||||
"connection": None,
|
||||
"html_message": None,
|
||||
}
|
||||
abstract_user = AbstractUser(email='foo@bar.com')
|
||||
abstract_user.email_user(subject="Subject here",
|
||||
message="This is a message", from_email="from@domain.com", **kwargs)
|
||||
# Test that one message has been sent.
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
# Verify that test email contains the correct attributes:
|
||||
message = mail.outbox[0]
|
||||
self.assertEqual(message.subject, "Subject here")
|
||||
self.assertEqual(message.body, "This is a message")
|
||||
self.assertEqual(message.from_email, "from@domain.com")
|
||||
self.assertEqual(message.to, [abstract_user.email])
|
||||
|
||||
|
||||
class IsActiveTestCase(TestCase):
|
||||
"""
|
||||
Tests the behavior of the guaranteed is_active attribute
|
||||
|
||||
Reference in New Issue
Block a user