2021-04-09 03:50:04 +02:00
|
|
|
import json
|
|
|
|
|
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class JsonHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = "json"
|
|
|
|
URL_TEMPLATE = "/api/v1/external/json?api_key={api_key}&stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "json"
|
2021-04-09 03:50:04 +02:00
|
|
|
|
|
|
|
def test_json_github_push__1_commit_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if json github push 1 commit is handled correctly
|
|
|
|
"""
|
|
|
|
with open("zerver/webhooks/json/fixtures/json_github_push__1_commit.json") as f:
|
|
|
|
original_fixture = json.load(f)
|
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "JSON"
|
2023-07-22 00:35:07 +02:00
|
|
|
expected_message = f"""```json
|
|
|
|
{json.dumps(original_fixture, indent=2)}
|
|
|
|
```"""
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("json_github_push__1_commit", expected_topic_name, expected_message)
|
2021-04-09 03:50:04 +02:00
|
|
|
|
|
|
|
def test_json_pingdom_http_up_to_down_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if json pingdom http up to down is handled correctly
|
|
|
|
"""
|
|
|
|
with open("zerver/webhooks/json/fixtures/json_pingdom_http_up_to_down.json") as f:
|
|
|
|
original_fixture = json.load(f)
|
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "JSON"
|
2023-07-22 00:35:07 +02:00
|
|
|
expected_message = f"""```json
|
|
|
|
{json.dumps(original_fixture, indent=2)}
|
|
|
|
```"""
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("json_pingdom_http_up_to_down", expected_topic_name, expected_message)
|
2021-04-09 03:50:04 +02:00
|
|
|
|
|
|
|
def test_json_sentry_event_for_exception_js_message(self) -> None:
|
|
|
|
"""
|
|
|
|
Tests if json sentry event for exception js is handled correctly
|
|
|
|
"""
|
|
|
|
with open("zerver/webhooks/json/fixtures/json_sentry_event_for_exception_js.json") as f:
|
|
|
|
original_fixture = json.load(f)
|
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "JSON"
|
2023-07-22 00:35:07 +02:00
|
|
|
expected_message = f"""```json
|
|
|
|
{json.dumps(original_fixture, indent=2)}
|
|
|
|
```"""
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook(
|
|
|
|
"json_sentry_event_for_exception_js", expected_topic_name, expected_message
|
|
|
|
)
|