diff options
| author | salmonik <salmonik@noreply.codeberg.org> | 2026-04-19 18:10:09 +0200 |
|---|---|---|
| committer | salmonik <salmonik@noreply.codeberg.org> | 2026-04-19 18:10:09 +0200 |
| commit | f8e1cf36e1efa0602bf2e450835f2a67654762a6 (patch) | |
| tree | fe6b12226d7eebe2a0dc6525de3414d0c3718cc8 /tests/cogs/test_music_join.py | |
| parent | add support for x^2+y^2=0,4 and alike (diff) | |
| parent | fix: proper aiohttp async context manager mocking in test (diff) | |
| download | senator-sperma-f8e1cf36e1efa0602bf2e450835f2a67654762a6.tar.gz senator-sperma-f8e1cf36e1efa0602bf2e450835f2a67654762a6.zip | |
Merge pull request 'massive changes' (#3) from dev into main
Reviewed-on: https://codeberg.org/salmonik/senator-sperma/pulls/3
stable enough
Diffstat (limited to '')
| -rw-r--r-- | tests/cogs/test_music_join.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/cogs/test_music_join.py b/tests/cogs/test_music_join.py new file mode 100644 index 0000000..3c7ca6e --- /dev/null +++ b/tests/cogs/test_music_join.py | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | import pytest | ||
| 2 | from unittest.mock import AsyncMock, patch, MagicMock | ||
| 3 | from tests.conftest import MockApplicationContext | ||
| 4 | |||
| 5 | |||
| 6 | @pytest.fixture | ||
| 7 | def join_cog(bot): | ||
| 8 | from cogs.music.join import Join | ||
| 9 | cog = Join(bot) | ||
| 10 | return cog | ||
| 11 | |||
| 12 | |||
| 13 | @pytest.fixture | ||
| 14 | def stop_cog(bot): | ||
| 15 | from cogs.music.stop import Stop | ||
| 16 | cog = Stop(bot) | ||
| 17 | return cog | ||
| 18 | |||
| 19 | |||
| 20 | @pytest.mark.asyncio | ||
| 21 | async def test_join_command_success(join_cog, mock_channel, mock_guild, bot, mock_user): | ||
| 22 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 23 | ctx.user = mock_user | ||
| 24 | ctx.author = mock_user | ||
| 25 | |||
| 26 | mock_voice_channel = MagicMock() | ||
| 27 | mock_voice = MagicMock() | ||
| 28 | mock_voice_channel.connect = AsyncMock(return_value=mock_voice) | ||
| 29 | |||
| 30 | ctx.author.voice = MagicMock() | ||
| 31 | ctx.author.voice.channel = mock_voice_channel | ||
| 32 | |||
| 33 | with patch.object(mock_voice_channel, 'connect', new_callable=AsyncMock, return_value=mock_voice): | ||
| 34 | with patch.object(ctx, 'respond', new_callable=AsyncMock): | ||
| 35 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): | ||
| 36 | await join_cog.join.callback(join_cog, ctx) | ||
| 37 | |||
| 38 | |||
| 39 | @pytest.mark.asyncio | ||
| 40 | async def test_stop_command_success(stop_cog, mock_channel, mock_guild, bot, mock_user): | ||
| 41 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 42 | ctx.user = mock_user | ||
| 43 | ctx.author = mock_user | ||
| 44 | |||
| 45 | mock_voice_client = MagicMock() | ||
| 46 | mock_voice_client.disconnect = AsyncMock() | ||
| 47 | ctx.voice_client = mock_voice_client | ||
| 48 | |||
| 49 | with patch.object(ctx, 'respond', new_callable=AsyncMock): | ||
| 50 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): | ||
| 51 | await stop_cog.stop.callback(stop_cog, ctx) | ||
| 52 | |||
| 53 | mock_voice_client.disconnect.assert_called_once() | ||
