summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPraful Gulani <prafulgulani555@gmail.com>2026-02-12 20:03:25 +0530
committerJacob Walls <jacobtylerwalls@gmail.com>2026-03-16 12:51:58 -0400
commit2333d56696141303000986a16553205ece993c67 (patch)
tree16ec0e70baa0beee82dab88bddf264eaac8ce91e /tests
parent455e787b9cc8bd3342f86ddcf8ef4103fd811bb5 (diff)
Fixed #36894 -- Added TypeError for conflicting arguments in mail APIs.
A TypeError is now raised if fail_silently=True, auth_user, or auth_password are provided along a connection. Updated AdminEmailHandler in django.utils.log to remove redundant fail_silently=True. Thanks Mike Edmunds for the report and Jacob Tyler Walls for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/mail/tests.py117
1 files changed, 109 insertions, 8 deletions
diff --git a/tests/mail/tests.py b/tests/mail/tests.py
index 851d1c371c..3ba3b9d062 100644
--- a/tests/mail/tests.py
+++ b/tests/mail/tests.py
@@ -1999,6 +1999,107 @@ class MailTests(MailTestsMixin, SimpleTestCase):
message.as_string(policy=policy.compat32),
)
+ def test_send_mail_fail_silently_conflict(self):
+ msg = (
+ "fail_silently cannot be used with a connection. "
+ "Pass fail_silently to get_connection() instead."
+ )
+ with self.assertRaisesMessage(TypeError, msg):
+ mail.send_mail(
+ "Subject",
+ "Body",
+ "from@example.com",
+ ["to@example.com"],
+ fail_silently=True,
+ connection=mail.get_connection(),
+ )
+
+ def test_send_mail_auth_conflict(self):
+ msg = (
+ "auth_user and auth_password cannot be used with a connection. "
+ "Pass auth_user and auth_password to get_connection() instead."
+ )
+ for param in ["auth_user", "auth_password"]:
+ with (
+ self.subTest(param=param),
+ self.assertRaisesMessage(TypeError, msg),
+ ):
+ mail.send_mail(
+ "subject",
+ "body",
+ "from@example.com",
+ ["to@example.com"],
+ **{param: "value"},
+ connection=mail.get_connection(),
+ )
+
+ def test_email_message_send_fail_silently_conflict(self):
+ email = mail.EmailMessage(
+ "Subject",
+ "Body",
+ "from@example.com",
+ ["to@example.com"],
+ connection=mail.get_connection(),
+ )
+ msg = (
+ "fail_silently cannot be used with a connection. "
+ "Pass fail_silently to get_connection() instead."
+ )
+ with self.assertRaisesMessage(TypeError, msg):
+ email.send(fail_silently=True)
+
+ def test_send_mass_mail_fail_silently_conflict(self):
+ datatuple = (("Subject", "Message", "from@example.com", ["to@example.com"]),)
+ msg = (
+ "fail_silently cannot be used with a connection. "
+ "Pass fail_silently to get_connection() instead."
+ )
+ with self.assertRaisesMessage(TypeError, msg):
+ mail.send_mass_mail(
+ datatuple, fail_silently=True, connection=mail.get_connection()
+ )
+
+ def test_send_mass_mail_auth_conflict(self):
+ datatuple = (("Subject", "Message", "from@example.com", ["to@example.com"]),)
+ msg = (
+ "auth_user and auth_password cannot be used with a connection. "
+ "Pass auth_user and auth_password to get_connection() instead."
+ )
+ for param in ["auth_user", "auth_password"]:
+ with (
+ self.subTest(param=param),
+ self.assertRaisesMessage(TypeError, msg),
+ ):
+ mail.send_mass_mail(
+ datatuple, **{param: "value"}, connection=mail.get_connection()
+ )
+
+ def test_mail_admins_fail_silently_conflict(self):
+ msg = (
+ "fail_silently cannot be used with a connection. "
+ "Pass fail_silently to get_connection() instead."
+ )
+ with self.assertRaisesMessage(TypeError, msg):
+ mail.mail_admins(
+ "Subject",
+ "Message",
+ fail_silently=True,
+ connection=mail.get_connection(),
+ )
+
+ def test_mail_managers_fail_silently_conflict(self):
+ msg = (
+ "fail_silently cannot be used with a connection. "
+ "Pass fail_silently to get_connection() instead."
+ )
+ with self.assertRaisesMessage(TypeError, msg):
+ mail.mail_managers(
+ "Subject",
+ "Message",
+ fail_silently=True,
+ connection=mail.get_connection(),
+ )
+
# RemovedInDjango70Warning.
class MailDeprecatedPositionalArgsTests(SimpleTestCase):
@@ -2029,9 +2130,9 @@ class MailDeprecatedPositionalArgsTests(SimpleTestCase):
"from@example.com",
["to@example.com"],
# Deprecated positional args:
- True,
- "username",
- "password",
+ None,
+ None,
+ None,
mail.get_connection(),
"html message",
)
@@ -2044,9 +2145,9 @@ class MailDeprecatedPositionalArgsTests(SimpleTestCase):
send_mass_mail(
[],
# Deprecated positional args:
- True,
- "username",
- "password",
+ None,
+ None,
+ None,
mail.get_connection(),
)
@@ -2058,7 +2159,7 @@ class MailDeprecatedPositionalArgsTests(SimpleTestCase):
"subject",
"message",
# Deprecated positional args:
- True,
+ None,
mail.get_connection(),
"html message",
)
@@ -2071,7 +2172,7 @@ class MailDeprecatedPositionalArgsTests(SimpleTestCase):
"subject",
"message",
# Deprecated positional args:
- True,
+ None,
mail.get_connection(),
"html message",
)