Fix 'add ' and 'addid '

This commit is contained in:
Stein Magnus Jodal 2010-08-24 23:11:22 +02:00
parent 19909d7aca
commit c89d58fccf
3 changed files with 19 additions and 2 deletions

View File

@ -25,6 +25,9 @@ No description yet.
too.
- Rename setting :attr:`mopidy.settings.DUMP_LOG_FILENAME` to
:attr:`mopidy.settings.DEBUG_LOG_FILENAME`.
- MPD frontend:
- ``add ""`` and ``addid ""`` now behaves as expected.
0.1.0 (2010-08-23)

View File

@ -12,13 +12,14 @@ def add(frontend, uri):
Adds the file ``URI`` to the playlist (directories add recursively).
``URI`` can also be a single file.
"""
if not uri:
return
for handler_prefix in frontend.backend.uri_handlers:
if uri.startswith(handler_prefix):
track = frontend.backend.library.lookup(uri)
if track is not None:
frontend.backend.current_playlist.add(track)
return
raise MpdNoExistError(
u'directory or file not found', command=u'add')
@ -37,6 +38,8 @@ def addid(frontend, uri, songpos=None):
Id: 999
OK
"""
if not uri:
raise MpdNoExistError(u'No such song', command=u'addid')
if songpos is not None:
songpos = int(songpos)
track = frontend.backend.library.lookup(uri)
@ -44,7 +47,8 @@ def addid(frontend, uri, songpos=None):
raise MpdNoExistError(u'No such song', command=u'addid')
if songpos and songpos > len(frontend.backend.current_playlist.tracks):
raise MpdArgError(u'Bad song index', command=u'addid')
cp_track = frontend.backend.current_playlist.add(track, at_position=songpos)
cp_track = frontend.backend.current_playlist.add(track,
at_position=songpos)
return ('Id', cp_track[0])
@handle_pattern(r'^delete "(?P<start>\d+):(?P<end>\d+)*"$')

View File

@ -33,6 +33,11 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
self.assertEqual(result[0],
u'ACK [50@0] {add} directory or file not found')
def test_add_with_empty_uri_should_add_all_known_tracks_and_ok(self):
result = self.h.handle_request(u'add ""')
# TODO check that we add all tracks (we currently don't)
self.assert_(u'OK' in result)
def test_addid_without_songpos(self):
needle = Track(uri='dummy://foo')
self.b.library._library = [Track(), Track(), needle, Track()]
@ -46,6 +51,11 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
in result)
self.assert_(u'OK' in result)
def test_addid_with_empty_uri_does_not_lookup_and_acks(self):
self.b.library.lookup = lambda uri: self.fail("Shouldn't run")
result = self.h.handle_request(u'addid ""')
self.assertEqual(result[0], u'ACK [50@0] {addid} No such song')
def test_addid_with_songpos(self):
needle = Track(uri='dummy://foo')
self.b.library._library = [Track(), Track(), needle, Track()]