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)'''
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('new_comment', expected_topic, expected_message,
|
2018-01-15 17:50:12 +01:00
|
|
|
content_type="application/json")
|
|
|
|
|
|
|
|
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'''
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('new_app', expected_topic, expected_message,
|
2018-01-15 17:50:12 +01:00
|
|
|
content_type="application/json")
|
|
|
|
|
|
|
|
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'''
|
|
|
|
self.send_and_test_stream_message(
|
|
|
|
'unsupported_object',
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic,
|
2018-01-15 17:50:12 +01:00
|
|
|
expected_message,
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
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)'''
|
|
|
|
self.send_and_test_stream_message(
|
2018-11-09 20:33:58 +01:00
|
|
|
'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)'''
|
|
|
|
self.send_and_test_stream_message(
|
2018-11-09 20:33:58 +01:00
|
|
|
'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)'''
|
|
|
|
self.send_and_test_stream_message(
|
2018-11-09 20:33:58 +01:00
|
|
|
'new_error', expected_topic, expected_message, content_type='application/json')
|