def handle(self, email_alert, push_notification_alert, sms_alert, history_filename, *args, **options): smoketest.run( history_filename=history_filename, email_alert=email_alert, push_notification_alert=push_notification_alert, sms_alert=sms_alert, )
def test_run_one_alert_with_history(self, mock_send_email, mock_send_sms, mock_push_notification_alert): with open('/tmp/testsmoke', 'w') as f: f.write('++-+--\n--') assert smoketest.run( history_filename='/tmp/testsmoke', email_alert=True, sms_alert=True, push_notification_alert=True ) == [ ('email', '*****@*****.**', 'not_exist.abcd ++-+---\ndead_host.xyz ---\nnew_host.ai -\n' ), ('sms', '', 'not_exist.abcd ++-+---\ndead_host.xyz ---\nnew_host.ai -\n' ), ('push', '', 'not_exist.abcd ++-+---\ndead_host.xyz ---\nnew_host.ai -\n' ) ] os.remove('/tmp/testsmoke') mock_send_email.assert_called_once() mock_send_sms.assert_called_once() mock_push_notification_alert.assert_called_once()
def test_https_not_ok(self, mock_send_email): assert smoketest.run(history_filename='/tmp/testsmoke', email_alert=True) is None with open('/tmp/testsmoke', 'r') as f: for line in f: assert line == "-" os.remove('/tmp/testsmoke') mock_send_email.assert_not_called()
def test_ping_ok(self, mock_send_email): if not os.path.isfile('/bin/ping'): return assert smoketest.run(history_filename='/tmp/testsmoke', email_alert=True) is None with open('/tmp/testsmoke', 'r') as f: for line in f: assert line == "+" os.remove('/tmp/testsmoke') mock_send_email.assert_not_called()
def test_run_smoketest_for_the_first_time(self, mock_send_email): with open('/tmp/testsmoke', 'w') as f: f.write('') assert smoketest.run(history_filename='/tmp/testsmoke', email_alert=True) is None # Check if file is updated with the negative health check for the host. with open('/tmp/testsmoke', 'r') as f: for line in f: assert line == "-" os.remove('/tmp/testsmoke') mock_send_email.assert_not_called()
def test_run_smoketest_for_the_file_does_not_exist(self): assert smoketest.run(history_filename='/tmp/testsmoke', email_alert=True) is None assert os.path.isfile('/tmp/testsmoke') is True os.remove('/tmp/testsmoke')
def test_run_no_hosts_no_alerts(self, mock_send_email): with open('/tmp/testsmoke', 'w') as f: f.write('') assert smoketest.run(history_filename='/tmp/testsmoke') is None os.remove('/tmp/testsmoke') mock_send_email.assert_not_called()