formatters: add github

This commit is contained in:
Guilhem Saurel
2021-08-27 23:47:07 +02:00
parent 4bcdb25c80
commit 6b5d6e6e87
9 changed files with 136 additions and 33 deletions

View File

@@ -1,4 +1,8 @@
"""Test module for grafana formatter."""
"""
Test module for grafana formatter.
ref https://grafana.com/docs/grafana/latest/alerting/old-alerting/notifications/#webhook
"""
import unittest
@@ -7,32 +11,6 @@ import nio
from .start import BOT_URL, FULL_ID, KEY, MATRIX_ID, MATRIX_PW, MATRIX_URL
# ref https://grafana.com/docs/grafana/latest/alerting/old-alerting/notifications/#webhook
EXAMPLE_GRAFANA_REQUEST = """
{
"dashboardId":1,
"evalMatches":[
{
"value":1,
"metric":"Count",
"tags":{}
}
],
"imageUrl":"https://grafana.com/assets/img/blog/mixed_styles.png",
"message":"Notification Message",
"orgId":1,
"panelId":2,
"ruleId":1,
"ruleName":"Panel Title alert",
"ruleUrl":"http://localhost:3000/d/hZ7BuVbWz/test-dashboard?fullscreen\u0026edit\u0026tab=alert\u0026panelId=2\u0026orgId=1",
"state":"alerting",
"tags":{
"tag name":"tag value"
},
"title":"[Alerting] Panel Title alert"
}
"""
class GrafanaFormatterTest(unittest.IsolatedAsyncioTestCase):
"""Grafana formatter test class."""
@@ -45,11 +23,13 @@ class GrafanaFormatterTest(unittest.IsolatedAsyncioTestCase):
await client.login(MATRIX_PW)
room = await client.room_create()
with open("tests/example_grafana.json") as f:
example_grafana_request = f.read()
self.assertEqual(
httpx.post(
f"{BOT_URL}/{room.room_id}",
params={"formatter": "grafana", "key": KEY},
content=EXAMPLE_GRAFANA_REQUEST,
content=example_grafana_request,
).json(),
{"status": 200, "ret": "OK"},
)