From b343381fea3eab26e334a1b3bba202d715f9ea2e Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 19 Apr 2026 15:44:33 +0200 Subject: test: improve test assertions and edge cases --- tests/cogs/test_trigger.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tests/cogs/test_trigger.py') diff --git a/tests/cogs/test_trigger.py b/tests/cogs/test_trigger.py index befc360..6aaaa11 100644 --- a/tests/cogs/test_trigger.py +++ b/tests/cogs/test_trigger.py @@ -28,17 +28,17 @@ def mock_db_connection(): @pytest.mark.asyncio async def test_trigger_create_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) - + mock_conn, mock_cursor = mock_db_connection mock_cursor.fetchone.return_value = None - + with patch('cogs.trigger.get_connection') as mock_get_conn: mock_conn = MagicMock() mock_cursor = MagicMock() mock_conn.cursor.return_value = mock_cursor mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) - + with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: await trigger_cog.create.callback(trigger_cog, ctx, name="test_trigger") mock_respond.assert_called_once_with("trigger added") @@ -47,7 +47,7 @@ async def test_trigger_create_command(trigger_cog, mock_channel, mock_guild, bot @pytest.mark.asyncio async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) - + with patch('cogs.trigger.get_connection') as mock_get_conn: mock_conn = MagicMock() mock_cursor = MagicMock() @@ -55,7 +55,7 @@ async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, m mock_conn.cursor.return_value = mock_cursor mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) - + with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: await trigger_cog.add.callback(trigger_cog, ctx, name="test_trigger", trigger="hello", response="Hi there!") mock_respond.assert_called_once_with("trigger updated") @@ -64,7 +64,7 @@ async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, m @pytest.mark.asyncio async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) - + with patch('cogs.trigger.get_connection') as mock_get_conn: mock_conn = MagicMock() mock_cursor = MagicMock() @@ -72,7 +72,7 @@ async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_gui mock_conn.cursor.return_value = mock_cursor mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) - + with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: await trigger_cog.add.callback(trigger_cog, ctx, name="nonexistent", trigger="hello", response="Hi") mock_respond.assert_called_once_with("Trigger not found.") @@ -81,7 +81,7 @@ async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_gui @pytest.mark.asyncio async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) - + with patch('cogs.trigger.get_connection') as mock_get_conn: mock_conn = MagicMock() mock_cursor = MagicMock() @@ -89,7 +89,7 @@ async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot mock_conn.cursor.return_value = mock_cursor mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) - + with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: await trigger_cog.delete.callback(trigger_cog, ctx, name="test_trigger") mock_respond.assert_called_once_with("trigger deleted") @@ -98,9 +98,9 @@ async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot @pytest.mark.asyncio async def test_trigger_help_command(trigger_cog, mock_channel, mock_guild, bot): ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) - + with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: await trigger_cog.help.callback(trigger_cog, ctx) mock_respond.assert_called_once() args = mock_respond.call_args - assert "Trigger create" in str(args) \ No newline at end of file + assert "Trigger create" in str(args) -- cgit v1.2.3