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
|
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()
voice_client = AsyncMock()
ctx.voice_client = voice_client
# Test join
ctx.author.voice.channel.connect = AsyncMock(return_value=voice_client)
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)
ctx.author.voice.channel.connect.assert_called_once()
# Test 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)
voice_client.disconnect.assert_called_once()
|