Implement _current_playlist_add

This commit is contained in:
Stein Magnus Jodal 2010-02-28 16:57:16 +01:00
parent 3dedb8ced3
commit 71fc316709
4 changed files with 23 additions and 4 deletions

View File

@ -63,7 +63,12 @@ class BaseCurrentPlaylistController(object):
:param at_position: position in current playlist to add track
:type at_position: int or :class:`None`
"""
raise NotImplementedError
tracks = self.playlist.tracks
if at_position:
tracks.insert(at_position, track)
else:
tracks.append(track)
self.playlist = self.playlist.with_(tracks=tracks)
def clear(self):
"""Clear the current playlist."""

View File

@ -15,6 +15,13 @@ class DummyCurrentPlaylistController(BaseCurrentPlaylistController):
pass
class DummyLibraryController(BaseLibraryController):
_library = []
def lookup(self, uri):
matches = filter(lambda t: uri == t.uri, self._library)
if matches:
return matches[0]
def search(self, type, query):
return Playlist()

View File

@ -224,7 +224,9 @@ class MpdHandler(object):
Adds the file ``URI`` to the playlist (directories add recursively).
``URI`` can also be a single file.
"""
raise MpdNotImplemented # TODO
track = self.backend.library.lookup(uri)
if track is not None:
self.backend.current_playlist.add(track)
@handle_pattern(r'^addid "(?P<uri>[^"]*)"( (?P<songpos>\d+))*$')
def _current_playlist_addid(self, uri, songpos=None):

View File

@ -494,8 +494,13 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
self.h = handler.MpdHandler(backend=self.b)
def test_add(self):
result = self.h.handle_request(u'add "file:///dev/urandom"')
self.assert_(u'ACK Not implemented' in result)
needle = Track(uri='dummy://foo')
self.b.library._library = [Track(), Track(), needle, Track()]
self.assertEquals(self.b.current_playlist.playlist.length, 0)
result = self.h.handle_request(u'add "dummy://foo"')
self.assertEquals(self.b.current_playlist.playlist.length, 1)
self.assert_(needle in self.b.current_playlist.playlist.tracks)
self.assert_(u'OK' in result)
def test_addid_without_songpos(self):
result = self.h.handle_request(u'addid "file:///dev/urandom"')