-
Notifications
You must be signed in to change notification settings - Fork 0
/
pytest_beathoven.py
63 lines (56 loc) · 2.25 KB
/
pytest_beathoven.py
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
54
55
56
57
58
59
60
61
62
63
import unittest
from unittest.mock import AsyncMock, MagicMock
from beathoven import play_song
class TestPlaySong(unittest.TestCase):
def setUp(self):
self.ctx = AsyncMock()
self.voice_client = MagicMock()
self.voice_client.play = MagicMock()
async def test_play_song_youtube(self):
global should_stop
global current_playlist
global repeat
should_stop = False
current_playlist = {'currently_playing': 0, 'playlist_type': 'YOUTUBE', 'playlist': ['song1']}
repeat = False
await play_song(self.ctx, self.voice_client)
self.voice_client.play.assert_called_once()
async def test_play_song_radio(self):
global should_stop
global current_playlist
global repeat
should_stop = False
current_playlist = {'currently_playing': 0, 'playlist_type': 'RADIO', 'playlist': ['song1']}
repeat = False
await play_song(self.ctx, self.voice_client)
self.voice_client.play.assert_called_once()
async def test_play_song_local(self):
global should_stop
global current_playlist
global repeat
should_stop = False
current_playlist = {'currently_playing': 0, 'playlist_type': 'LOCAL', 'playlist': ['song1']}
repeat = False
await play_song(self.ctx, self.voice_client)
self.voice_client.play.assert_called_once()
async def test_play_song_should_stop(self):
global should_stop
global current_playlist
global repeat
should_stop = True
current_playlist = {'currently_playing': 0, 'playlist_type': 'YOUTUBE', 'playlist': ['song1']}
repeat = False
await play_song(self.ctx, self.voice_client)
self.voice_client.play.assert_not_called()
async def test_play_song_exception(self):
global should_stop
global current_playlist
global repeat
should_stop = False
current_playlist = {'currently_playing': 0, 'playlist_type': 'YOUTUBE', 'playlist': ['song1']}
repeat = False
self.voice_client.play.side_effect = Exception('Test exception')
with self.assertRaises(Exception):
await play_song(self.ctx, self.voice_client)
if __name__ == '__main__':
unittest.main()