diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-19 15:44:33 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-19 15:44:33 +0200 |
| commit | b343381fea3eab26e334a1b3bba202d715f9ea2e (patch) | |
| tree | 792210018d1e11ac3b160edfe29cf878eb4e3f56 /tests/cogs/test_trigger.py | |
| parent | chore: add pycord dependency, update main (diff) | |
| download | senator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.tar.gz senator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.zip | |
test: improve test assertions and edge cases
Diffstat (limited to '')
| -rw-r--r-- | tests/cogs/test_trigger.py | 22 |
1 files changed, 11 insertions, 11 deletions
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(): | |||
| 28 | @pytest.mark.asyncio | 28 | @pytest.mark.asyncio |
| 29 | async def test_trigger_create_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): | 29 | async def test_trigger_create_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): |
| 30 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | 30 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) |
| 31 | 31 | ||
| 32 | mock_conn, mock_cursor = mock_db_connection | 32 | mock_conn, mock_cursor = mock_db_connection |
| 33 | mock_cursor.fetchone.return_value = None | 33 | mock_cursor.fetchone.return_value = None |
| 34 | 34 | ||
| 35 | with patch('cogs.trigger.get_connection') as mock_get_conn: | 35 | with patch('cogs.trigger.get_connection') as mock_get_conn: |
| 36 | mock_conn = MagicMock() | 36 | mock_conn = MagicMock() |
| 37 | mock_cursor = MagicMock() | 37 | mock_cursor = MagicMock() |
| 38 | mock_conn.cursor.return_value = mock_cursor | 38 | mock_conn.cursor.return_value = mock_cursor |
| 39 | mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) | 39 | mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) |
| 40 | mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) | 40 | mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) |
| 41 | 41 | ||
| 42 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | 42 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: |
| 43 | await trigger_cog.create.callback(trigger_cog, ctx, name="test_trigger") | 43 | await trigger_cog.create.callback(trigger_cog, ctx, name="test_trigger") |
| 44 | mock_respond.assert_called_once_with("trigger added") | 44 | 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 | |||
| 47 | @pytest.mark.asyncio | 47 | @pytest.mark.asyncio |
| 48 | async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): | 48 | async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): |
| 49 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | 49 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) |
| 50 | 50 | ||
| 51 | with patch('cogs.trigger.get_connection') as mock_get_conn: | 51 | with patch('cogs.trigger.get_connection') as mock_get_conn: |
| 52 | mock_conn = MagicMock() | 52 | mock_conn = MagicMock() |
| 53 | mock_cursor = MagicMock() | 53 | mock_cursor = MagicMock() |
| @@ -55,7 +55,7 @@ async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, m | |||
| 55 | mock_conn.cursor.return_value = mock_cursor | 55 | mock_conn.cursor.return_value = mock_cursor |
| 56 | mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) | 56 | mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) |
| 57 | mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) | 57 | mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) |
| 58 | 58 | ||
| 59 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | 59 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: |
| 60 | await trigger_cog.add.callback(trigger_cog, ctx, name="test_trigger", trigger="hello", response="Hi there!") | 60 | await trigger_cog.add.callback(trigger_cog, ctx, name="test_trigger", trigger="hello", response="Hi there!") |
| 61 | mock_respond.assert_called_once_with("trigger updated") | 61 | 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 | |||
| 64 | @pytest.mark.asyncio | 64 | @pytest.mark.asyncio |
| 65 | async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): | 65 | async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): |
| 66 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | 66 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) |
| 67 | 67 | ||
| 68 | with patch('cogs.trigger.get_connection') as mock_get_conn: | 68 | with patch('cogs.trigger.get_connection') as mock_get_conn: |
| 69 | mock_conn = MagicMock() | 69 | mock_conn = MagicMock() |
| 70 | mock_cursor = MagicMock() | 70 | mock_cursor = MagicMock() |
| @@ -72,7 +72,7 @@ async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_gui | |||
| 72 | mock_conn.cursor.return_value = mock_cursor | 72 | mock_conn.cursor.return_value = mock_cursor |
| 73 | mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) | 73 | mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) |
| 74 | mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) | 74 | mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) |
| 75 | 75 | ||
| 76 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | 76 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: |
| 77 | await trigger_cog.add.callback(trigger_cog, ctx, name="nonexistent", trigger="hello", response="Hi") | 77 | await trigger_cog.add.callback(trigger_cog, ctx, name="nonexistent", trigger="hello", response="Hi") |
| 78 | mock_respond.assert_called_once_with("Trigger not found.") | 78 | 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 | |||
| 81 | @pytest.mark.asyncio | 81 | @pytest.mark.asyncio |
| 82 | async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): | 82 | async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): |
| 83 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | 83 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) |
| 84 | 84 | ||
| 85 | with patch('cogs.trigger.get_connection') as mock_get_conn: | 85 | with patch('cogs.trigger.get_connection') as mock_get_conn: |
| 86 | mock_conn = MagicMock() | 86 | mock_conn = MagicMock() |
| 87 | mock_cursor = MagicMock() | 87 | mock_cursor = MagicMock() |
| @@ -89,7 +89,7 @@ async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot | |||
| 89 | mock_conn.cursor.return_value = mock_cursor | 89 | mock_conn.cursor.return_value = mock_cursor |
| 90 | mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) | 90 | mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) |
| 91 | mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) | 91 | mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) |
| 92 | 92 | ||
| 93 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | 93 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: |
| 94 | await trigger_cog.delete.callback(trigger_cog, ctx, name="test_trigger") | 94 | await trigger_cog.delete.callback(trigger_cog, ctx, name="test_trigger") |
| 95 | mock_respond.assert_called_once_with("trigger deleted") | 95 | 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 | |||
| 98 | @pytest.mark.asyncio | 98 | @pytest.mark.asyncio |
| 99 | async def test_trigger_help_command(trigger_cog, mock_channel, mock_guild, bot): | 99 | async def test_trigger_help_command(trigger_cog, mock_channel, mock_guild, bot): |
| 100 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | 100 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) |
| 101 | 101 | ||
| 102 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | 102 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: |
| 103 | await trigger_cog.help.callback(trigger_cog, ctx) | 103 | await trigger_cog.help.callback(trigger_cog, ctx) |
| 104 | mock_respond.assert_called_once() | 104 | mock_respond.assert_called_once() |
| 105 | args = mock_respond.call_args | 105 | args = mock_respond.call_args |
| 106 | assert "Trigger create" in str(args) \ No newline at end of file | 106 | assert "Trigger create" in str(args) |
