def test_no_login_when_credentials_not_present(): '''Test login is not called when credentials not available.''' with mock.patch('sawmill.handler.email.smtplib.SMTP', spec=True) as SMTP: handler = Email( formatter=EmailFormatter( 'Test', '*****@*****.**', '*****@*****.**' ) ) log = Log(level='info', message='A message') handler.handle(log) smtp = SMTP.return_value assert smtp.login.called is False
def test_login_when_credentials_present(): '''Test login is called when credentials available.''' with mock.patch('sawmill.handler.email.smtplib.SMTP', spec=True) as SMTP: handler = Email( credentials=('*****@*****.**', 'mypassword'), formatter=EmailFormatter( 'Test', '*****@*****.**', '*****@*****.**' ) ) log = Log(level='info', message='A message') handler.handle(log) smtp = SMTP.return_value smtp.login.assert_called_with('*****@*****.**', 'mypassword')
def test_output(): '''Test outputting to email.''' with mock.patch('sawmill.handler.email.smtplib.SMTP', spec=True) as SMTP: host = 'emailhost' port = 90210 handler = Email( host=host, port=port, formatter=EmailFormatter( 'Test', '*****@*****.**', '*****@*****.**' ) ) log = Log(level='info', message='A message') handler.handle(log) SMTP.assert_called_with(host, port) smtp = SMTP.return_value assert smtp.sendmail.called is True assert smtp.quit.called is True