diff options
| author | 2024-04-01 20:13:44 +0100 | |
|---|---|---|
| committer | 2024-04-01 20:13:44 +0100 | |
| commit | be3706755b8e5810a24aabcf521234792501adc8 (patch) | |
| tree | 8d2d875f2a65ba6af42a919a93230c56eb9e017a | |
| parent | Merge pull request #2995 from python-discord/wookie184-show-warnings-in-actio... (diff) | |
Test that infraction reason sent to database is not truncated
Diffstat (limited to '')
| -rw-r--r-- | tests/bot/exts/moderation/infraction/test_infractions.py | 20 | 
1 files changed, 16 insertions, 4 deletions
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)  |