aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs/test_music_integration.py
blob: 692e1c1620d0cd9dfd1c41bfbb69f7fb42b2de5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)