@ -9,16 +9,14 @@ from apistar_mail.exc import MailUnicodeDecodeError, BadHeaderError
import pytest
import pytest
settings = {
test_mail_options = {
' MAIL ' : {
' MAIL_SERVER ' : ' smtp.example.com ' ,
' MAIL_SERVER ' : ' smtp.example.com ' ,
' MAIL_USERNAME ' : ' fake@example.com ' ,
' MAIL_USERNAME ' : ' fake@example.com ' ,
' MAIL_PASSWORD ' : ' secret ' ,
' MAIL_PASSWORD ' : ' secret ' ,
' MAIL_PORT ' : 587 ,
' MAIL_PORT ' : 587 ,
' MAIL_USE_TLS ' : True ,
' MAIL_USE_TLS ' : True ,
' MAIL_SUPPRESS_SEND ' : True ,
' MAIL_SUPPRESS_SEND ' : True ,
' MAIL_DEFAULT_SENDER ' : ' fake@example.com '
' MAIL_DEFAULT_SENDER ' : ' fake@example.com '
}
}
}
@ -400,7 +398,7 @@ def test_message_charset():
def test_empty_subject_header ( ) :
def test_empty_subject_header ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
msg = Message ( sender = " from@example.com " ,
msg = Message ( sender = " from@example.com " ,
recipients = [ " foo@bar.com " ] )
recipients = [ " foo@bar.com " ] )
msg . body = " normal ascii text "
msg . body = " normal ascii text "
@ -411,13 +409,13 @@ def test_empty_subject_header():
def test_message_default_sender ( ) :
def test_message_default_sender ( ) :
msg = Message ( recipients = [ " foo@bar.com " ] )
msg = Message ( recipients = [ " foo@bar.com " ] )
msg . body = " normal ascii text "
msg . body = " normal ascii text "
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
mail . send ( msg )
mail . send ( msg )
assert msg . sender == ' fake@example.com '
assert msg . sender == ' fake@example.com '
def test_mail_send_message ( ) :
def test_mail_send_message ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
mail . send = MagicMock ( )
mail . send = MagicMock ( )
mail . send_message ( sender = " from@example.com " ,
mail . send_message ( sender = " from@example.com " ,
recipients = [ " foo@bar.com " ] ,
recipients = [ " foo@bar.com " ] ,
@ -426,7 +424,7 @@ def test_mail_send_message():
def test_message_ascii_attachments_config ( ) :
def test_message_ascii_attachments_config ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
mail . mail_ascii_attachments = True
mail . mail_ascii_attachments = True
msg = Message ( sender = " from@example.com " ,
msg = Message ( sender = " from@example.com " ,
subject = " subject " ,
subject = " subject " ,
@ -447,7 +445,7 @@ def test_message_as_bytes():
@patch ( ' apistar_mail.mail.smtplib.SMTP ' )
@patch ( ' apistar_mail.mail.smtplib.SMTP ' )
def test_connection_configure_host_non_ssl ( mock_smtp ) :
def test_connection_configure_host_non_ssl ( mock_smtp ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
mail . mail_suppress_send = False
mail . mail_suppress_send = False
mail . mail_use_tls = True
mail . mail_use_tls = True
mock_smtp . return_value = MagicMock ( )
mock_smtp . return_value = MagicMock ( )
@ -459,7 +457,7 @@ def test_connection_configure_host_non_ssl(mock_smtp):
@patch ( ' apistar_mail.mail.smtplib.SMTP_SSL ' )
@patch ( ' apistar_mail.mail.smtplib.SMTP_SSL ' )
def test_connection_configure_host_ssl ( mock_smtp_ssl ) :
def test_connection_configure_host_ssl ( mock_smtp_ssl ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
mail . mail_suppress_send = False
mail . mail_suppress_send = False
mail . mail_use_tls = False
mail . mail_use_tls = False
mail . mail_use_ssl = True
mail . mail_use_ssl = True
@ -469,7 +467,7 @@ def test_connection_configure_host_ssl(mock_smtp_ssl):
def test_connection_send_message ( ) :
def test_connection_send_message ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
with mail . connect ( ) as conn :
with mail . connect ( ) as conn :
conn . send = MagicMock ( )
conn . send = MagicMock ( )
conn . send_message ( sender = " from@example.com " ,
conn . send_message ( sender = " from@example.com " ,
@ -480,7 +478,7 @@ def test_connection_send_message():
@patch ( ' apistar_mail.mail.smtplib.SMTP ' )
@patch ( ' apistar_mail.mail.smtplib.SMTP ' )
def test_connection_send_single ( mock_smtp ) :
def test_connection_send_single ( mock_smtp ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
mail . mail_suppress_send = False
mail . mail_suppress_send = False
msg = Message ( sender = " from@example.com " ,
msg = Message ( sender = " from@example.com " ,
recipients = [ " foo@bar.com " ] ,
recipients = [ " foo@bar.com " ] ,
@ -494,7 +492,7 @@ def test_connection_send_single(mock_smtp):
def test_connection_send_ascii_recipient_single ( ) :
def test_connection_send_ascii_recipient_single ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
msg = Message ( sender = " from@example.com " ,
msg = Message ( sender = " from@example.com " ,
recipients = [ " foo@bar.com " ] ,
recipients = [ " foo@bar.com " ] ,
body = " normal ascii text " )
body = " normal ascii text " )
@ -506,7 +504,7 @@ def test_connection_send_ascii_recipient_single():
def test_connection_send_non_ascii_recipient_single ( ) :
def test_connection_send_non_ascii_recipient_single ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
with mail . connect ( ) as conn :
with mail . connect ( ) as conn :
with patch . object ( conn , ' host ' ) as host :
with patch . object ( conn , ' host ' ) as host :
msg = Message ( subject = " testing " ,
msg = Message ( subject = " testing " ,
@ -526,7 +524,7 @@ def test_connection_send_non_ascii_recipient_single():
@patch ( ' apistar_mail.mail.smtplib.SMTP ' )
@patch ( ' apistar_mail.mail.smtplib.SMTP ' )
def test_connection_send_many ( mock_smtp ) :
def test_connection_send_many ( mock_smtp ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
mail . mail_suppress_send = False
mail . mail_suppress_send = False
mail . mail_max_emails = 50
mail . mail_max_emails = 50
mock_smtp . return_value = MagicMock ( spec = SMTP )
mock_smtp . return_value = MagicMock ( spec = SMTP )
@ -545,7 +543,7 @@ def test_connection_send_many(mock_smtp):
def test_bad_header_subject ( ) :
def test_bad_header_subject ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
msg = Message ( subject = " testing \r \n " ,
msg = Message ( subject = " testing \r \n " ,
body = " testing " ,
body = " testing " ,
recipients = [ " to@example.com " ] )
recipients = [ " to@example.com " ] )
@ -555,7 +553,7 @@ def test_bad_header_subject():
def test_bad_header_subject_whitespace ( ) :
def test_bad_header_subject_whitespace ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
msg = Message ( subject = " \t \r \n " ,
msg = Message ( subject = " \t \r \n " ,
body = " testing " ,
body = " testing " ,
recipients = [ " to@example.com " ] )
recipients = [ " to@example.com " ] )
@ -570,7 +568,7 @@ def test_bad_header_subject_with_no_trailing_whitespace():
This is a bit of a strange test but we aren ' t changing the bad_header check from flask_mail
This is a bit of a strange test but we aren ' t changing the bad_header check from flask_mail
"""
"""
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
msg = Message ( subject = " testing \r \n testing " ,
msg = Message ( subject = " testing \r \n testing " ,
body = " testing " ,
body = " testing " ,
recipients = [ " to@example.com " ] )
recipients = [ " to@example.com " ] )
@ -580,7 +578,7 @@ def test_bad_header_subject_with_no_trailing_whitespace():
def test_bad_header_subject_trailing_whitespace ( ) :
def test_bad_header_subject_trailing_whitespace ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
msg = Message ( subject = " testing \r \n \t " ,
msg = Message ( subject = " testing \r \n \t " ,
body = " testing " ,
body = " testing " ,
recipients = [ " to@example.com " ] )
recipients = [ " to@example.com " ] )
@ -590,7 +588,7 @@ def test_bad_header_subject_trailing_whitespace():
def test_bad_header_with_a_newline ( ) :
def test_bad_header_with_a_newline ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
msg = Message ( subject = " \n testing \r \n testing " ,
msg = Message ( subject = " \n testing \r \n testing " ,
body = " testing " ,
body = " testing " ,
recipients = [ " to@example.com " ] )
recipients = [ " to@example.com " ] )
@ -600,7 +598,7 @@ def test_bad_header_with_a_newline():
def test_bad_header_with_newline_in_sender ( ) :
def test_bad_header_with_newline_in_sender ( ) :
mail = Mail ( se tting s)
mail = Mail ( * * te st_mail_op tio ns)
msg = Message ( subject = " testing " ,
msg = Message ( subject = " testing " ,
body = " testing " ,
body = " testing " ,
sender = ' me \n @example.com ' ,
sender = ' me \n @example.com ' ,