From be3706755b8e5810a24aabcf521234792501adc8 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Mon, 1 Apr 2024 20:13:44 +0100 Subject: Test that infraction reason sent to database is not truncated --- .../exts/moderation/infraction/test_infractions.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/bot/exts/moderation/infraction/test_infractions.py b/tests/bot/exts/moderation/infraction/test_infractions.py index 26ba770dc..f257bec7d 100644 --- a/tests/bot/exts/moderation/infraction/test_infractions.py +++ b/tests/bot/exts/moderation/infraction/test_infractions.py @@ -37,7 +37,9 @@ class TruncationTests(unittest.IsolatedAsyncioTestCase): self.cog.mod_log.ignore = Mock() self.ctx.guild.ban = AsyncMock() - await self.cog.apply_ban(self.ctx, self.target, "foo bar" * 3000) + infraction_reason = "foo bar" * 3000 + + await self.cog.apply_ban(self.ctx, self.target, infraction_reason) self.cog.apply_infraction.assert_awaited_once_with( self.ctx, {"foo": "bar", "purge": ""}, self.target, ANY ) @@ -46,10 +48,14 @@ class TruncationTests(unittest.IsolatedAsyncioTestCase): await action() self.ctx.guild.ban.assert_awaited_once_with( self.target, - reason=textwrap.shorten("foo bar" * 3000, 512, placeholder="..."), + reason=textwrap.shorten(infraction_reason, 512, placeholder="..."), delete_message_days=0 ) + # Assert that the reason sent to the database isn't truncated. + post_infraction_mock.assert_awaited_once() + self.assertEqual(post_infraction_mock.call_args.args[3], infraction_reason) + @patch("bot.exts.moderation.infraction._utils.post_infraction") async def test_apply_kick_reason_truncation(self, post_infraction_mock): """Should truncate reason for `Member.kick`.""" @@ -59,14 +65,20 @@ class TruncationTests(unittest.IsolatedAsyncioTestCase): self.cog.mod_log.ignore = Mock() self.target.kick = AsyncMock() - await self.cog.apply_kick(self.ctx, self.target, "foo bar" * 3000) + infraction_reason = "foo bar" * 3000 + + await self.cog.apply_kick(self.ctx, self.target, infraction_reason) self.cog.apply_infraction.assert_awaited_once_with( self.ctx, {"foo": "bar"}, self.target, ANY ) action = self.cog.apply_infraction.call_args.args[-1] await action() - self.target.kick.assert_awaited_once_with(reason=textwrap.shorten("foo bar" * 3000, 512, placeholder="...")) + self.target.kick.assert_awaited_once_with(reason=textwrap.shorten(infraction_reason, 512, placeholder="...")) + + # Assert that the reason sent to the database isn't truncated. + post_infraction_mock.assert_awaited_once() + self.assertEqual(post_infraction_mock.call_args.args[3], infraction_reason) @patch("bot.exts.moderation.infraction.infractions.constants.Roles.voice_verified", new=123456) -- cgit v1.2.3