import pytest from unittest.mock import MagicMock, AsyncMock, patch, PropertyMock import sys sys.path.insert(0, '/home/salmon/Documents/botcode/senator-sperma/tests') from conftest import MockApplicationContext @pytest.fixture def music_cog(bot): from cogs.music.play_commands import PlayCommands cog = PlayCommands(bot) return cog @pytest.mark.slow @pytest.mark.asyncio async def test_music_join_stop(music_cog, bot): """Test music join and stop commands.""" from cogs.music.join import Join from cogs.music.stop import Stop join_cog = Join(bot) stop_cog = Stop(bot) ctx = MockApplicationContext(bot=bot) ctx.author.voice = MagicMock() ctx.author.voice.channel = MagicMock() ctx.guild = MagicMock() # Test join mock_vm = MagicMock() mock_vm.connect = AsyncMock() with patch('cogs.music.join.get_voice_manager', return_value=mock_vm): with patch.object(ctx, 'respond', new_callable=AsyncMock): with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): await join_cog.join.callback(join_cog, ctx) mock_vm.connect.assert_called_once_with(ctx.author.voice.channel) # Test stop mock_vm_stop = MagicMock() mock_vm_stop.disconnect = AsyncMock() with patch('cogs.music.stop.get_voice_manager', return_value=mock_vm_stop): with patch.object(ctx, 'respond', new_callable=AsyncMock): with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): await stop_cog.stop.callback(stop_cog, ctx) mock_vm_stop.disconnect.assert_called_once_with(ctx.guild)