mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 03:41:58 +00:00
This forces us to be a bit more explicit about testing the three key values in any stream message, and it also de-clutters the code a bit. I eventually want to phase out do_test_topic and friends, since they have the pitfall that you can call them and have them do nothing, because they don't actually require values to be be passed in. I also clean up the code a bit for the tests that have two new messages arriving.
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
class UpdownHookTests(WebhookTestCase):
|
|
STREAM_NAME = 'updown'
|
|
URL_TEMPLATE = "/api/v1/external/updown?stream={stream}&api_key={api_key}"
|
|
FIXTURE_DIR_NAME = 'updown'
|
|
|
|
def test_updown_check_down_event(self) -> None:
|
|
expected_topic = "https://updown.io"
|
|
expected_message = "Service is `down`. It returned a 500 error at 2016-02-07 13:11:43 UTC."
|
|
self.check_webhook("check_down_one_event", expected_topic, expected_message)
|
|
|
|
def test_updown_check_up_again_event(self) -> None:
|
|
expected_topic = "https://updown.io"
|
|
expected_message = "Service is `up` again after 4 minutes 25 seconds."
|
|
self.check_webhook("check_up_again_one_event", expected_topic, expected_message)
|
|
|
|
def test_updown_check_up_event(self) -> None:
|
|
expected_topic = "https://updown.io"
|
|
expected_message = "Service is `up`."
|
|
self.check_webhook("check_up_first_time", expected_topic, expected_message)
|
|
|
|
def test_updown_check_up_multiple_events(self) -> None:
|
|
topic_name = "https://updown.io"
|
|
|
|
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."
|
|
|
|
self.check_webhook("check_multiple_events")
|
|
|
|
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,
|
|
)
|