def test_connection_configure_host_ssl(mock_smtp_ssl): mail = Mail(**test_mail_options) mail.mail_suppress_send = False mail.mail_use_tls = False mail.mail_use_ssl = True mock_smtp_ssl.return_value = MagicMock() with mail.connect() as conn: # NOQA mock_smtp_ssl.assert_called_with(mail.mail_server, mail.mail_port)
def test_connection_configure_host_non_ssl(mock_smtp): mail = Mail(**test_mail_options) mail.mail_suppress_send = False mail.mail_use_tls = True mock_smtp.return_value = MagicMock() mock_smtp.return_value.starttls.return_value = None with mail.connect() as conn: mock_smtp.assert_called_with(mail.mail_server, mail.mail_port) assert conn.host.starttls.called
def test_connection_send_single(mock_smtp): mail = Mail(**test_mail_options) mail.mail_suppress_send = False msg = Message(sender="*****@*****.**", recipients=["*****@*****.**"], body="normal ascii text") mock_smtp.return_value = MagicMock(spec=SMTP) with mail.connect() as conn: conn.send(msg) host = conn.host host.sendmail.assert_called_with(msg.sender, msg.recipients, msg.as_bytes(), msg.mail_options, msg.rcpt_options)
def test_connection_send_many(mock_smtp): mail = Mail(**test_mail_options) mail.mail_suppress_send = False mail.mail_max_emails = 50 mock_smtp.return_value = MagicMock(spec=SMTP) with mail.connect() as conn: host = conn.host conn.configure_host = MagicMock() conn.configure_host.return_value = None for i in range(100): msg = Message(sender="*****@*****.**", recipients=["*****@*****.**"], body="normal ascii text") conn.send(msg) assert host.quit.called assert conn.configure_host.called