2017-12-27 07:15:27 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2017-12-27 07:15:27 +01:00
|
|
|
class StatuspageHookTests(WebhookTestCase):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "statuspage-test"
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/statuspage?api_key={api_key}&stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "statuspage"
|
2017-12-27 07:15:27 +01:00
|
|
|
|
|
|
|
def test_statuspage_incident(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Database query delays: All Systems Operational"
|
2019-04-12 05:55:01 +02:00
|
|
|
expected_message = """
|
|
|
|
**Database query delays**:
|
|
|
|
* State: **identified**
|
2020-03-28 01:25:56 +01:00
|
|
|
* Description: We just encountered that database queries are timing out resulting in inconvenience to our end users...we'll do quick fix latest by tomorrow !!!
|
2019-04-12 05:55:01 +02:00
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"incident_created",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-12-27 07:15:27 +01:00
|
|
|
|
|
|
|
def test_statuspage_incident_update(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Database query delays: All Systems Operational"
|
2019-04-12 05:55:01 +02:00
|
|
|
expected_message = """
|
|
|
|
**Database query delays**:
|
|
|
|
* State: **resolved**
|
|
|
|
* Description: The database issue is resolved.
|
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"incident_update",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-12-27 07:15:27 +01:00
|
|
|
|
|
|
|
def test_statuspage_component(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Database component: Service Under Maintenance"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = "**Database component** has changed status from **operational** to **under_maintenance**."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"component_status_update",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2023-10-06 00:17:52 +02:00
|
|
|
|
|
|
|
def test_statuspage_anomalous_payload(self) -> None:
|
|
|
|
result = self.client_post(
|
|
|
|
self.url,
|
|
|
|
{},
|
|
|
|
content_type="application/json",
|
|
|
|
)
|
|
|
|
self.assert_json_error(
|
|
|
|
result, "Unable to parse request: Did Statuspage generate this event?", 400
|
|
|
|
)
|