diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/cogs/test_music_audio.py | 20 | ||||
| -rw-r--r-- | tests/cogs/test_music_integration.py | 26 | ||||
| -rw-r--r-- | tests/cogs/test_music_join.py | 25 | ||||
| -rw-r--r-- | tests/cogs/test_voice.py | 4 |
4 files changed, 40 insertions, 35 deletions
diff --git a/tests/cogs/test_music_audio.py b/tests/cogs/test_music_audio.py index 705f1b3..98c6f6b 100644 --- a/tests/cogs/test_music_audio.py +++ b/tests/cogs/test_music_audio.py | |||
| @@ -6,7 +6,7 @@ from conftest import MockApplicationContext | |||
| 6 | 6 | ||
| 7 | @pytest.mark.asyncio | 7 | @pytest.mark.asyncio |
| 8 | async def test_validate_voice_channel_not_in_voice(): | 8 | async def test_validate_voice_channel_not_in_voice(): |
| 9 | from cogs.music.audio_playback import AudioPlaybackManager | 9 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 10 | 10 | ||
| 11 | mock_ctx = MagicMock() | 11 | mock_ctx = MagicMock() |
| 12 | mock_ctx.author.voice = None | 12 | mock_ctx.author.voice = None |
| @@ -20,7 +20,7 @@ async def test_validate_voice_channel_not_in_voice(): | |||
| 20 | 20 | ||
| 21 | @pytest.mark.asyncio | 21 | @pytest.mark.asyncio |
| 22 | async def test_validate_voice_channel_in_voice(): | 22 | async def test_validate_voice_channel_in_voice(): |
| 23 | from cogs.music.audio_playback import AudioPlaybackManager | 23 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 24 | 24 | ||
| 25 | mock_channel = MagicMock() | 25 | mock_channel = MagicMock() |
| 26 | mock_ctx = MagicMock() | 26 | mock_ctx = MagicMock() |
| @@ -35,7 +35,7 @@ async def test_validate_voice_channel_in_voice(): | |||
| 35 | 35 | ||
| 36 | @pytest.mark.asyncio | 36 | @pytest.mark.asyncio |
| 37 | async def test_prepare_file_source_file_not_found(): | 37 | async def test_prepare_file_source_file_not_found(): |
| 38 | from cogs.music.audio_playback import AudioPlaybackManager | 38 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 39 | 39 | ||
| 40 | display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/nonexistent/file.mp3") | 40 | display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/nonexistent/file.mp3") |
| 41 | 41 | ||
| @@ -45,7 +45,7 @@ async def test_prepare_file_source_file_not_found(): | |||
| 45 | 45 | ||
| 46 | @pytest.mark.asyncio | 46 | @pytest.mark.asyncio |
| 47 | async def test_prepare_file_source_absolute_path(): | 47 | async def test_prepare_file_source_absolute_path(): |
| 48 | from cogs.music.audio_playback import AudioPlaybackManager | 48 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 49 | 49 | ||
| 50 | with patch('os.path.exists', return_value=True): | 50 | with patch('os.path.exists', return_value=True): |
| 51 | with patch('os.path.isabs', return_value=True): | 51 | with patch('os.path.isabs', return_value=True): |
| @@ -57,9 +57,9 @@ async def test_prepare_file_source_absolute_path(): | |||
| 57 | 57 | ||
| 58 | @pytest.mark.asyncio | 58 | @pytest.mark.asyncio |
| 59 | async def test_prepare_source_url(): | 59 | async def test_prepare_source_url(): |
| 60 | from cogs.music.audio_playback import AudioPlaybackManager | 60 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 61 | 61 | ||
| 62 | source, _, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "https://example.com/stream") | 62 | source, _, is_url = await AudioPlaybackManager.prepare_source("https://example.com/stream") |
| 63 | 63 | ||
| 64 | assert is_url == True | 64 | assert is_url == True |
| 65 | assert source == "https://example.com/stream" | 65 | assert source == "https://example.com/stream" |
| @@ -67,10 +67,10 @@ async def test_prepare_source_url(): | |||
| 67 | 67 | ||
| 68 | @pytest.mark.asyncio | 68 | @pytest.mark.asyncio |
| 69 | async def test_prepare_source_local_file(): | 69 | async def test_prepare_source_local_file(): |
| 70 | from cogs.music.audio_playback import AudioPlaybackManager | 70 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 71 | 71 | ||
| 72 | with patch('os.path.exists', return_value=True): | 72 | with patch('os.path.exists', return_value=True): |
| 73 | source, display_name, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "/tmp/test.mp3") | 73 | source, display_name, is_url = await AudioPlaybackManager.prepare_source("/tmp/test.mp3") |
| 74 | 74 | ||
| 75 | assert is_url == False | 75 | assert is_url == False |
| 76 | assert display_name == "test" | 76 | assert display_name == "test" |
| @@ -78,7 +78,7 @@ async def test_prepare_source_local_file(): | |||
| 78 | 78 | ||
| 79 | @pytest.mark.asyncio | 79 | @pytest.mark.asyncio |
| 80 | async def test_cleanup_temp_file(): | 80 | async def test_cleanup_temp_file(): |
| 81 | from cogs.music.audio_playback import AudioPlaybackManager | 81 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 82 | 82 | ||
| 83 | with patch('os.path.exists', return_value=True): | 83 | with patch('os.path.exists', return_value=True): |
| 84 | with patch('os.remove'): | 84 | with patch('os.remove'): |
| @@ -87,7 +87,7 @@ async def test_cleanup_temp_file(): | |||
| 87 | 87 | ||
| 88 | @pytest.mark.asyncio | 88 | @pytest.mark.asyncio |
| 89 | async def test_cleanup_temp_file_not_exists(): | 89 | async def test_cleanup_temp_file_not_exists(): |
| 90 | from cogs.music.audio_playback import AudioPlaybackManager | 90 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 91 | 91 | ||
| 92 | with patch('os.path.exists', return_value=False): | 92 | with patch('os.path.exists', return_value=False): |
| 93 | await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3") | 93 | await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3") |
diff --git a/tests/cogs/test_music_integration.py b/tests/cogs/test_music_integration.py index 1c0260a..692e1c1 100644 --- a/tests/cogs/test_music_integration.py +++ b/tests/cogs/test_music_integration.py | |||
| @@ -27,18 +27,20 @@ async def test_music_join_stop(music_cog, bot): | |||
| 27 | ctx.author.voice.channel = MagicMock() | 27 | ctx.author.voice.channel = MagicMock() |
| 28 | ctx.guild = MagicMock() | 28 | ctx.guild = MagicMock() |
| 29 | 29 | ||
| 30 | voice_client = AsyncMock() | ||
| 31 | ctx.voice_client = voice_client | ||
| 32 | |||
| 33 | # Test join | 30 | # Test join |
| 34 | ctx.author.voice.channel.connect = AsyncMock(return_value=voice_client) | 31 | mock_vm = MagicMock() |
| 35 | with patch.object(ctx, 'respond', new_callable=AsyncMock): | 32 | mock_vm.connect = AsyncMock() |
| 36 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): | 33 | with patch('cogs.music.join.get_voice_manager', return_value=mock_vm): |
| 37 | await join_cog.join.callback(join_cog, ctx) | 34 | with patch.object(ctx, 'respond', new_callable=AsyncMock): |
| 38 | ctx.author.voice.channel.connect.assert_called_once() | 35 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): |
| 36 | await join_cog.join.callback(join_cog, ctx) | ||
| 37 | mock_vm.connect.assert_called_once_with(ctx.author.voice.channel) | ||
| 39 | 38 | ||
| 40 | # Test stop | 39 | # Test stop |
| 41 | with patch.object(ctx, 'respond', new_callable=AsyncMock): | 40 | mock_vm_stop = MagicMock() |
| 42 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): | 41 | mock_vm_stop.disconnect = AsyncMock() |
| 43 | await stop_cog.stop.callback(stop_cog, ctx) | 42 | with patch('cogs.music.stop.get_voice_manager', return_value=mock_vm_stop): |
| 44 | voice_client.disconnect.assert_called_once() | 43 | with patch.object(ctx, 'respond', new_callable=AsyncMock): |
| 44 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): | ||
| 45 | await stop_cog.stop.callback(stop_cog, ctx) | ||
| 46 | mock_vm_stop.disconnect.assert_called_once_with(ctx.guild) | ||
diff --git a/tests/cogs/test_music_join.py b/tests/cogs/test_music_join.py index 0176759..b40d93a 100644 --- a/tests/cogs/test_music_join.py +++ b/tests/cogs/test_music_join.py | |||
| @@ -24,16 +24,18 @@ async def test_join_command_success(join_cog, mock_channel, mock_guild, bot, moc | |||
| 24 | ctx.author = mock_user | 24 | ctx.author = mock_user |
| 25 | 25 | ||
| 26 | mock_voice_channel = MagicMock() | 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() | 27 | ctx.author.voice = MagicMock() |
| 31 | ctx.author.voice.channel = mock_voice_channel | 28 | ctx.author.voice.channel = mock_voice_channel |
| 32 | 29 | ||
| 33 | with patch.object(mock_voice_channel, 'connect', new_callable=AsyncMock, return_value=mock_voice): | 30 | with patch('cogs.music.join.get_voice_manager') as mock_get_vm: |
| 31 | mock_vm = MagicMock() | ||
| 32 | mock_vm.connect = AsyncMock() | ||
| 33 | mock_get_vm.return_value = mock_vm | ||
| 34 | |||
| 34 | with patch.object(ctx, 'respond', new_callable=AsyncMock): | 35 | with patch.object(ctx, 'respond', new_callable=AsyncMock): |
| 35 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): | 36 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): |
| 36 | await join_cog.join.callback(join_cog, ctx) | 37 | await join_cog.join.callback(join_cog, ctx) |
| 38 | mock_vm.connect.assert_called_once_with(mock_voice_channel) | ||
| 37 | 39 | ||
| 38 | 40 | ||
| 39 | @pytest.mark.asyncio | 41 | @pytest.mark.asyncio |
| @@ -42,12 +44,13 @@ async def test_stop_command_success(stop_cog, mock_channel, mock_guild, bot, moc | |||
| 42 | ctx.user = mock_user | 44 | ctx.user = mock_user |
| 43 | ctx.author = mock_user | 45 | ctx.author = mock_user |
| 44 | 46 | ||
| 45 | mock_voice_client = MagicMock() | 47 | with patch('cogs.music.stop.get_voice_manager') as mock_get_vm: |
| 46 | mock_voice_client.disconnect = AsyncMock() | 48 | mock_vm = MagicMock() |
| 47 | ctx.voice_client = mock_voice_client | 49 | mock_vm.disconnect = AsyncMock() |
| 50 | mock_get_vm.return_value = mock_vm | ||
| 48 | 51 | ||
| 49 | with patch.object(ctx, 'respond', new_callable=AsyncMock): | 52 | with patch.object(ctx, 'respond', new_callable=AsyncMock): |
| 50 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): | 53 | with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): |
| 51 | await stop_cog.stop.callback(stop_cog, ctx) | 54 | await stop_cog.stop.callback(stop_cog, ctx) |
| 52 | 55 | ||
| 53 | mock_voice_client.disconnect.assert_called_once() | 56 | mock_vm.disconnect.assert_called_once_with(mock_guild) |
diff --git a/tests/cogs/test_voice.py b/tests/cogs/test_voice.py index 104eea6..6eb226b 100644 --- a/tests/cogs/test_voice.py +++ b/tests/cogs/test_voice.py | |||
| @@ -53,7 +53,7 @@ async def test_voice_manager_get_voice_status_not_connected(): | |||
| 53 | mock_bot = MagicMock() | 53 | mock_bot = MagicMock() |
| 54 | mock_guild = MagicMock() | 54 | mock_guild = MagicMock() |
| 55 | 55 | ||
| 56 | with patch('cogs.voice.VoiceManager.get_voice_client', return_value=None): | 56 | with patch('cogs.voice.VoiceManager.get_client', return_value=None): |
| 57 | manager = VoiceManager(mock_bot) | 57 | manager = VoiceManager(mock_bot) |
| 58 | voice_client, is_connected, is_playing = await manager.get_voice_status(mock_guild) | 58 | voice_client, is_connected, is_playing = await manager.get_voice_status(mock_guild) |
| 59 | 59 | ||
| @@ -71,7 +71,7 @@ async def test_voice_manager_stop(): | |||
| 71 | mock_voice_client = MagicMock() | 71 | mock_voice_client = MagicMock() |
| 72 | mock_voice_client.disconnect = AsyncMock() | 72 | mock_voice_client.disconnect = AsyncMock() |
| 73 | 73 | ||
| 74 | with patch('cogs.voice.VoiceManager.get_voice_client', return_value=mock_voice_client): | 74 | with patch('cogs.voice.VoiceManager.get_client', return_value=mock_voice_client): |
| 75 | manager = VoiceManager(mock_bot) | 75 | manager = VoiceManager(mock_bot) |
| 76 | await manager.stop(mock_guild) | 76 | await manager.stop(mock_guild) |
| 77 | 77 | ||
