From 22e03705c496ca5e7febe28d7cbc002c91ab2d0f Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 11 Jan 2018 10:37:01 +0200 Subject: [PATCH 1/2] Passing test for limit=1 or 50, failing test for 100 --- tests/test_pylast_artist.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/test_pylast_artist.py b/tests/test_pylast_artist.py index 66dbb49..658f1d3 100755 --- a/tests/test_pylast_artist.py +++ b/tests/test_pylast_artist.py @@ -86,6 +86,42 @@ class TestPyLastArtist(PyLastTestCase): # Assert self.helper_two_different_things_in_top_list(things, pylast.Album) + def test_artist_top_albums_limit_1(self): + # Arrange + limit = 1 + # Pick an artist with plenty of plays + artist = self.network.get_top_artists(limit=1)[0].item + + # Act + things = artist.get_top_albums(limit=limit) + + # Assert + self.assertEqual(len(things), 1) + + def test_artist_top_albums_limit_50(self): + # Arrange + limit = 50 + # Pick an artist with plenty of plays + artist = self.network.get_top_artists(limit=1)[0].item + + # Act + things = artist.get_top_albums(limit=limit) + + # Assert + self.assertEqual(len(things), 50) + + def test_artist_top_albums_limit_100(self): + # Arrange + limit = 100 + # Pick an artist with plenty of plays + artist = self.network.get_top_artists(limit=1)[0].item + + # Act + things = artist.get_top_albums(limit=limit) + + # Assert + self.assertEqual(len(things), 100) + def test_artist_listener_count(self): # Arrange artist = self.network.get_artist("Test Artist") From 309b156fca6811225a5ad7e027e69e5aa9e4df3d Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 11 Jan 2018 11:36:14 +0200 Subject: [PATCH 2/2] Use paging to get all 'limit' items for Artist.get_top_albums (and others using _get_things) --- pylast/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 4ba99a4..3252c96 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -1046,11 +1046,14 @@ class _BaseObject(object): self, method, thing, thing_type, params=None, cacheable=True): """Returns a list of the most played thing_types by this thing.""" - doc = self._request( - self.ws_prefix + "." + method, cacheable, params) - + limit = params.get("limit", 1) seq = [] - for node in doc.getElementsByTagName(thing): + for node in _collect_nodes( + limit, + self, + self.ws_prefix + "." + method, + cacheable, + params): title = _extract(node, "name") artist = _extract(node, "name", 1) playcount = _number(_extract(node, "playcount"))