@@ -1999,6 +1999,107 @@ def test_message_policy_compat32(self):
19991999 message .as_string (policy = policy .compat32 ),
20002000 )
20012001
2002+ def test_send_mail_fail_silently_conflict (self ):
2003+ msg = (
2004+ "fail_silently cannot be used with a connection. "
2005+ "Pass fail_silently to get_connection() instead."
2006+ )
2007+ with self .assertRaisesMessage (TypeError , msg ):
2008+ mail .send_mail (
2009+ "Subject" ,
2010+ "Body" ,
2011+ "from@example.com" ,
2012+ ["to@example.com" ],
2013+ fail_silently = True ,
2014+ connection = mail .get_connection (),
2015+ )
2016+
2017+ def test_send_mail_auth_conflict (self ):
2018+ msg = (
2019+ "auth_user and auth_password cannot be used with a connection. "
2020+ "Pass auth_user and auth_password to get_connection() instead."
2021+ )
2022+ for param in ["auth_user" , "auth_password" ]:
2023+ with (
2024+ self .subTest (param = param ),
2025+ self .assertRaisesMessage (TypeError , msg ),
2026+ ):
2027+ mail .send_mail (
2028+ "subject" ,
2029+ "body" ,
2030+ "from@example.com" ,
2031+ ["to@example.com" ],
2032+ ** {param : "value" },
2033+ connection = mail .get_connection (),
2034+ )
2035+
2036+ def test_email_message_send_fail_silently_conflict (self ):
2037+ email = mail .EmailMessage (
2038+ "Subject" ,
2039+ "Body" ,
2040+ "from@example.com" ,
2041+ ["to@example.com" ],
2042+ connection = mail .get_connection (),
2043+ )
2044+ msg = (
2045+ "fail_silently cannot be used with a connection. "
2046+ "Pass fail_silently to get_connection() instead."
2047+ )
2048+ with self .assertRaisesMessage (TypeError , msg ):
2049+ email .send (fail_silently = True )
2050+
2051+ def test_send_mass_mail_fail_silently_conflict (self ):
2052+ datatuple = (("Subject" , "Message" , "from@example.com" , ["to@example.com" ]),)
2053+ msg = (
2054+ "fail_silently cannot be used with a connection. "
2055+ "Pass fail_silently to get_connection() instead."
2056+ )
2057+ with self .assertRaisesMessage (TypeError , msg ):
2058+ mail .send_mass_mail (
2059+ datatuple , fail_silently = True , connection = mail .get_connection ()
2060+ )
2061+
2062+ def test_send_mass_mail_auth_conflict (self ):
2063+ datatuple = (("Subject" , "Message" , "from@example.com" , ["to@example.com" ]),)
2064+ msg = (
2065+ "auth_user and auth_password cannot be used with a connection. "
2066+ "Pass auth_user and auth_password to get_connection() instead."
2067+ )
2068+ for param in ["auth_user" , "auth_password" ]:
2069+ with (
2070+ self .subTest (param = param ),
2071+ self .assertRaisesMessage (TypeError , msg ),
2072+ ):
2073+ mail .send_mass_mail (
2074+ datatuple , ** {param : "value" }, connection = mail .get_connection ()
2075+ )
2076+
2077+ def test_mail_admins_fail_silently_conflict (self ):
2078+ msg = (
2079+ "fail_silently cannot be used with a connection. "
2080+ "Pass fail_silently to get_connection() instead."
2081+ )
2082+ with self .assertRaisesMessage (TypeError , msg ):
2083+ mail .mail_admins (
2084+ "Subject" ,
2085+ "Message" ,
2086+ fail_silently = True ,
2087+ connection = mail .get_connection (),
2088+ )
2089+
2090+ def test_mail_managers_fail_silently_conflict (self ):
2091+ msg = (
2092+ "fail_silently cannot be used with a connection. "
2093+ "Pass fail_silently to get_connection() instead."
2094+ )
2095+ with self .assertRaisesMessage (TypeError , msg ):
2096+ mail .mail_managers (
2097+ "Subject" ,
2098+ "Message" ,
2099+ fail_silently = True ,
2100+ connection = mail .get_connection (),
2101+ )
2102+
20022103
20032104# RemovedInDjango70Warning.
20042105class MailDeprecatedPositionalArgsTests (SimpleTestCase ):
@@ -2029,9 +2130,9 @@ def test_send_mail(self):
20292130 "from@example.com" ,
20302131 ["to@example.com" ],
20312132 # Deprecated positional args:
2032- True ,
2033- "username" ,
2034- "password" ,
2133+ None ,
2134+ None ,
2135+ None ,
20352136 mail .get_connection (),
20362137 "html message" ,
20372138 )
@@ -2044,9 +2145,9 @@ def test_send_mass_mail(self):
20442145 send_mass_mail (
20452146 [],
20462147 # Deprecated positional args:
2047- True ,
2048- "username" ,
2049- "password" ,
2148+ None ,
2149+ None ,
2150+ None ,
20502151 mail .get_connection (),
20512152 )
20522153
@@ -2058,7 +2159,7 @@ def test_mail_admins(self):
20582159 "subject" ,
20592160 "message" ,
20602161 # Deprecated positional args:
2061- True ,
2162+ None ,
20622163 mail .get_connection (),
20632164 "html message" ,
20642165 )
@@ -2071,7 +2172,7 @@ def test_mail_managers(self):
20712172 "subject" ,
20722173 "message" ,
20732174 # Deprecated positional args:
2074- True ,
2175+ None ,
20752176 mail .get_connection (),
20762177 "html message" ,
20772178 )
0 commit comments