cleanup alertmanager client tests
This commit is contained in:
parent
4873abca70
commit
5d2d109da1
1 changed files with 5 additions and 260 deletions
|
@ -1,21 +1,20 @@
|
|||
from __future__ import annotations
|
||||
import json
|
||||
from sys import implementation
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
import aiotools
|
||||
|
||||
import aiohttp
|
||||
from aiohttp import web, web_request
|
||||
import aiohttp.test_utils
|
||||
import nio
|
||||
import aiotools
|
||||
from aiohttp import web, web_request
|
||||
from diskcache import Cache
|
||||
|
||||
from matrix_alertbot.alertmanager import AlertmanagerClient
|
||||
from matrix_alertbot.errors import (
|
||||
AlertNotFoundError,
|
||||
AlertmanagerError,
|
||||
AlertNotFoundError,
|
||||
SilenceNotFoundError,
|
||||
)
|
||||
|
||||
|
@ -293,260 +292,6 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
|
|||
with self.assertRaises(AlertNotFoundError):
|
||||
alertmanager._find_alert("fingerprint2", [{"fingerprint": "fingerprint1"}])
|
||||
|
||||
# fake_session_get.assert_called_once_with("http://localhost:9093/api/v2/alerts")
|
||||
|
||||
# async def test_get_alerts_not_empty(self) -> None:
|
||||
# alerts = await self.alertmanager.get_alerts()
|
||||
|
||||
# self.assertEqual(["alert1", "alert2"], alerts)
|
||||
# # fake_session_get.assert_called_once_with("http://localhost:9093/api/v2/alerts")
|
||||
|
||||
# async def test_get_alerts_raise_alertmanager_error(self) -> None:
|
||||
# with self.assertRaises(AlertmanagerError):
|
||||
# await self.alertmanager.get_alerts()
|
||||
# # fake_session_get.assert_called_once_with("http://localhost:9093/api/v2/alerts")
|
||||
|
||||
# @patch.object(matrix_alertbot.command.Command, "_ack")
|
||||
# async def test_process_ack_command(self, fake_ack: Mock) -> None:
|
||||
# """Tests the callback for InviteMemberEvents"""
|
||||
# # Tests that the bot attempts to join a room after being invited to it
|
||||
|
||||
# fake_message_event = Mock(spec=nio.RoomMessageText)
|
||||
|
||||
# command = Command(
|
||||
# self.fake_client,
|
||||
# self.fake_cache,
|
||||
# self.fake_alertmanager,
|
||||
# self.fake_config,
|
||||
# "ack",
|
||||
# self.fake_room,
|
||||
# fake_message_event,
|
||||
# )
|
||||
# await command.process()
|
||||
|
||||
# @patch.object(matrix_alertbot.command.Command, "_unack")
|
||||
# async def test_process_unack_command(self, fake_unack: Mock) -> None:
|
||||
# """Tests the callback for InviteMemberEvents"""
|
||||
# # Tests that the bot attempts to join a room after being invited to it
|
||||
|
||||
# fake_message_event = Mock(spec=nio.RoomMessageText)
|
||||
|
||||
# for command_word in ("unack", "nack"):
|
||||
# command = Command(
|
||||
# self.fake_client,
|
||||
# self.fake_cache,
|
||||
# self.fake_alertmanager,
|
||||
# self.fake_config,
|
||||
# command_word,
|
||||
# self.fake_room,
|
||||
# fake_message_event,
|
||||
# )
|
||||
# await command.process()
|
||||
|
||||
# # Check that we attempted to process the command
|
||||
# fake_unack.assert_has_calls([call(), call()])
|
||||
|
||||
# @patch.object(matrix_alertbot.command.Command, "_show_help")
|
||||
# async def test_process_help_command(self, fake_help: Mock) -> None:
|
||||
# """Tests the callback for InviteMemberEvents"""
|
||||
# # Tests that the bot attempts to join a room after being invited to it
|
||||
|
||||
# fake_message_event = Mock(spec=nio.RoomMessageText)
|
||||
|
||||
# command = Command(
|
||||
# self.fake_client,
|
||||
# self.fake_cache,
|
||||
# self.fake_alertmanager,
|
||||
# self.fake_config,
|
||||
# "help",
|
||||
# self.fake_room,
|
||||
# fake_message_event,
|
||||
# )
|
||||
# await command.process()
|
||||
|
||||
# # Check that we attempted to process the command
|
||||
# fake_help.assert_called_once()
|
||||
|
||||
# @patch.object(matrix_alertbot.command.Command, "_unknown_command")
|
||||
# async def test_process_unknown_command(self, fake_unknown: Mock) -> None:
|
||||
# """Tests the callback for InviteMemberEvents"""
|
||||
# # Tests that the bot attempts to join a room after being invited to it
|
||||
|
||||
# fake_message_event = Mock(spec=nio.RoomMessageText)
|
||||
|
||||
# command = Command(
|
||||
# self.fake_client,
|
||||
# self.fake_cache,
|
||||
# self.fake_alertmanager,
|
||||
# self.fake_config,
|
||||
# "",
|
||||
# self.fake_room,
|
||||
# fake_message_event,
|
||||
# )
|
||||
# await command.process()
|
||||
|
||||
# # Check that we attempted to process the command
|
||||
# fake_unknown.assert_called_once()
|
||||
|
||||
# async def test_ack_not_in_reply_without_duration(self) -> None:
|
||||
# """Tests the callback for InviteMemberEvents"""
|
||||
# # Tests that the bot attempts to join a room after being invited to it
|
||||
|
||||
# fake_message_event = Mock(spec=nio.RoomMessageText)
|
||||
# fake_message_event.sender = "@some_other_fake_user:example.com"
|
||||
# fake_message_event.body = ""
|
||||
# fake_message_event.source = self.fake_source_not_in_reply
|
||||
|
||||
# command = Command(
|
||||
# self.fake_client,
|
||||
# self.fake_cache,
|
||||
# self.fake_alertmanager,
|
||||
# self.fake_config,
|
||||
# "ack",
|
||||
# self.fake_room,
|
||||
# fake_message_event,
|
||||
# )
|
||||
# await command._ack()
|
||||
|
||||
# # Check that we didn't attempt to create silences
|
||||
# self.fake_alertmanager.create_silence.assert_not_called()
|
||||
# self.fake_client.room_send.assert_not_called()
|
||||
|
||||
# async def test_ack_not_in_reply_with_duration(self) -> None:
|
||||
# """Tests the callback for InviteMemberEvents"""
|
||||
# # Tests that the bot attempts to join a room after being invited to it
|
||||
|
||||
# fake_message_event = Mock(spec=nio.RoomMessageText)
|
||||
# fake_message_event.sender = "@some_other_fake_user:example.com"
|
||||
# fake_message_event.body = ""
|
||||
# fake_message_event.source = self.fake_source_not_in_reply
|
||||
|
||||
# command = Command(
|
||||
# self.fake_client,
|
||||
# self.fake_cache,
|
||||
# self.fake_alertmanager,
|
||||
# self.fake_config,
|
||||
# "ack 2d",
|
||||
# self.fake_room,
|
||||
# fake_message_event,
|
||||
# )
|
||||
# await command._ack()
|
||||
|
||||
# # Check that we didn't attempt to create silences
|
||||
# self.fake_alertmanager.create_silence.assert_not_called()
|
||||
# self.fake_client.room_send.assert_not_called()
|
||||
|
||||
# @patch.object(matrix_alertbot.command, "send_text_to_room")
|
||||
# async def test_ack_in_reply_without_duration(
|
||||
# self, fake_send_text_to_room: Mock
|
||||
# ) -> None:
|
||||
# """Tests the callback for InviteMemberEvents"""
|
||||
# # Tests that the bot attempts to join a room after being invited to it
|
||||
|
||||
# fake_message_event = Mock(spec=nio.RoomMessageText)
|
||||
# fake_message_event.sender = "@some_other_fake_user:example.com"
|
||||
# fake_message_event.body = ""
|
||||
# fake_message_event.source = self.fake_source_in_reply
|
||||
|
||||
# command = Command(
|
||||
# self.fake_client,
|
||||
# self.fake_cache,
|
||||
# self.fake_alertmanager,
|
||||
# self.fake_config,
|
||||
# "ack",
|
||||
# self.fake_room,
|
||||
# fake_message_event,
|
||||
# )
|
||||
# await command._ack()
|
||||
|
||||
# # Check that we attempted to create silences
|
||||
# self.fake_alertmanager.create_silence.assert_has_calls(
|
||||
# list(
|
||||
# call(
|
||||
# fingerprint,
|
||||
# "1d",
|
||||
# fake_message_event.sender,
|
||||
# )
|
||||
# for fingerprint in self.fake_fingerprints.return_value
|
||||
# )
|
||||
# )
|
||||
# fake_send_text_to_room.assert_called_once_with(
|
||||
# self.fake_client,
|
||||
# self.fake_room.room_id,
|
||||
# "Created 2 silences with a duration of 1d.",
|
||||
# )
|
||||
|
||||
# @patch.object(matrix_alertbot.command, "send_text_to_room")
|
||||
# async def test_ack_in_reply_with_duration(
|
||||
# self, fake_send_text_to_room: Mock
|
||||
# ) -> None:
|
||||
# """Tests the callback for InviteMemberEvents"""
|
||||
# # Tests that the bot attempts to join a room after being invited to it
|
||||
|
||||
# fake_message_event = Mock(spec=nio.RoomMessageText)
|
||||
# fake_message_event.sender = "@some_other_fake_user:example.com"
|
||||
# fake_message_event.body = ""
|
||||
# fake_message_event.source = self.fake_source_in_reply
|
||||
|
||||
# command = Command(
|
||||
# self.fake_client,
|
||||
# self.fake_cache,
|
||||
# self.fake_alertmanager,
|
||||
# self.fake_config,
|
||||
# "ack 2d",
|
||||
# self.fake_room,
|
||||
# fake_message_event,
|
||||
# )
|
||||
# await command._ack()
|
||||
|
||||
# # Check that we attempted to create silences
|
||||
# self.fake_alertmanager.create_silence.assert_has_calls(
|
||||
# list(
|
||||
# call(
|
||||
# fingerprint,
|
||||
# "2d",
|
||||
# fake_message_event.sender,
|
||||
# )
|
||||
# for fingerprint in self.fake_fingerprints.return_value
|
||||
# )
|
||||
# )
|
||||
# fake_send_text_to_room.assert_called_once_with(
|
||||
# self.fake_client,
|
||||
# self.fake_room.room_id,
|
||||
# "Created 2 silences with a duration of 2d.",
|
||||
# )
|
||||
|
||||
# @patch.object(matrix_alertbot.command, "send_text_to_room")
|
||||
# async def test_unack_in_reply(self, fake_send_text_to_room: Mock) -> None:
|
||||
# """Tests the callback for InviteMemberEvents"""
|
||||
# # Tests that the bot attempts to join a room after being invited to it
|
||||
|
||||
# fake_message_event = Mock(spec=nio.RoomMessageText)
|
||||
# fake_message_event.sender = "@some_other_fake_user:example.com"
|
||||
# fake_message_event.body = ""
|
||||
# fake_message_event.source = self.fake_source_in_reply
|
||||
|
||||
# command = Command(
|
||||
# self.fake_client,
|
||||
# self.fake_cache,
|
||||
# self.fake_alertmanager,
|
||||
# self.fake_config,
|
||||
# "unack",
|
||||
# self.fake_room,
|
||||
# fake_message_event,
|
||||
# )
|
||||
# await command._unack()
|
||||
|
||||
# # Check that we attempted to create silences
|
||||
# self.fake_alertmanager.delete_silence.assert_has_calls(
|
||||
# list(
|
||||
# call(fingerprint) for fingerprint in self.fake_fingerprints.return_value
|
||||
# )
|
||||
# )
|
||||
# fake_send_text_to_room.assert_called_with(
|
||||
# self.fake_client, self.fake_room.room_id, "Removed 2 silences."
|
||||
# )
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in a new issue