aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2020-06-21 14:21:18 +0200
committerGravatar kwzrd <[email protected]>2020-06-21 14:21:18 +0200
commita8d179d9b04f54b20c5e870bcfa85c78c42c8dca (patch)
treea79cfba507abdfc3fcefb2f1c6cb7ffbba77e7ed /tests
parentIncidents: implement `make_username` helper (diff)
Incidents: append `actioned_by` to webhook username
Incident author and the moderator who actioned report are now passed through `make_username` to create the webhook username. Tests adjusted as appropriate.
Diffstat (limited to 'tests')
-rw-r--r--tests/bot/cogs/moderation/test_incidents.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/tests/bot/cogs/moderation/test_incidents.py b/tests/bot/cogs/moderation/test_incidents.py
index 5700a5a35..a811868e5 100644
--- a/tests/bot/cogs/moderation/test_incidents.py
+++ b/tests/bot/cogs/moderation/test_incidents.py
@@ -307,7 +307,9 @@ class TestArchive(TestIncidents):
propagate out of the method, which is just as important.
"""
self.cog_instance.bot.fetch_webhook = AsyncMock(side_effect=mock_404)
- self.assertFalse(await self.cog_instance.archive(incident=MockMessage(), outcome=MagicMock()))
+
+ result = await self.cog_instance.archive(incident=MockMessage(), outcome=MagicMock(), actioned_by=MockMember())
+ self.assertFalse(result)
async def test_archive_relays_incident(self):
"""
@@ -332,12 +334,18 @@ class TestArchive(TestIncidents):
author=MockUser(name="author_name", avatar_url="author_avatar"),
id=123,
)
- archive_return = await self.cog_instance.archive(incident, outcome=MagicMock(value="A"))
+
+ with patch("bot.cogs.moderation.incidents.make_username", MagicMock(return_value="generated_username")):
+ archive_return = await self.cog_instance.archive(
+ incident=incident,
+ outcome=MagicMock(value="A"),
+ actioned_by=MockMember(name="moderator"),
+ )
# Check that the webhook was dispatched correctly
webhook.send.assert_called_once_with(
content="pingless message",
- username="author_name",
+ username="generated_username",
avatar_url="author_avatar",
wait=True,
)
@@ -354,7 +362,8 @@ class TestArchive(TestIncidents):
Discord will reject any webhook with "clyde" in the username field, as it impersonates
the official Clyde bot. Since we do not control what the username will be (the incident
- author name is used), we must ensure the name is cleansed, otherwise the relay may fail.
+ author name, and actioning moderator names are used), we must ensure the name is cleansed,
+ otherwise the relay may fail.
This test assumes the username is passed as a kwarg. If this test fails, please review
whether the passed argument is being retrieved correctly.
@@ -362,9 +371,11 @@ class TestArchive(TestIncidents):
webhook = MockAsyncWebhook()
self.cog_instance.bot.fetch_webhook = AsyncMock(return_value=webhook)
- message_from_clyde = MockMessage(author=MockUser(name="clyde the great"))
- await self.cog_instance.archive(message_from_clyde, MagicMock(incidents.Signal))
+ # The `make_username` helper will return a string with "clyde" in it
+ with patch("bot.cogs.moderation.incidents.make_username", MagicMock(return_value="clyde the great")):
+ await self.cog_instance.archive(MockMessage(), MagicMock(incidents.Signal), MockMember())
+ # Assert that the "clyde" was never passed to `send`
self.assertNotIn("clyde", webhook.send.call_args.kwargs["username"])