Merge branch 'master' of git://github.com/jodal/mopidy
This commit is contained in:
commit
e7a87d0375
@ -50,6 +50,8 @@ We got an updated :doc:`release roadmap <development/roadmap>`!
|
|||||||
lists of :class:`mopidy.models.Track` instead of
|
lists of :class:`mopidy.models.Track` instead of
|
||||||
:class:`mopidy.models.Playlist`, as none of the other fields on the
|
:class:`mopidy.models.Playlist`, as none of the other fields on the
|
||||||
``Playlist`` model was in use.
|
``Playlist`` model was in use.
|
||||||
|
- :meth:`mopidy.backends.BaseCurrentPlaylistController.add()` now returns the
|
||||||
|
``cp_track`` added to the current playlist.
|
||||||
- :meth:`mopidy.backends.BaseCurrentPlaylistController.remove()` now takes
|
- :meth:`mopidy.backends.BaseCurrentPlaylistController.remove()` now takes
|
||||||
criterias, just like
|
criterias, just like
|
||||||
:meth:`mopidy.backends.BaseCurrentPlaylistController.get()`.
|
:meth:`mopidy.backends.BaseCurrentPlaylistController.get()`.
|
||||||
|
|||||||
@ -122,14 +122,18 @@ class BaseCurrentPlaylistController(object):
|
|||||||
:type track: :class:`mopidy.models.Track`
|
:type track: :class:`mopidy.models.Track`
|
||||||
:param at_position: position in current playlist to add track
|
:param at_position: position in current playlist to add track
|
||||||
:type at_position: int or :class:`None`
|
:type at_position: int or :class:`None`
|
||||||
|
:rtype: two-tuple of (CPID integer, :class:`mopidy.models.Track`) that
|
||||||
|
was added to the current playlist playlist
|
||||||
"""
|
"""
|
||||||
assert at_position <= len(self._cp_tracks), \
|
assert at_position <= len(self._cp_tracks), \
|
||||||
u'at_position can not be greater than playlist length'
|
u'at_position can not be greater than playlist length'
|
||||||
|
cp_track = (self.version, track)
|
||||||
if at_position is not None:
|
if at_position is not None:
|
||||||
self._cp_tracks.insert(at_position, (self.version, track))
|
self._cp_tracks.insert(at_position, cp_track)
|
||||||
else:
|
else:
|
||||||
self._cp_tracks.append((self.version, track))
|
self._cp_tracks.append(cp_track)
|
||||||
self.version += 1
|
self.version += 1
|
||||||
|
return cp_track
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
"""Clear the current playlist."""
|
"""Clear the current playlist."""
|
||||||
|
|||||||
@ -295,8 +295,8 @@ class MpdFrontend(object):
|
|||||||
raise MpdNoExistError(u'No such song', command=u'addid')
|
raise MpdNoExistError(u'No such song', command=u'addid')
|
||||||
if songpos and songpos > len(self.backend.current_playlist.tracks):
|
if songpos and songpos > len(self.backend.current_playlist.tracks):
|
||||||
raise MpdArgError(u'Bad song index', command=u'addid')
|
raise MpdArgError(u'Bad song index', command=u'addid')
|
||||||
self.backend.current_playlist.add(track, at_position=songpos)
|
cp_track = self.backend.current_playlist.add(track, at_position=songpos)
|
||||||
return ('Id', track.id)
|
return ('Id', cp_track[0])
|
||||||
|
|
||||||
@handle_pattern(r'^delete "(?P<start>\d+):(?P<end>\d+)*"$')
|
@handle_pattern(r'^delete "(?P<start>\d+):(?P<end>\d+)*"$')
|
||||||
def _current_playlist_delete_range(self, start, end=None):
|
def _current_playlist_delete_range(self, start, end=None):
|
||||||
|
|||||||
@ -43,24 +43,23 @@ class BaseCurrentPlaylistControllerTest(object):
|
|||||||
|
|
||||||
def test_add(self):
|
def test_add(self):
|
||||||
for track in self.tracks:
|
for track in self.tracks:
|
||||||
self.controller.add(track)
|
cp_track = self.controller.add(track)
|
||||||
self.assertEqual(track, self.controller.tracks[-1])
|
self.assertEqual(track, self.controller.tracks[-1])
|
||||||
|
self.assertEqual(cp_track, self.controller.cp_tracks[-1])
|
||||||
|
self.assertEqual(track, cp_track[1])
|
||||||
|
|
||||||
def test_add_at_position(self):
|
def test_add_at_position(self):
|
||||||
for track in self.tracks[:-1]:
|
for track in self.tracks[:-1]:
|
||||||
self.controller.add(track, 0)
|
cp_track = self.controller.add(track, 0)
|
||||||
self.assertEqual(track, self.controller.tracks[0])
|
self.assertEqual(track, self.controller.tracks[0])
|
||||||
|
self.assertEqual(cp_track, self.controller.cp_tracks[0])
|
||||||
|
self.assertEqual(track, cp_track[1])
|
||||||
|
|
||||||
@populate_playlist
|
@populate_playlist
|
||||||
def test_add_at_position_outside_of_playlist(self):
|
def test_add_at_position_outside_of_playlist(self):
|
||||||
test = lambda: self.controller.add(self.tracks[0], len(self.tracks)+2)
|
test = lambda: self.controller.add(self.tracks[0], len(self.tracks)+2)
|
||||||
self.assertRaises(AssertionError, test)
|
self.assertRaises(AssertionError, test)
|
||||||
|
|
||||||
@populate_playlist
|
|
||||||
def test_add_sets_id_property(self):
|
|
||||||
for track in self.controller.tracks:
|
|
||||||
self.assertNotEqual(None, track.id)
|
|
||||||
|
|
||||||
@populate_playlist
|
@populate_playlist
|
||||||
def test_get_by_cpid(self):
|
def test_get_by_cpid(self):
|
||||||
cp_track = self.controller.cp_tracks[1]
|
cp_track = self.controller.cp_tracks[1]
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
|
|||||||
u'ACK [50@0] {add} directory or file not found')
|
u'ACK [50@0] {add} directory or file not found')
|
||||||
|
|
||||||
def test_addid_without_songpos(self):
|
def test_addid_without_songpos(self):
|
||||||
needle = Track(uri='dummy://foo', id=137)
|
needle = Track(uri='dummy://foo')
|
||||||
self.b.library._library = [Track(), Track(), needle, Track()]
|
self.b.library._library = [Track(), Track(), needle, Track()]
|
||||||
self.b.current_playlist.load(
|
self.b.current_playlist.load(
|
||||||
[Track(), Track(), Track(), Track(), Track()])
|
[Track(), Track(), Track(), Track(), Track()])
|
||||||
@ -37,11 +37,12 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
|
|||||||
result = self.h.handle_request(u'addid "dummy://foo"')
|
result = self.h.handle_request(u'addid "dummy://foo"')
|
||||||
self.assertEqual(len(self.b.current_playlist.tracks), 6)
|
self.assertEqual(len(self.b.current_playlist.tracks), 6)
|
||||||
self.assertEqual(self.b.current_playlist.tracks[5], needle)
|
self.assertEqual(self.b.current_playlist.tracks[5], needle)
|
||||||
self.assert_(u'Id: 137' in result)
|
self.assert_(u'Id: %d' % self.b.current_playlist.cp_tracks[5][0]
|
||||||
|
in result)
|
||||||
self.assert_(u'OK' in result)
|
self.assert_(u'OK' in result)
|
||||||
|
|
||||||
def test_addid_with_songpos(self):
|
def test_addid_with_songpos(self):
|
||||||
needle = Track(uri='dummy://foo', id=137)
|
needle = Track(uri='dummy://foo')
|
||||||
self.b.library._library = [Track(), Track(), needle, Track()]
|
self.b.library._library = [Track(), Track(), needle, Track()]
|
||||||
self.b.current_playlist.load(
|
self.b.current_playlist.load(
|
||||||
[Track(), Track(), Track(), Track(), Track()])
|
[Track(), Track(), Track(), Track(), Track()])
|
||||||
@ -49,7 +50,8 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
|
|||||||
result = self.h.handle_request(u'addid "dummy://foo" "3"')
|
result = self.h.handle_request(u'addid "dummy://foo" "3"')
|
||||||
self.assertEqual(len(self.b.current_playlist.tracks), 6)
|
self.assertEqual(len(self.b.current_playlist.tracks), 6)
|
||||||
self.assertEqual(self.b.current_playlist.tracks[3], needle)
|
self.assertEqual(self.b.current_playlist.tracks[3], needle)
|
||||||
self.assert_(u'Id: 137' in result)
|
self.assert_(u'Id: %d' % self.b.current_playlist.cp_tracks[3][0]
|
||||||
|
in result)
|
||||||
self.assert_(u'OK' in result)
|
self.assert_(u'OK' in result)
|
||||||
|
|
||||||
def test_addid_with_songpos_out_of_bounds_should_ack(self):
|
def test_addid_with_songpos_out_of_bounds_should_ack(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user