2018-01-15 17:50:12 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
2022-10-09 15:29:36 +02:00
|
|
|
from zerver.lib.validator import wrap_wild_value
|
2018-01-15 17:50:12 +01:00
|
|
|
from zerver.webhooks.opbeat.view import get_value
|
|
|
|
|
|
|
|
|
|
|
|
class OpbeatHookTests(WebhookTestCase):
|
2024-05-04 22:02:50 +02:00
|
|
|
CHANNEL_NAME = "opbeat"
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/opbeat?api_key={api_key}&stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "opbeat"
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_comment(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "foo commented on E#2"
|
2021-07-05 17:55:02 +02:00
|
|
|
expected_message = """\
|
2018-01-15 17:50:12 +01:00
|
|
|
**[foo commented on E#2](https://opbeat.com/foo/test-flask-app/errors/2/#activity-5df00003ea4e42458db48446692f6d37)**
|
|
|
|
test comment
|
|
|
|
|
|
|
|
|
|
|
|
**[E#2](https://opbeat.com/foo/test-flask-app/errors/2/)**
|
|
|
|
|
|
|
|
>**Most recent Occurrence**
|
|
|
|
>in app.py
|
2021-02-12 08:20:45 +01:00
|
|
|
>A warning occurred (42 apples)"""
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2024-01-17 15:53:30 +01:00
|
|
|
"new_comment", expected_topic_name, expected_message, content_type="application/json"
|
2020-08-23 15:49:24 +02:00
|
|
|
)
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_new_app(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "foo"
|
2021-07-05 17:55:02 +02:00
|
|
|
expected_message = """\
|
2018-01-15 17:50:12 +01:00
|
|
|
**foo**
|
|
|
|
App foo created
|
|
|
|
|
|
|
|
**[foo](https://opbeat.com/bar/foo/)**
|
|
|
|
>language: nodejs
|
2021-02-12 08:20:45 +01:00
|
|
|
>framework: custom"""
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2024-01-17 15:53:30 +01:00
|
|
|
"new_app", expected_topic_name, expected_message, content_type="application/json"
|
2020-08-23 15:49:24 +02:00
|
|
|
)
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_get_empty_value(self) -> None:
|
2022-10-09 15:29:36 +02:00
|
|
|
test_dictionary = wrap_wild_value("test_dictionary", {"key": "value"})
|
|
|
|
self.assertEqual(get_value(test_dictionary, "foo"), "")
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_no_subject_type(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "test title"
|
2021-07-05 17:55:02 +02:00
|
|
|
expected_message = """\
|
2018-01-15 17:50:12 +01:00
|
|
|
**test title**
|
2021-02-12 08:20:45 +01:00
|
|
|
test summary"""
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"unsupported_object",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message,
|
|
|
|
content_type="application/json",
|
2018-01-15 17:50:12 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_error_fixed(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "foo marked E#2 as fixed"
|
2021-07-05 17:55:02 +02:00
|
|
|
expected_message = """\
|
2018-01-15 17:50:12 +01:00
|
|
|
**[foo marked E#2 as fixed](https://opbeat.com/test_org/test-flask-app/errors/2/#activity-bf991a45d9184b0ca6fb3d48d3db4c38)**
|
|
|
|
foo marked the error group as fixed
|
|
|
|
|
|
|
|
**[E#2](https://opbeat.com/test_org/test-flask-app/errors/2/)**
|
|
|
|
|
|
|
|
>**Most recent Occurrence**
|
|
|
|
>in app.py
|
2021-02-12 08:20:45 +01:00
|
|
|
>A warning occurred (42 apples)"""
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2024-01-17 15:53:30 +01:00
|
|
|
"error_fixed", expected_topic_name, expected_message, content_type="application/json"
|
2020-08-23 15:49:24 +02:00
|
|
|
)
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_error_reopened(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "foo reopened E#2"
|
2021-07-05 17:55:02 +02:00
|
|
|
expected_message = """\
|
2018-01-15 17:50:12 +01:00
|
|
|
**[foo reopened E#2](https://opbeat.com/test_org/test-flask-app/errors/2/#activity-38a556dfc0b04a59a586359bbce1463d)**
|
|
|
|
foo reopened the error group
|
|
|
|
|
|
|
|
**[E#2](https://opbeat.com/test_org/test-flask-app/errors/2/)**
|
|
|
|
|
|
|
|
>**Most recent Occurrence**
|
|
|
|
>in app.py
|
2021-02-12 08:20:45 +01:00
|
|
|
>A warning occurred (42 apples)"""
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2024-01-17 15:53:30 +01:00
|
|
|
"error_reopen", expected_topic_name, expected_message, content_type="application/json"
|
2020-08-23 15:49:24 +02:00
|
|
|
)
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_error_regressed(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "E#2 regressed"
|
2021-07-05 17:55:02 +02:00
|
|
|
expected_message = """\
|
2018-01-15 17:50:12 +01:00
|
|
|
**[E#2 regressed](https://opbeat.com/test_org/test-flask-app/errors/2/#activity-c0396f38323a4fa7b314f87d5ed9cdd2)**
|
|
|
|
The error group regressed
|
|
|
|
|
|
|
|
**[E#2](https://opbeat.com/test_org/test-flask-app/errors/2/)**
|
|
|
|
|
|
|
|
>**Most recent Occurrence**
|
|
|
|
>in app.py
|
2021-02-12 08:20:45 +01:00
|
|
|
>A warning occurred (42 apples)"""
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2024-01-17 15:53:30 +01:00
|
|
|
"new_error", expected_topic_name, expected_message, content_type="application/json"
|
2020-08-23 15:49:24 +02:00
|
|
|
)
|