2018-01-15 17:50:12 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
from zerver.webhooks.opbeat.view import get_value
|
|
|
|
|
|
|
|
|
|
|
|
class OpbeatHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'opbeat'
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/opbeat?api_key={api_key}&stream={stream}"
|
2018-01-15 17:50:12 +01:00
|
|
|
FIXTURE_DIR_NAME = 'opbeat'
|
|
|
|
|
|
|
|
def test_comment(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "foo commented on E#2"
|
2018-01-15 17:50:12 +01:00
|
|
|
expected_message = '''
|
|
|
|
**[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
|
|
|
|
>A warning occurred (42 apples)'''
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"new_comment", expected_topic, expected_message, content_type="application/json"
|
|
|
|
)
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_new_app(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "foo"
|
2018-01-15 17:50:12 +01:00
|
|
|
expected_message = '''
|
|
|
|
**foo**
|
|
|
|
App foo created
|
|
|
|
|
|
|
|
**[foo](https://opbeat.com/bar/foo/)**
|
|
|
|
>language: nodejs
|
|
|
|
>framework: custom'''
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"new_app", expected_topic, expected_message, content_type="application/json"
|
|
|
|
)
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_get_empty_value(self) -> None:
|
|
|
|
self.assertEqual(get_value({'key': 'value'}, 'foo'), '')
|
|
|
|
|
|
|
|
def test_no_subject_type(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "test title"
|
2018-01-15 17:50:12 +01:00
|
|
|
expected_message = '''
|
|
|
|
**test title**
|
|
|
|
test summary'''
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"unsupported_object", expected_topic, expected_message, content_type="application/json",
|
2018-01-15 17:50:12 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_error_fixed(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = 'foo marked E#2 as fixed'
|
2018-01-15 17:50:12 +01:00
|
|
|
expected_message = '''
|
|
|
|
**[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
|
|
|
|
>A warning occurred (42 apples)'''
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"error_fixed", expected_topic, expected_message, content_type="application/json"
|
|
|
|
)
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_error_reopened(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = 'foo reopened E#2'
|
2018-01-15 17:50:12 +01:00
|
|
|
expected_message = '''
|
|
|
|
**[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
|
|
|
|
>A warning occurred (42 apples)'''
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"error_reopen", expected_topic, expected_message, content_type="application/json"
|
|
|
|
)
|
2018-01-15 17:50:12 +01:00
|
|
|
|
|
|
|
def test_error_regressed(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = 'E#2 regressed'
|
2018-01-15 17:50:12 +01:00
|
|
|
expected_message = '''
|
|
|
|
**[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
|
|
|
|
>A warning occurred (42 apples)'''
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"new_error", expected_topic, expected_message, content_type="application/json"
|
|
|
|
)
|