2016-09-20 22:51:11 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-11-10 19:30:09 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
2016-09-20 22:51:11 +02:00
|
|
|
|
|
|
|
class UpdownHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'updown'
|
|
|
|
URL_TEMPLATE = u"/api/v1/external/updown?stream={stream}&api_key={api_key}"
|
|
|
|
FIXTURE_DIR_NAME = 'updown'
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_updown_check_down_event(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"https://updown.io"
|
2017-02-26 09:10:14 +01:00
|
|
|
expected_message = u"Service is `down`. It returned a 500 error at 2016-02-07 13:11:43 UTC."
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('check_down_one_event', expected_topic, expected_message)
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_updown_check_up_again_event(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"https://updown.io"
|
2016-09-20 22:51:11 +02:00
|
|
|
expected_message = u"Service is `up` again after 4 minutes 25 seconds."
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('check_up_again_one_event', expected_topic, expected_message)
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_updown_check_up_event(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"https://updown.io"
|
2016-09-20 22:51:11 +02:00
|
|
|
expected_message = u"Service is `up`."
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('check_up_first_time', expected_topic, expected_message)
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_updown_check_up_multiple_events(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
first_message_expected_topic = u"https://updown.io"
|
2016-09-20 22:51:11 +02:00
|
|
|
first_message_expected_message = u"Service is `up` again after 1 second."
|
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
second_message_expected_topic = u"https://updown.io"
|
2017-02-26 09:10:14 +01:00
|
|
|
second_message_expected_message = u"Service is `down`. It returned a 500 error at 2016-02-07 13:11:43 UTC."
|
2016-09-20 22:51:11 +02:00
|
|
|
|
|
|
|
self.send_and_test_stream_message('check_multiple_events')
|
|
|
|
last_message = self.get_last_message()
|
2018-11-09 20:33:58 +01:00
|
|
|
self.do_test_topic(last_message, first_message_expected_topic)
|
2016-09-20 22:51:11 +02:00
|
|
|
self.do_test_message(last_message, first_message_expected_message)
|
|
|
|
|
|
|
|
second_to_last_message = self.get_second_to_last_message()
|
2018-11-09 20:33:58 +01:00
|
|
|
self.do_test_topic(second_to_last_message, second_message_expected_topic)
|
2016-09-20 22:51:11 +02:00
|
|
|
self.do_test_message(second_to_last_message, second_message_expected_message)
|