aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shivansh <[email protected]>2021-05-12 11:19:59 +0530
committerGravatar Shivansh-007 <[email protected]>2021-10-11 12:05:44 +0530
commit40a57a1dad45f0b32f2c5137e9c36d9c6df183fd (patch)
treec67e0daf8c205704cb888cd33a76e7f317ca68bc
parentUse raw message delete listener (diff)
Update tests for message link embeds
This commit updates the test in accordance with 0b35f2a and 0c5561d.
Diffstat (limited to '')
-rw-r--r--bot/exts/moderation/incidents.py2
-rw-r--r--tests/bot/exts/moderation/test_incidents.py42
2 files changed, 29 insertions, 15 deletions
diff --git a/bot/exts/moderation/incidents.py b/bot/exts/moderation/incidents.py
index 7ef4af3df..97bb32591 100644
--- a/bot/exts/moderation/incidents.py
+++ b/bot/exts/moderation/incidents.py
@@ -422,7 +422,7 @@ class Incidents(Cog):
log.trace("Deletion was confirmed")
# Deletes the message link embeds found in cache from the channel and cache.
- await self.delete_msg_link_embed(incident)
+ await self.delete_msg_link_embed(incident.id)
async def resolve_message(self, message_id: int) -> t.Optional[discord.Message]:
"""
diff --git a/tests/bot/exts/moderation/test_incidents.py b/tests/bot/exts/moderation/test_incidents.py
index 875b76057..6e97d31af 100644
--- a/tests/bot/exts/moderation/test_incidents.py
+++ b/tests/bot/exts/moderation/test_incidents.py
@@ -833,27 +833,41 @@ class TestMessageLinkEmbeds(TestIncidents):
f"as they break our rules: \n{', '.join(msg_links)}"
)
- embeds = await incidents.extract_message_links(incident_msg, self.cog_instance.bot)
- description = (
- f"**Author:** {format_user(msg.author)}\n"
- f"**Channel:** {msg.channel.mention} ({msg.channel.category}/#{msg.channel.name})\n"
- f"**Content:** {('Hello, World!' * 3000)[:300] + '...'}\n"
- )
+ with patch(
+ "bot.exts.moderation.incidents.Incidents.extract_message_links", AsyncMock()
+ ) as mock_extract_message_links:
+ embeds = mock_extract_message_links(incident_msg)
+ description = (
+ f"**Author:** {format_user(msg.author)}\n"
+ f"**Channel:** {msg.channel.mention} ({msg.channel.category}/#{msg.channel.name})\n"
+ f"**Content:** {('Hello, World!' * 3000)[:300] + '...'}\n"
+ )
- # Check number of embeds returned with number of valid links
- self.assertEqual(len(embeds), 2)
+ # Check number of embeds returned with number of valid links
+ self.assertEqual(len(embeds), 2)
- # Check for the embed descriptions
- for embed in embeds:
- self.assertEqual(embed.description, description)
+ # Check for the embed descriptions
+ for embed in embeds:
+ self.assertEqual(embed.description, description)
@patch("bot.exts.moderation.incidents.is_incident", MagicMock(return_value=True))
async def test_incident_message_edit(self):
"""Edit the incident message and check whether `extract_message_links` is called or not."""
self.cog_instance.incidents_webhook = MockAsyncWebhook() # Patch in our webhook
- edited_msg = MockMessage(id=123)
- with patch("bot.exts.moderation.incidents.extract_message_links", AsyncMock()) as mock_extract_message_links:
- await self.cog_instance.on_message_edit(MockMessage(id=123), edited_msg)
+ text_channel = MockTextChannel()
+ self.cog_instance.bot.get_channel = MagicMock(return_value=text_channel)
+ text_channel.fetch_message = AsyncMock(return_value=MockMessage())
+
+ payload = AsyncMock(
+ discord.RawMessageUpdateEvent,
+ channel_id=123,
+ message_id=456
+ )
+
+ with patch(
+ "bot.exts.moderation.incidents.Incidents.extract_message_links", AsyncMock()
+ ) as mock_extract_message_links:
+ await self.cog_instance.on_raw_message_edit(payload)
mock_extract_message_links.assert_awaited_once()