From 3178f5223c1992c98a15ef73daa4c6bf77179bdf Mon Sep 17 00:00:00 2001 From: Dimosthenis Schizas Date: Fri, 22 Nov 2024 11:18:39 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20(tests/src/cmds/core/test=5Fuser.py?= =?UTF-8?q?):=20Fix=20tests=20patch=20DB=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cmds/core/user.py | 2 +- tests/src/cmds/core/test_user.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cmds/core/user.py b/src/cmds/core/user.py index 2e3de5e..fb8f9ea 100644 --- a/src/cmds/core/user.py +++ b/src/cmds/core/user.py @@ -95,7 +95,7 @@ async def kick(self, ctx: ApplicationContext, user: Member, reason: str, evidenc ) await ctx.guild.kick(user=member, reason=reason) - infraction_reason = f"{ctx.user.name} was kicked on {datetime.now()} for {reason}" + infraction_reason = f"{ctx.user.name} was kicked on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} for {reason}" await add_infraction(ctx.guild, member, 0, infraction_reason, ctx.user) return await ctx.respond(f"{member.name} got the boot!") diff --git a/tests/src/cmds/core/test_user.py b/tests/src/cmds/core/test_user.py index 4b940cb..8541456 100644 --- a/tests/src/cmds/core/test_user.py +++ b/tests/src/cmds/core/test_user.py @@ -1,3 +1,4 @@ +from datetime import datetime from unittest.mock import AsyncMock, patch import pytest @@ -10,9 +11,10 @@ class TestUserCog: """Test the `User` cog.""" @pytest.mark.asyncio - async def test_kick_success(self, ctx, bot): + async def test_kick_success(self, ctx, guild, bot, session): ctx.user = helpers.MockMember(id=1, name="Test Moderator") user_to_kick = helpers.MockMember(id=2, name="User to Kick", bot=False) + ctx.guild = guild ctx.guild.kick = AsyncMock() bot.get_member_or_user = AsyncMock(return_value=user_to_kick) @@ -21,19 +23,23 @@ async def test_kick_success(self, ctx, bot): user_to_kick.name = "User to Kick" with ( + patch('src.cmds.core.user.add_infraction', new_callable=AsyncMock) as add_infraction_mock, patch('src.cmds.core.user.add_evidence_note', new_callable=AsyncMock) as add_evidence_mock, patch('src.cmds.core.user.member_is_staff', return_value=False) ): cog = user.UserCog(bot) await cog.kick.callback(cog, ctx, user_to_kick, "Violation of rules") - add_evidence_mock.assert_called_once_with(user_to_kick.id, "kick", "Violation of rules", None, ctx.user.id) + reason = "Violation of rules" + add_evidence_mock.assert_called_once_with(user_to_kick.id, "kick", reason, None, ctx.user.id) + add_infraction_mock.assert_called_once_with( + ctx.guild, user_to_kick, 0, f"{ctx.user.name} was kicked on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} for {reason}", ctx.user + ) # Assertions ctx.guild.kick.assert_called_once_with(user=user_to_kick, reason="Violation of rules") ctx.respond.assert_called_once_with("User to Kick got the boot!") - def test_setup(self, bot): """Test the setup method of the cog.""" # Invoke the command