2016-11-10 19:30:09 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2016-09-20 22:51:11 +02:00
|
|
|
class UpdownHookTests(WebhookTestCase):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "updown"
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/updown?stream={stream}&api_key={api_key}"
|
2021-02-12 08:20:45 +01:00
|
|
|
FIXTURE_DIR_NAME = "updown"
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_updown_check_down_event(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "https://updown.io"
|
|
|
|
expected_message = "Service is `down`. It returned a 500 error at 2016-02-07 13:11:43 UTC."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook("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:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "https://updown.io"
|
|
|
|
expected_message = "Service is `up` again after 4 minutes 25 seconds."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook("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:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "https://updown.io"
|
|
|
|
expected_message = "Service is `up`."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook("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:
|
2020-08-24 14:21:58 +02:00
|
|
|
topic_name = "https://updown.io"
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-08-24 14:21:58 +02:00
|
|
|
down_content = "Service is `down`. It returned a 500 error at 2016-02-07 13:11:43 UTC."
|
|
|
|
up_content = "Service is `up` again after 1 second."
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-08-24 17:53:05 +02:00
|
|
|
self.subscribe(self.test_user, self.STREAM_NAME)
|
|
|
|
payload = self.get_body("check_multiple_events")
|
|
|
|
|
|
|
|
msg = self.send_webhook_payload(
|
|
|
|
self.test_user,
|
|
|
|
self.url,
|
|
|
|
payload,
|
|
|
|
content_type="application/json",
|
|
|
|
)
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-08-24 14:21:58 +02:00
|
|
|
msg = self.get_second_to_last_message()
|
|
|
|
self.assert_stream_message(
|
|
|
|
message=msg,
|
|
|
|
stream_name=self.STREAM_NAME,
|
|
|
|
topic_name=topic_name,
|
|
|
|
content=down_content,
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = self.get_last_message()
|
|
|
|
self.assert_stream_message(
|
|
|
|
message=msg,
|
|
|
|
stream_name=self.STREAM_NAME,
|
|
|
|
topic_name=topic_name,
|
|
|
|
content=up_content,
|
|
|
|
)
|