コード例 #1
0
def test_mail_send_message():
    mail = Mail(**test_mail_options)
    mail.send = MagicMock()
    mail.send_message(sender="*****@*****.**",
                      recipients=["*****@*****.**"],
                      body="normal ascii text")
    assert mail.send.has_been_called()
コード例 #2
0
def test_bad_header_with_a_newline():
    mail = Mail(**test_mail_options)
    msg = Message(subject="\ntesting\r\ntesting",
                  body="testing",
                  recipients=["*****@*****.**"])

    with pytest.raises(BadHeaderError):
        mail.send(msg)
コード例 #3
0
def test_bad_header_subject_trailing_whitespace():
    mail = Mail(**test_mail_options)
    msg = Message(subject="testing\r\n\t",
                  body="testing",
                  recipients=["*****@*****.**"])

    with pytest.raises(BadHeaderError):
        mail.send(msg)
コード例 #4
0
def test_message_ascii_attachments_config():
    mail = Mail(**test_mail_options)
    mail.mail_ascii_attachments = True
    msg = Message(sender="*****@*****.**",
                  subject="subject",
                  recipients=["*****@*****.**"])
    mail.send(msg)
    assert msg.ascii_attachments
コード例 #5
0
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
コード例 #6
0
def test_connection_send_ascii_recipient_single():
    mail = Mail(**test_mail_options)
    msg = Message(sender="*****@*****.**",
                  recipients=["*****@*****.**"],
                  body="normal ascii text")
    with mail.connect() as conn:
        with patch.object(conn, 'host') as host:
            conn.send(msg)
            host.sendmail.assert_called_once_with(msg.sender, msg.recipients,
                                                  msg.as_bytes(),
                                                  msg.mail_options,
                                                  msg.rcpt_options)
コード例 #7
0
def test_bad_header_subject_with_no_trailing_whitespace():
    """
    Exercises line `if linenum > 0 and line[0] not in '\t ':`

    This is a bit of a strange test but we aren't changing the bad_header check from flask_mail
    """
    mail = Mail(**test_mail_options)
    msg = Message(subject="testing\r\ntesting",
                  body="testing",
                  recipients=["*****@*****.**"])

    with pytest.raises(BadHeaderError):
        mail.send(msg)
コード例 #8
0
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)
コード例 #9
0
def test_connection_send_non_ascii_recipient_single():
    mail = Mail(**test_mail_options)
    with mail.connect() as conn:
        with patch.object(conn, 'host') as host:
            msg = Message(subject="testing",
                          sender="*****@*****.**",
                          recipients=[u'ÄÜÖ → ✓ <*****@*****.**>'],
                          body="testing")
            conn.send(msg)

            host.sendmail.assert_called_once_with(
                "*****@*****.**",
                ["=?utf-8?b?w4TDnMOWIOKGkiDinJM=?= <*****@*****.**>"],
                msg.as_bytes(), msg.mail_options, msg.rcpt_options)
コード例 #10
0
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
コード例 #11
0
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)
コード例 #12
0
def test_message_default_sender():
    msg = Message(recipients=["*****@*****.**"])
    msg.body = "normal ascii text"
    mail = Mail(**test_mail_options)
    mail.send(msg)
    assert msg.sender == '*****@*****.**'
コード例 #13
0
def test_empty_subject_header():
    mail = Mail(**test_mail_options)
    msg = Message(sender="*****@*****.**", recipients=["*****@*****.**"])
    msg.body = "normal ascii text"
    mail.send(msg)
    assert 'Subject:' not in msg.as_string()