|
|
|
@ -36,7 +36,6 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
self.fake_config.allowed_rooms = [self.fake_room.room_id]
|
|
|
|
|
self.fake_config.allowed_reactions = ["🤫", "🤗"]
|
|
|
|
|
self.fake_config.insult_reactions = ["🤗"]
|
|
|
|
|
self.fake_config.command_prefix = "!alert "
|
|
|
|
|
self.fake_config.user_ids = [self.fake_matrix_client.user_id]
|
|
|
|
|
|
|
|
|
|
self.fake_matrix_client_pool = Mock(
|
|
|
|
@ -101,8 +100,8 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback.CommandFactory, "create", autospec=True)
|
|
|
|
|
async def test_message_without_prefix(self, fake_command_create: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText without any command prefix"""
|
|
|
|
|
async def test_message_without_mention(self, fake_command_create: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText without any mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
@ -117,12 +116,12 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.command, "HelpCommand", autospec=True)
|
|
|
|
|
async def test_message_help_client_not_in_pool(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText without any command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText without any mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.event_id = "some event id"
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
|
fake_message_event.body = "!alert help"
|
|
|
|
|
fake_message_event.body = "@fake_user help"
|
|
|
|
|
fake_message_event.source = {"content": {}}
|
|
|
|
|
|
|
|
|
|
self.fake_matrix_client_pool.matrix_client = None
|
|
|
|
@ -134,15 +133,15 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
fake_command.assert_not_called()
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.command, "HelpCommand", autospec=True)
|
|
|
|
|
async def test_message_help_not_in_reply_with_prefix(
|
|
|
|
|
async def test_message_help_not_in_reply_with_mention(
|
|
|
|
|
self, fake_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.event_id = "some event id"
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
|
fake_message_event.body = "!alert help"
|
|
|
|
|
fake_message_event.body = "@fake_user help"
|
|
|
|
|
fake_message_event.source = {"content": {}}
|
|
|
|
|
|
|
|
|
|
# Pretend that we received a text message event
|
|
|
|
@ -162,14 +161,14 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
fake_command.return_value.process.assert_called_once()
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.command, "HelpCommand", autospec=True)
|
|
|
|
|
async def test_message_help_in_reply_with_prefix(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
async def test_message_help_in_reply_with_mention(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.event_id = "some event id"
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
|
fake_message_event.body = "!alert help"
|
|
|
|
|
fake_message_event.body = "@fake_user help"
|
|
|
|
|
fake_message_event.source = {
|
|
|
|
|
"content": {
|
|
|
|
|
"m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}}
|
|
|
|
@ -194,7 +193,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.command.CommandFactory, "create", autospec=True)
|
|
|
|
|
async def test_ignore_message_sent_by_bot(self, fake_create_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
@ -210,7 +209,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_ignore_message_sent_on_unauthorized_room(
|
|
|
|
|
self, fake_create_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
|
|
|
|
|
self.fake_room.room_id = "!unauthorizedroom@example.com"
|
|
|
|
@ -225,15 +224,15 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
fake_create_command.assert_not_called()
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.command, "AckAlertCommand", autospec=True)
|
|
|
|
|
async def test_message_ack_not_in_reply_with_prefix(
|
|
|
|
|
async def test_message_ack_not_in_reply_with_mention(
|
|
|
|
|
self, fake_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.event_id = "some event id"
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
|
fake_message_event.body = "!alert ack"
|
|
|
|
|
fake_message_event.body = "@fake_user ack"
|
|
|
|
|
fake_message_event.source = {"content": {}}
|
|
|
|
|
|
|
|
|
|
# Pretend that we received a text message event
|
|
|
|
@ -243,13 +242,48 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
fake_command.assert_not_called()
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.command, "AckAlertCommand", autospec=True)
|
|
|
|
|
async def test_message_ack_in_reply_with_prefix(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
async def test_message_ack_in_reply_with_full_mention(
|
|
|
|
|
self, fake_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.event_id = "some event id"
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
|
fake_message_event.body = "!alert ack"
|
|
|
|
|
fake_message_event.body = "@fake_user:example.com ack"
|
|
|
|
|
fake_message_event.source = {
|
|
|
|
|
"content": {
|
|
|
|
|
"m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Pretend that we received a text message event
|
|
|
|
|
await self.callbacks.message(self.fake_room, fake_message_event)
|
|
|
|
|
|
|
|
|
|
# Check that the command was not executed
|
|
|
|
|
fake_command.assert_called_once_with(
|
|
|
|
|
self.fake_matrix_client,
|
|
|
|
|
self.fake_cache,
|
|
|
|
|
self.fake_alertmanager_client,
|
|
|
|
|
self.fake_config,
|
|
|
|
|
self.fake_room,
|
|
|
|
|
fake_message_event.sender,
|
|
|
|
|
fake_message_event.event_id,
|
|
|
|
|
"some alert event id",
|
|
|
|
|
(),
|
|
|
|
|
)
|
|
|
|
|
fake_command.return_value.process.assert_called_once()
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.command, "AckAlertCommand", autospec=True)
|
|
|
|
|
async def test_message_ack_in_reply_with_short_mention(
|
|
|
|
|
self, fake_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.event_id = "some event id"
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
|
fake_message_event.body = "fake_user ack"
|
|
|
|
|
fake_message_event.source = {
|
|
|
|
|
"content": {
|
|
|
|
|
"m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}}
|
|
|
|
@ -274,15 +308,15 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
fake_command.return_value.process.assert_called_once()
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "UnackAlertCommand", autospec=True)
|
|
|
|
|
async def test_message_unack_not_in_reply_with_prefix(
|
|
|
|
|
async def test_message_unack_not_in_reply_with_mention(
|
|
|
|
|
self, fake_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.event_id = "some event id"
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
|
fake_message_event.body = "!alert unack"
|
|
|
|
|
fake_message_event.body = "@fake_user unack"
|
|
|
|
|
fake_message_event.source = {"content": {}}
|
|
|
|
|
|
|
|
|
|
# Pretend that we received a text message event
|
|
|
|
@ -292,13 +326,15 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
fake_command.assert_not_called()
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.command, "UnackAlertCommand", autospec=True)
|
|
|
|
|
async def test_message_unack_in_reply_with_prefix(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
async def test_message_unack_in_reply_with_mention(
|
|
|
|
|
self, fake_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.event_id = "some event id"
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
|
fake_message_event.body = "!alert unack"
|
|
|
|
|
fake_message_event.body = "@fake_user unack"
|
|
|
|
|
fake_message_event.source = {
|
|
|
|
|
"content": {
|
|
|
|
|
"m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}}
|
|
|
|
@ -327,12 +363,12 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_message_raise_exception(
|
|
|
|
|
self, fake_command: Mock, fake_logger
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_message_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_message_event.event_id = "some event id"
|
|
|
|
|
fake_message_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
|
fake_message_event.body = "!alert ack"
|
|
|
|
|
fake_message_event.body = "@fake_user ack"
|
|
|
|
|
fake_message_event.source = {
|
|
|
|
|
"content": {
|
|
|
|
|
"m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}}
|
|
|
|
@ -364,7 +400,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True)
|
|
|
|
|
async def test_reaction_client_not_in_pool(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_alert_event.event_id = "some alert event id"
|
|
|
|
@ -390,8 +426,10 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "AngryUserCommand", autospec=True)
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True)
|
|
|
|
|
async def test_reaction_to_existing_alert(self, fake_command: Mock, fake_angry_user_command) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
async def test_reaction_to_existing_alert(
|
|
|
|
|
self, fake_command: Mock, fake_angry_user_command
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_alert_event.event_id = "some alert event id"
|
|
|
|
@ -433,7 +471,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_insult_reaction(
|
|
|
|
|
self, fake_command: Mock, fake_angry_user_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_alert_event.event_id = "some alert event id"
|
|
|
|
@ -481,7 +519,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True)
|
|
|
|
|
async def test_reaction_to_inexistent_event(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event_id = "some alert event id"
|
|
|
|
|
|
|
|
|
@ -509,7 +547,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_reaction_to_event_not_from_bot_user(
|
|
|
|
|
self, fake_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_alert_event.event_id = "some alert event id"
|
|
|
|
@ -541,7 +579,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_reaction_raise_exception(
|
|
|
|
|
self, fake_command: Mock, fake_logger: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event = Mock(spec=nio.RoomMessageText)
|
|
|
|
|
fake_alert_event.event_id = "some alert event id"
|
|
|
|
@ -584,7 +622,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True)
|
|
|
|
|
async def test_reaction_unknown(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event_id = "some alert event id"
|
|
|
|
|
|
|
|
|
@ -604,7 +642,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True)
|
|
|
|
|
async def test_ignore_reaction_sent_by_bot_user(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event_id = "some alert event id"
|
|
|
|
|
|
|
|
|
@ -626,7 +664,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_ignore_reaction_in_unauthorized_room(
|
|
|
|
|
self, fake_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
self.fake_room.room_id = "!unauthorizedroom@example.com"
|
|
|
|
|
|
|
|
|
@ -648,7 +686,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "UnackAlertCommand", autospec=True)
|
|
|
|
|
async def test_redaction_client_not_in_pool(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event_id = "some alert event id"
|
|
|
|
|
|
|
|
|
@ -670,7 +708,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "UnackAlertCommand", autospec=True)
|
|
|
|
|
async def test_redaction(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event_id = "some alert event id"
|
|
|
|
|
|
|
|
|
@ -703,7 +741,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_redaction_raise_exception(
|
|
|
|
|
self, fake_command: Mock, fake_logger
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_alert_event_id = "some alert event id"
|
|
|
|
|
|
|
|
|
@ -739,7 +777,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(matrix_alertbot.callback, "UnackAlertCommand", autospec=True)
|
|
|
|
|
async def test_ignore_redaction_sent_by_bot_user(self, fake_command: Mock) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_redaction_event = Mock(spec=nio.RedactionEvent)
|
|
|
|
|
fake_redaction_event.sender = self.fake_matrix_client.user_id
|
|
|
|
@ -758,7 +796,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_ignore_redaction_in_unauthorized_room(
|
|
|
|
|
self, fake_command: Mock
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
self.fake_room.room_id = "!unauthorizedroom@example.com"
|
|
|
|
|
|
|
|
|
@ -776,7 +814,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
self.fake_cache.__getitem__.assert_not_called()
|
|
|
|
|
|
|
|
|
|
async def test_key_verification_start(self) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
@ -800,7 +838,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
self.fake_matrix_client.to_device.assert_called_once_with(fake_sas.share_key())
|
|
|
|
|
|
|
|
|
|
async def test_key_verification_start_with_emoji_not_supported(self) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
@ -824,7 +862,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_key_verification_start_with_accept_key_verification_error(
|
|
|
|
|
self,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
@ -854,7 +892,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
async def test_key_verification_start_with_to_device_error(
|
|
|
|
|
self,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
@ -880,7 +918,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
self.fake_matrix_client.to_device.assert_called_once_with(fake_sas.share_key())
|
|
|
|
|
|
|
|
|
|
async def test_key_verification_cancel(self) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_key_verification_event = Mock(spec=nio.KeyVerificationCancel)
|
|
|
|
|
fake_key_verification_event.sender = "@some_other_fake_user:example.com"
|
|
|
|
@ -892,7 +930,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
# Check that we attempted to execute the command
|
|
|
|
|
|
|
|
|
|
async def test_key_verification_confirm(self) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
@ -917,7 +955,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
async def test_key_verification_confirm_with_error(self) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
@ -946,7 +984,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
async def test_key_verification_end(self) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
@ -967,7 +1005,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
self.fake_matrix_client.to_device.assert_called_once_with(fake_sas.get_mac())
|
|
|
|
|
|
|
|
|
|
async def test_key_verification_end_with_missing_transaction_id(self) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
@ -987,7 +1025,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
self.fake_matrix_client.to_device.assert_not_called()
|
|
|
|
|
|
|
|
|
|
async def test_key_verification_end_with_mac_error(self) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
@ -1008,7 +1046,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase):
|
|
|
|
|
self.fake_matrix_client.to_device.assert_not_called()
|
|
|
|
|
|
|
|
|
|
async def test_key_verification_end_with_to_device_error(self) -> None:
|
|
|
|
|
"""Tests the callback for RoomMessageText with the command prefix"""
|
|
|
|
|
"""Tests the callback for RoomMessageText with a mention of the bot"""
|
|
|
|
|
# Tests that the bot process messages in the room that contain a command
|
|
|
|
|
fake_transaction_id = "fake transaction id"
|
|
|
|
|
|
|
|
|
|