aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Jannes Jonkers <[email protected]>2020-05-07 19:45:57 +0200
committerGravatar Jannes Jonkers <[email protected]>2020-05-07 19:45:57 +0200
commit3913a8eba46bf98bd09e13145da33f7a09f77960 (patch)
tree002d77a6578219c790726c3c20a1518de36cda9d /tests
parentAntiMalware Tests - Added unittest for messages send by staff (diff)
AntiMalware Tests - Added unittest for the embed for a python file.
Diffstat (limited to 'tests')
-rw-r--r--tests/bot/cogs/test_antimalware.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/bot/cogs/test_antimalware.py b/tests/bot/cogs/test_antimalware.py
index e3fd477fa..0bb5af943 100644
--- a/tests/bot/cogs/test_antimalware.py
+++ b/tests/bot/cogs/test_antimalware.py
@@ -3,7 +3,7 @@ import unittest
from unittest.mock import AsyncMock
from bot.cogs import antimalware
-from bot.constants import Roles
+from bot.constants import Roles, URLs
from tests.helpers import MockAttachment, MockBot, MockMessage, MockRole
@@ -28,16 +28,20 @@ class AntiMalwareCogTests(unittest.TestCase):
attachment = MockAttachment(filename="python.asdfsff")
self.message.attachments = [attachment]
self.message.guild = None
+
coroutine = self.cog.on_message(self.message)
asyncio.run(coroutine)
+
self.message.delete.assert_not_called()
def test_message_with_illegal_extension_gets_deleted(self):
"""A message containing an illegal extension should send an embed."""
attachment = MockAttachment(filename="python.asdfsff")
self.message.attachments = [attachment]
+
coroutine = self.cog.on_message(self.message)
asyncio.run(coroutine)
+
self.message.delete.assert_called_once()
def test_message_send_by_staff(self):
@@ -46,6 +50,25 @@ class AntiMalwareCogTests(unittest.TestCase):
self.message.author.roles.append(moderator_role)
attachment = MockAttachment(filename="python.asdfsff")
self.message.attachments = [attachment]
+
coroutine = self.cog.on_message(self.message)
asyncio.run(coroutine)
+
self.message.delete.assert_not_called()
+
+ def test_python_file_redirect_embed(self):
+ """A message containing a .python file should result in an embed redirecting the user to our paste site"""
+ attachment = MockAttachment(filename="python.py")
+ 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")
+
+ self.assertEqual(args[0], f"Hey {self.message.author.mention}!")
+ self.assertEqual(embed.description, (
+ "It looks like you tried to attach a Python file - "
+ f"please use a code-pasting service such as {URLs.site_schema}{URLs.site_paste}"
+ ))