Add skip test
This commit is contained in:
parent
57fbd247da
commit
645e6556a4
|
@ -29,7 +29,9 @@ def mbot(bot):
|
|||
|
||||
@pytest.fixture
|
||||
def ctx(mocker: MockerFixture):
|
||||
yield mocker.patch('discord.ext.commands.Context', autospec=True)
|
||||
ctx_mock = mocker.patch('discord.ext.commands.Context', autospec=True)
|
||||
ctx_mock.voice_client.stop = lambda: ctx_mock.voice_client.play.call_args.kwargs["after"](None)
|
||||
return ctx_mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
@ -96,3 +96,51 @@ async def test_bot_playback(mbot, ctx):
|
|||
assert \
|
||||
ctx.voice_client.play.call_args.args == (time_of_dying_audio,), \
|
||||
"Did not queue next song"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bot_skip(mbot, ctx):
|
||||
with patch.object(mbot, '_ytdl') as ytdl:
|
||||
with patch('discord.FFmpegPCMAudio') as ffmpeg_pcm_audio:
|
||||
|
||||
ctx.voice_client.is_playing.return_value = False
|
||||
url = "https://www.youtube.com/watch?v=Wr9LZ1hAFpQ"
|
||||
title = "In Flames - Deliver Us (Official Video)"
|
||||
mock_ytdl_extract_info(ytdl, url, title)
|
||||
deliver_us_audio = mock_ffmpeg_pcm_audio(ffmpeg_pcm_audio)
|
||||
query = 'in flames deliver us'
|
||||
# pylint: disable=too-many-function-args
|
||||
await mbot.play(mbot, ctx, query=query)
|
||||
await asyncio.sleep(0)
|
||||
assert \
|
||||
ctx.voice_client.play.call_args.args == (deliver_us_audio,), \
|
||||
"Did not playback correct audio"
|
||||
|
||||
ctx.voice_client.is_playing.return_value = True
|
||||
url = "https://www.youtube.com/watch?v=pMDcYX2wRSg"
|
||||
title = "Three Days Grace - Time of Dying (lyrics)"
|
||||
mock_ytdl_extract_info(ytdl, url, title)
|
||||
time_of_dying_audio = mock_ffmpeg_pcm_audio(ffmpeg_pcm_audio)
|
||||
# pylint: disable=too-many-function-args
|
||||
query = "three days grace time of dying"
|
||||
await mbot.play(mbot, ctx, query=query)
|
||||
await asyncio.sleep(0)
|
||||
assert \
|
||||
not ctx.voice_client.play.call_args.args == (time_of_dying_audio,), \
|
||||
"Did immediately playback audio instead of being queued"
|
||||
|
||||
await mbot.skip(mbot, ctx)
|
||||
await asyncio.sleep(0)
|
||||
assert \
|
||||
ctx.voice_client.play.call_args.args == (time_of_dying_audio,), \
|
||||
"Did not skip song"
|
||||
|
||||
# TEST: Error if no song playing
|
||||
ctx.voice_client.is_playing.return_value = False
|
||||
with pytest.raises(commands.CommandError):
|
||||
await mbot.skip(mbot, ctx)
|
||||
|
||||
# TEST: Error if no voice client
|
||||
ctx.voice_client = None
|
||||
with pytest.raises(commands.CommandError):
|
||||
await mbot.skip(mbot, ctx)
|
||||
|
|
Loading…
Reference in New Issue