-
Notifications
You must be signed in to change notification settings - Fork 686
/
stored_playlists_test.py
192 lines (151 loc) · 7.47 KB
/
stored_playlists_test.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
from __future__ import unicode_literals
import datetime
from mopidy.models import Track, Playlist
from tests.frontends.mpd import protocol
class PlaylistsHandlerTest(protocol.BaseTestCase):
def test_listplaylist(self):
self.backend.playlists.playlists = [
Playlist(name='name', uri='dummy:name',
tracks=[Track(uri='dummy:a')])]
self.sendRequest('listplaylist "name"')
self.assertInResponse('file: dummy:a')
self.assertInResponse('OK')
def test_listplaylist_without_quotes(self):
self.backend.playlists.playlists = [
Playlist(name='name', uri='dummy:name',
tracks=[Track(uri='dummy:a')])]
self.sendRequest('listplaylist name')
self.assertInResponse('file: dummy:a')
self.assertInResponse('OK')
def test_listplaylist_fails_if_no_playlist_is_found(self):
self.sendRequest('listplaylist "name"')
self.assertEqualResponse('ACK [50@0] {listplaylist} No such playlist')
def test_listplaylist_duplicate(self):
playlist1 = Playlist(name='a', uri='dummy:a1', tracks=[Track(uri='b')])
playlist2 = Playlist(name='a', uri='dummy:a2', tracks=[Track(uri='c')])
self.backend.playlists.playlists = [playlist1, playlist2]
self.sendRequest('listplaylist "a [2]"')
self.assertInResponse('file: c')
self.assertInResponse('OK')
def test_listplaylistinfo(self):
self.backend.playlists.playlists = [
Playlist(name='name', uri='dummy:name',
tracks=[Track(uri='dummy:a')])]
self.sendRequest('listplaylistinfo "name"')
self.assertInResponse('file: dummy:a')
self.assertInResponse('Track: 0')
self.assertNotInResponse('Pos: 0')
self.assertInResponse('OK')
def test_listplaylistinfo_without_quotes(self):
self.backend.playlists.playlists = [
Playlist(name='name', uri='dummy:name',
tracks=[Track(uri='dummy:a')])]
self.sendRequest('listplaylistinfo name')
self.assertInResponse('file: dummy:a')
self.assertInResponse('Track: 0')
self.assertNotInResponse('Pos: 0')
self.assertInResponse('OK')
def test_listplaylistinfo_fails_if_no_playlist_is_found(self):
self.sendRequest('listplaylistinfo "name"')
self.assertEqualResponse(
'ACK [50@0] {listplaylistinfo} No such playlist')
def test_listplaylistinfo_duplicate(self):
playlist1 = Playlist(name='a', uri='dummy:a1', tracks=[Track(uri='b')])
playlist2 = Playlist(name='a', uri='dummy:a2', tracks=[Track(uri='c')])
self.backend.playlists.playlists = [playlist1, playlist2]
self.sendRequest('listplaylistinfo "a [2]"')
self.assertInResponse('file: c')
self.assertInResponse('Track: 0')
self.assertNotInResponse('Pos: 0')
self.assertInResponse('OK')
def test_listplaylists(self):
last_modified = datetime.datetime(2001, 3, 17, 13, 41, 17, 12345)
self.backend.playlists.playlists = [
Playlist(name='a', uri='dummy:a', last_modified=last_modified)]
self.sendRequest('listplaylists')
self.assertInResponse('playlist: a')
# Date without microseconds and with time zone information
self.assertInResponse('Last-Modified: 2001-03-17T13:41:17Z')
self.assertInResponse('OK')
def test_listplaylists_duplicate(self):
playlist1 = Playlist(name='a', uri='dummy:a1')
playlist2 = Playlist(name='a', uri='dummy:a2')
self.backend.playlists.playlists = [playlist1, playlist2]
self.sendRequest('listplaylists')
self.assertInResponse('playlist: a')
self.assertInResponse('playlist: a [2]')
self.assertInResponse('OK')
def test_listplaylists_ignores_playlists_without_name(self):
last_modified = datetime.datetime(2001, 3, 17, 13, 41, 17, 12345)
self.backend.playlists.playlists = [
Playlist(name='', uri='dummy:', last_modified=last_modified)]
self.sendRequest('listplaylists')
self.assertNotInResponse('playlist: ')
self.assertInResponse('OK')
def test_load_appends_to_tracklist(self):
self.core.tracklist.add([Track(uri='a'), Track(uri='b')])
self.assertEqual(len(self.core.tracklist.tracks.get()), 2)
self.backend.playlists.playlists = [
Playlist(name='A-list', uri='dummy:A-list', tracks=[
Track(uri='c'), Track(uri='d'), Track(uri='e')])]
self.sendRequest('load "A-list"')
tracks = self.core.tracklist.tracks.get()
self.assertEqual(5, len(tracks))
self.assertEqual('a', tracks[0].uri)
self.assertEqual('b', tracks[1].uri)
self.assertEqual('c', tracks[2].uri)
self.assertEqual('d', tracks[3].uri)
self.assertEqual('e', tracks[4].uri)
self.assertInResponse('OK')
def test_load_with_range_loads_part_of_playlist(self):
self.core.tracklist.add([Track(uri='a'), Track(uri='b')])
self.assertEqual(len(self.core.tracklist.tracks.get()), 2)
self.backend.playlists.playlists = [
Playlist(name='A-list', uri='dummy:A-list', tracks=[
Track(uri='c'), Track(uri='d'), Track(uri='e')])]
self.sendRequest('load "A-list" "1:2"')
tracks = self.core.tracklist.tracks.get()
self.assertEqual(3, len(tracks))
self.assertEqual('a', tracks[0].uri)
self.assertEqual('b', tracks[1].uri)
self.assertEqual('d', tracks[2].uri)
self.assertInResponse('OK')
def test_load_with_range_without_end_loads_rest_of_playlist(self):
self.core.tracklist.add([Track(uri='a'), Track(uri='b')])
self.assertEqual(len(self.core.tracklist.tracks.get()), 2)
self.backend.playlists.playlists = [
Playlist(name='A-list', uri='dummy:A-list', tracks=[
Track(uri='c'), Track(uri='d'), Track(uri='e')])]
self.sendRequest('load "A-list" "1:"')
tracks = self.core.tracklist.tracks.get()
self.assertEqual(4, len(tracks))
self.assertEqual('a', tracks[0].uri)
self.assertEqual('b', tracks[1].uri)
self.assertEqual('d', tracks[2].uri)
self.assertEqual('e', tracks[3].uri)
self.assertInResponse('OK')
def test_load_unknown_playlist_acks(self):
self.sendRequest('load "unknown playlist"')
self.assertEqual(0, len(self.core.tracklist.tracks.get()))
self.assertEqualResponse('ACK [50@0] {load} No such playlist')
def test_playlistadd(self):
self.sendRequest('playlistadd "name" "dummy:a"')
self.assertEqualResponse('ACK [0@0] {} Not implemented')
def test_playlistclear(self):
self.sendRequest('playlistclear "name"')
self.assertEqualResponse('ACK [0@0] {} Not implemented')
def test_playlistdelete(self):
self.sendRequest('playlistdelete "name" "5"')
self.assertEqualResponse('ACK [0@0] {} Not implemented')
def test_playlistmove(self):
self.sendRequest('playlistmove "name" "5" "10"')
self.assertEqualResponse('ACK [0@0] {} Not implemented')
def test_rename(self):
self.sendRequest('rename "old_name" "new_name"')
self.assertEqualResponse('ACK [0@0] {} Not implemented')
def test_rm(self):
self.sendRequest('rm "name"')
self.assertEqualResponse('ACK [0@0] {} Not implemented')
def test_save(self):
self.sendRequest('save "name"')
self.assertEqualResponse('ACK [0@0] {} Not implemented')