From 0ddbb4e28a64d410f312945b59f87d1764a95090 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 29 Oct 2012 20:25:58 +0100 Subject: [PATCH] Make core.stored_playlists.playlists read-only (#217) --- docs/changes.rst | 7 +++++++ mopidy/core/stored_playlists.py | 7 +------ tests/backends/base/stored_playlists.py | 8 +++++--- tests/frontends/mpd/protocol/stored_playlists_test.py | 8 ++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 0203a89f..7fa59a3c 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -56,6 +56,13 @@ backends: dummy/mocked lower layers easier than with the old variant, where dependencies where looked up in Pykka's actor registry. +- The stored playlists part of the core API have been revised a bit: + + - :attr:`mopidy.core.StoredPlaylistsController.playlists` no longer supports + assignment to it. The `playlists` property on the backend layer still does, + and all functionality is maintained by assigning to the playlists + collections at the backend level. + **Changes** - Made the :mod:`NAD mixer ` responsive to interrupts diff --git a/mopidy/core/stored_playlists.py b/mopidy/core/stored_playlists.py index 9de1545f..a3d52023 100644 --- a/mopidy/core/stored_playlists.py +++ b/mopidy/core/stored_playlists.py @@ -15,17 +15,12 @@ class StoredPlaylistsController(object): """ Currently stored playlists. - Read/write. List of :class:`mopidy.models.Playlist`. + Read-only. List of :class:`mopidy.models.Playlist`. """ futures = [b.stored_playlists.playlists for b in self.backends] results = pykka.get_all(futures) return list(itertools.chain(*results)) - @playlists.setter # noqa - def playlists(self, playlists): - # TODO Support multiple backends - self.backends[0].stored_playlists.playlists = playlists - def create(self, name): """ Create a new playlist. diff --git a/tests/backends/base/stored_playlists.py b/tests/backends/base/stored_playlists.py index 5d01996d..fca13b93 100644 --- a/tests/backends/base/stored_playlists.py +++ b/tests/backends/base/stored_playlists.py @@ -65,12 +65,13 @@ class StoredPlaylistsControllerTest(object): def test_get_by_name_returns_unique_match(self): playlist = Playlist(name='b') - self.stored.playlists = [Playlist(name='a'), playlist] + self.backend.stored_playlists.playlists = [ + Playlist(name='a'), playlist] self.assertEqual(playlist, self.stored.get(name='b')) def test_get_by_name_returns_first_of_multiple_matches(self): playlist = Playlist(name='b') - self.stored.playlists = [ + self.backend.stored_playlists.playlists = [ playlist, Playlist(name='a'), Playlist(name='b')] try: self.stored.get(name='b') @@ -79,7 +80,8 @@ class StoredPlaylistsControllerTest(object): self.assertEqual(u'"name=b" match multiple playlists', e[0]) def test_get_by_name_raises_keyerror_if_no_match(self): - self.stored.playlists = [Playlist(name='a'), Playlist(name='b')] + self.backend.stored_playlists.playlists = [ + Playlist(name='a'), Playlist(name='b')] try: self.stored.get(name='c') self.fail(u'Should raise LookupError if no match') diff --git a/tests/frontends/mpd/protocol/stored_playlists_test.py b/tests/frontends/mpd/protocol/stored_playlists_test.py index 8cfcb338..346cd37f 100644 --- a/tests/frontends/mpd/protocol/stored_playlists_test.py +++ b/tests/frontends/mpd/protocol/stored_playlists_test.py @@ -7,7 +7,7 @@ from tests.frontends.mpd import protocol class StoredPlaylistsHandlerTest(protocol.BaseTestCase): def test_listplaylist(self): - self.core.stored_playlists.playlists = [ + self.backend.stored_playlists.playlists = [ Playlist(name='name', tracks=[Track(uri='file:///dev/urandom')])] self.sendRequest(u'listplaylist "name"') @@ -19,7 +19,7 @@ class StoredPlaylistsHandlerTest(protocol.BaseTestCase): self.assertEqualResponse(u'ACK [50@0] {listplaylist} No such playlist') def test_listplaylistinfo(self): - self.core.stored_playlists.playlists = [ + self.backend.stored_playlists.playlists = [ Playlist(name='name', tracks=[Track(uri='file:///dev/urandom')])] self.sendRequest(u'listplaylistinfo "name"') @@ -35,7 +35,7 @@ class StoredPlaylistsHandlerTest(protocol.BaseTestCase): def test_listplaylists(self): last_modified = datetime.datetime(2001, 3, 17, 13, 41, 17, 12345) - self.core.stored_playlists.playlists = [ + self.backend.stored_playlists.playlists = [ Playlist(name='a', last_modified=last_modified)] self.sendRequest(u'listplaylists') @@ -47,7 +47,7 @@ class StoredPlaylistsHandlerTest(protocol.BaseTestCase): def test_load_known_playlist_appends_to_current_playlist(self): self.core.current_playlist.append([Track(uri='a'), Track(uri='b')]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 2) - self.core.stored_playlists.playlists = [ + self.backend.stored_playlists.playlists = [ Playlist(name='A-list', tracks=[ Track(uri='c'), Track(uri='d'), Track(uri='e')])]