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
47
48
49
50
51
52
53
|
import pytest
from unittest.mock import AsyncMock, patch, MagicMock
from tests.conftest import MockApplicationContext
@pytest.fixture
def join_cog(bot):
from cogs.music.join import Join
cog = Join(bot)
return cog
@pytest.fixture
def stop_cog(bot):
from cogs.music.stop import Stop
cog = Stop(bot)
return cog
@pytest.mark.asyncio
async def test_join_command_success(join_cog, mock_channel, mock_guild, bot, mock_user):
ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
ctx.user = mock_user
ctx.author = mock_user
mock_voice_channel = MagicMock()
mock_voice = MagicMock()
mock_voice_channel.connect = AsyncMock(return_value=mock_voice)
ctx.author.voice = MagicMock()
ctx.author.voice.channel = mock_voice_channel
with patch.object(mock_voice_channel, 'connect', new_callable=AsyncMock, return_value=mock_voice):
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)
@pytest.mark.asyncio
async def test_stop_command_success(stop_cog, mock_channel, mock_guild, bot, mock_user):
ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
ctx.user = mock_user
ctx.author = mock_user
mock_voice_client = MagicMock()
mock_voice_client.disconnect = AsyncMock()
ctx.voice_client = mock_voice_client
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_voice_client.disconnect.assert_called_once()
|