def test_send_mime_dryrun(self, mock_smtp, mock_smtp_ssl): utils.send_mime_email("from", "to", MIMEMultipart(), app.config, dryrun=True) assert not mock_smtp.called assert not mock_smtp_ssl.called
def test_send_mime_ssl(self, mock_smtp, mock_smtp_ssl): app.config["SMTP_SSL"] = True mock_smtp.return_value = mock.Mock() mock_smtp_ssl.return_value = mock.Mock() utils.send_mime_email("from", "to", MIMEMultipart(), app.config, dryrun=False) assert not mock_smtp.called mock_smtp_ssl.assert_called_with( app.config["SMTP_HOST"], app.config["SMTP_PORT"] )
def test_send_mime(self, mock_smtp, mock_smtp_ssl): mock_smtp.return_value = mock.Mock() mock_smtp_ssl.return_value = mock.Mock() msg = MIMEMultipart() utils.send_mime_email("from", "to", msg, app.config, dryrun=False) mock_smtp.assert_called_with(app.config["SMTP_HOST"], app.config["SMTP_PORT"]) assert mock_smtp.return_value.starttls.called mock_smtp.return_value.login.assert_called_with( app.config["SMTP_USER"], app.config["SMTP_PASSWORD"]) mock_smtp.return_value.sendmail.assert_called_with( "from", "to", msg.as_string()) assert mock_smtp.return_value.quit.called
def test_send_mime_noauth(self, mock_smtp, mock_smtp_ssl): smtp_user = app.config["SMTP_USER"] smtp_password = app.config["SMTP_PASSWORD"] app.config["SMTP_USER"] = None app.config["SMTP_PASSWORD"] = None mock_smtp.return_value = mock.Mock() mock_smtp_ssl.return_value = mock.Mock() utils.send_mime_email("from", "to", MIMEMultipart(), app.config, dryrun=False) assert not mock_smtp_ssl.called mock_smtp.assert_called_with(app.config["SMTP_HOST"], app.config["SMTP_PORT"]) assert not mock_smtp.login.called app.config["SMTP_USER"] = smtp_user app.config["SMTP_PASSWORD"] = smtp_password