diff options
| -rw-r--r-- | tests/bot/cogs/test_antimalware.py | 25 | 
1 files changed, 23 insertions, 2 deletions
| diff --git a/tests/bot/cogs/test_antimalware.py b/tests/bot/cogs/test_antimalware.py index 407fa05c1..eba439afb 100644 --- a/tests/bot/cogs/test_antimalware.py +++ b/tests/bot/cogs/test_antimalware.py @@ -7,7 +7,7 @@ from unittest.mock import AsyncMock, Mock  from discord import NotFound  from bot.cogs import antimalware -from bot.constants import AntiMalware as AntiMalwareConfig, Roles, URLs +from bot.constants import AntiMalware as AntiMalwareConfig, Channels, Roles, URLs  from tests.helpers import MockAttachment, MockBot, MockMessage, MockRole  MODULE = "bot.cogs.antimalware" @@ -21,7 +21,6 @@ class AntiMalwareCogTests(unittest.TestCase):          self.bot = MockBot()          self.cog = antimalware.AntiMalware(self.bot)          self.message = MockMessage() -        self.message.delete = AsyncMock()      def test_message_with_allowed_attachment(self):          """Messages with allowed extensions should not be deleted""" @@ -88,6 +87,28 @@ class AntiMalwareCogTests(unittest.TestCase):              f"please use a code-pasting service such as {URLs.site_schema}{URLs.site_paste}"          )) +    def test_txt_file_redirect_embed(self): +        attachment = MockAttachment(filename="python.txt") +        self.message.attachments = [attachment] +        self.message.channel.send = AsyncMock() + +        coroutine = self.cog.on_message(self.message) +        asyncio.run(coroutine) +        args, kwargs = self.message.channel.send.call_args +        embed = kwargs.pop("embed") +        cmd_channel = self.bot.get_channel(Channels.bot_commands) + +        self.assertEqual(args[0], f"Hey {self.message.author.mention}!") +        self.assertEqual(embed.description, ( +            "**Uh-oh!** It looks like your message got zapped by our spam filter. " +            "We currently don't allow `.txt` attachments, so here are some tips to help you travel safely: \n\n" +            "• If you attempted to send a message longer than 2000 characters, try shortening your message " +            "to fit within the character limit or use a pasting service (see below) \n\n" +            "• If you tried to show someone your code, you can use codeblocks \n(run `!code-blocks` in " +            f"{cmd_channel.mention} for more information) or use a pasting service like: " +            f"\n\n{URLs.site_schema}{URLs.site_paste}" +        )) +      def test_removing_deleted_message_logs(self):          """Removing an already deleted message logs the correct message"""          attachment = MockAttachment(filename="python.asdfsff") | 
