Merge pull request #1165 from tkem/fix/1162-v1.0.x
Fix #1162: Ignore None results and exceptions from PlaylistsProvider.create().
This commit is contained in:
commit
bf13bb4dd6
@ -5,6 +5,15 @@ Changelog
|
|||||||
This changelog is used to track all major changes to Mopidy.
|
This changelog is used to track all major changes to Mopidy.
|
||||||
|
|
||||||
|
|
||||||
|
v1.0.5 (UNRELEASED)
|
||||||
|
===================
|
||||||
|
|
||||||
|
Bug fix release.
|
||||||
|
|
||||||
|
- Core: Add workaround for playlist providers that do not support
|
||||||
|
creating playlists. (Fixes: :issue:`1162`, PR :issue:`1165`)
|
||||||
|
|
||||||
|
|
||||||
v1.0.4 (2015-04-30)
|
v1.0.4 (2015-04-30)
|
||||||
===================
|
===================
|
||||||
|
|
||||||
|
|||||||
@ -118,13 +118,19 @@ class PlaylistsController(object):
|
|||||||
:rtype: :class:`mopidy.models.Playlist`
|
:rtype: :class:`mopidy.models.Playlist`
|
||||||
"""
|
"""
|
||||||
if uri_scheme in self.backends.with_playlists:
|
if uri_scheme in self.backends.with_playlists:
|
||||||
backend = self.backends.with_playlists[uri_scheme]
|
backends = [self.backends.with_playlists[uri_scheme]]
|
||||||
else:
|
else:
|
||||||
# TODO: this fallback looks suspicious
|
backends = self.backends.with_playlists.values()
|
||||||
backend = list(self.backends.with_playlists.values())[0]
|
for backend in backends:
|
||||||
playlist = backend.playlists.create(name).get()
|
try:
|
||||||
listener.CoreListener.send('playlist_changed', playlist=playlist)
|
playlist = backend.playlists.create(name).get()
|
||||||
return playlist
|
except Exception:
|
||||||
|
playlist = None
|
||||||
|
# Workaround for playlist providers that return None from create()
|
||||||
|
if not playlist:
|
||||||
|
continue
|
||||||
|
listener.CoreListener.send('playlist_changed', playlist=playlist)
|
||||||
|
return playlist
|
||||||
|
|
||||||
def delete(self, uri):
|
def delete(self, uri):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -118,6 +118,32 @@ class PlaylistsTest(unittest.TestCase):
|
|||||||
self.sp1.create.assert_called_once_with('foo')
|
self.sp1.create.assert_called_once_with('foo')
|
||||||
self.assertFalse(self.sp2.create.called)
|
self.assertFalse(self.sp2.create.called)
|
||||||
|
|
||||||
|
def test_create_without_uri_scheme_ignores_none_result(self):
|
||||||
|
playlist = Playlist()
|
||||||
|
self.sp1.create().get.return_value = None
|
||||||
|
self.sp1.reset_mock()
|
||||||
|
self.sp2.create().get.return_value = playlist
|
||||||
|
self.sp2.reset_mock()
|
||||||
|
|
||||||
|
result = self.core.playlists.create('foo')
|
||||||
|
|
||||||
|
self.assertEqual(playlist, result)
|
||||||
|
self.sp1.create.assert_called_once_with('foo')
|
||||||
|
self.sp2.create.assert_called_once_with('foo')
|
||||||
|
|
||||||
|
def test_create_without_uri_scheme_ignores_exception(self):
|
||||||
|
playlist = Playlist()
|
||||||
|
self.sp1.create().get.side_effect = Exception
|
||||||
|
self.sp1.reset_mock()
|
||||||
|
self.sp2.create().get.return_value = playlist
|
||||||
|
self.sp2.reset_mock()
|
||||||
|
|
||||||
|
result = self.core.playlists.create('foo')
|
||||||
|
|
||||||
|
self.assertEqual(playlist, result)
|
||||||
|
self.sp1.create.assert_called_once_with('foo')
|
||||||
|
self.sp2.create.assert_called_once_with('foo')
|
||||||
|
|
||||||
def test_create_with_uri_scheme_selects_the_matching_backend(self):
|
def test_create_with_uri_scheme_selects_the_matching_backend(self):
|
||||||
playlist = Playlist()
|
playlist = Playlist()
|
||||||
self.sp2.create().get.return_value = playlist
|
self.sp2.create().get.return_value = playlist
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user