diff options
Diffstat (limited to 'tests/cogs/test_music_audio.py')
| -rw-r--r-- | tests/cogs/test_music_audio.py | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/tests/cogs/test_music_audio.py b/tests/cogs/test_music_audio.py index b53cf95..7ea902e 100644 --- a/tests/cogs/test_music_audio.py +++ b/tests/cogs/test_music_audio.py | |||
| @@ -7,13 +7,13 @@ from tests.conftest import MockApplicationContext | |||
| 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.music.audio_playback import AudioPlaybackManager |
| 10 | 10 | ||
| 11 | mock_ctx = MagicMock() | 11 | mock_ctx = MagicMock() |
| 12 | mock_ctx.author.voice = None | 12 | mock_ctx.author.voice = None |
| 13 | mock_ctx.respond = AsyncMock() | 13 | mock_ctx.respond = AsyncMock() |
| 14 | 14 | ||
| 15 | result = await AudioPlaybackManager.validate_voice_channel(mock_ctx) | 15 | result = await AudioPlaybackManager.validate_voice_channel(mock_ctx) |
| 16 | 16 | ||
| 17 | assert result is None | 17 | assert result is None |
| 18 | mock_ctx.respond.assert_called_once() | 18 | mock_ctx.respond.assert_called_once() |
| 19 | 19 | ||
| @@ -21,24 +21,24 @@ async def test_validate_voice_channel_not_in_voice(): | |||
| 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.music.audio_playback import AudioPlaybackManager |
| 24 | 24 | ||
| 25 | mock_channel = MagicMock() | 25 | mock_channel = MagicMock() |
| 26 | mock_ctx = MagicMock() | 26 | mock_ctx = MagicMock() |
| 27 | mock_ctx.author.voice = MagicMock() | 27 | mock_ctx.author.voice = MagicMock() |
| 28 | mock_ctx.author.voice.channel = mock_channel | 28 | mock_ctx.author.voice.channel = mock_channel |
| 29 | mock_ctx.respond = AsyncMock() | 29 | mock_ctx.respond = AsyncMock() |
| 30 | 30 | ||
| 31 | result = await AudioPlaybackManager.validate_voice_channel(mock_ctx) | 31 | result = await AudioPlaybackManager.validate_voice_channel(mock_ctx) |
| 32 | 32 | ||
| 33 | assert result == mock_channel | 33 | assert result == mock_channel |
| 34 | 34 | ||
| 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.music.audio_playback import 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 | ||
| 42 | assert display_name is None | 42 | assert display_name is None |
| 43 | assert absolute_path is None | 43 | assert absolute_path is None |
| 44 | 44 | ||
| @@ -46,11 +46,11 @@ async def test_prepare_file_source_file_not_found(): | |||
| 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.music.audio_playback import 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): |
| 52 | display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/tmp/test.mp3") | 52 | display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/tmp/test.mp3") |
| 53 | 53 | ||
| 54 | assert display_name == "test" | 54 | assert display_name == "test" |
| 55 | assert absolute_path == "/tmp/test.mp3" | 55 | assert absolute_path == "/tmp/test.mp3" |
| 56 | 56 | ||
| @@ -58,9 +58,9 @@ async def test_prepare_file_source_absolute_path(): | |||
| 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.music.audio_playback import AudioPlaybackManager |
| 61 | 61 | ||
| 62 | source, display_name, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "https://example.com/stream") | 62 | source, _, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "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" |
| 66 | 66 | ||
| @@ -68,10 +68,10 @@ async def test_prepare_source_url(): | |||
| 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.music.audio_playback import 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(MagicMock(), "/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" |
| 77 | 77 | ||
| @@ -79,7 +79,7 @@ async def test_prepare_source_local_file(): | |||
| 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.music.audio_playback import 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'): |
| 85 | await AudioPlaybackManager.cleanup_temp_file("/tmp/test.mp3") | 85 | await AudioPlaybackManager.cleanup_temp_file("/tmp/test.mp3") |
| @@ -88,6 +88,6 @@ async def test_cleanup_temp_file(): | |||
| 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.music.audio_playback import 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") \ No newline at end of file | 93 | await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3") |
