rename /alert endpoint to /alerts

This commit is contained in:
HgO 2022-07-12 18:22:11 +02:00
parent fa39283bf4
commit c4752d8192
2 changed files with 7 additions and 7 deletions

View file

@ -23,7 +23,7 @@ async def get_health(request: web_request.Request) -> web.Response:
return web.Response(status=200)
@routes.post("/alert")
@routes.post("/alerts")
async def create_alert(request: web_request.Request) -> web.Response:
data = await request.json()
logger.info(f"Received alert: {data}")

View file

@ -64,7 +64,7 @@ class WebhookApplicationTestCase(aiohttp.test_utils.AioHTTPTestCase):
@patch.object(matrix_alertbot.webhook, "send_text_to_room")
async def test_post_alert(self, fake_send_text_to_room: Mock) -> None:
data = self.fake_alerts
async with self.client.request("POST", "/alert", json=data) as response:
async with self.client.request("POST", "/alerts", json=data) as response:
self.assertEqual(200, response.status)
fake_send_text_to_room.assert_called_once_with(
self.fake_client,
@ -84,7 +84,7 @@ class WebhookApplicationTestCase(aiohttp.test_utils.AioHTTPTestCase):
async def test_post_alert_with_empty_data(
self, fake_send_text_to_room: Mock
) -> None:
async with self.client.request("POST", "/alert", json={}) as response:
async with self.client.request("POST", "/alerts", json={}) as response:
self.assertEqual(400, response.status)
error_msg = await response.text()
self.assertEqual("Data must contain 'alerts' key.", error_msg)
@ -95,7 +95,7 @@ class WebhookApplicationTestCase(aiohttp.test_utils.AioHTTPTestCase):
self, fake_send_text_to_room: Mock
) -> None:
data: Dict = {"alerts": []}
async with self.client.request("POST", "/alert", json=data) as response:
async with self.client.request("POST", "/alerts", json=data) as response:
self.assertEqual(400, response.status)
error_msg = await response.text()
self.assertEqual("Alerts cannot be empty.", error_msg)
@ -106,7 +106,7 @@ class WebhookApplicationTestCase(aiohttp.test_utils.AioHTTPTestCase):
self, fake_send_text_to_room: Mock
) -> None:
data = {"alerts": "invalid"}
async with self.client.request("POST", "/alert", json=data) as response:
async with self.client.request("POST", "/alerts", json=data) as response:
self.assertEqual(400, response.status)
error_msg = await response.text()
self.assertEqual("Alerts must be a list.", error_msg)
@ -117,7 +117,7 @@ class WebhookApplicationTestCase(aiohttp.test_utils.AioHTTPTestCase):
self, fake_send_text_to_room: Mock
) -> None:
data: Dict = {"alerts": [{}]}
async with self.client.request("POST", "/alert", json=data) as response:
async with self.client.request("POST", "/alerts", json=data) as response:
self.assertEqual(400, response.status)
error_msg = await response.text()
self.assertEqual("Invalid alert: {}.", error_msg)
@ -132,7 +132,7 @@ class WebhookApplicationTestCase(aiohttp.test_utils.AioHTTPTestCase):
self, fake_send_text_to_room: Mock
) -> None:
data = self.fake_alerts
async with self.client.request("POST", "/alert", json=data) as response:
async with self.client.request("POST", "/alerts", json=data) as response:
self.assertEqual(500, response.status)
error_msg = await response.text()
self.assertEqual(