Merge pull request #243 from pylast/242-limit-100
Use paging to get all 'limit' items for Artist.get_top_albums
This commit is contained in:
commit
a1e10e75cd
|
@ -1046,11 +1046,14 @@ class _BaseObject(object):
|
||||||
self, method, thing, thing_type, params=None, cacheable=True):
|
self, method, thing, thing_type, params=None, cacheable=True):
|
||||||
"""Returns a list of the most played thing_types by this thing."""
|
"""Returns a list of the most played thing_types by this thing."""
|
||||||
|
|
||||||
doc = self._request(
|
limit = params.get("limit", 1)
|
||||||
self.ws_prefix + "." + method, cacheable, params)
|
|
||||||
|
|
||||||
seq = []
|
seq = []
|
||||||
for node in doc.getElementsByTagName(thing):
|
for node in _collect_nodes(
|
||||||
|
limit,
|
||||||
|
self,
|
||||||
|
self.ws_prefix + "." + method,
|
||||||
|
cacheable,
|
||||||
|
params):
|
||||||
title = _extract(node, "name")
|
title = _extract(node, "name")
|
||||||
artist = _extract(node, "name", 1)
|
artist = _extract(node, "name", 1)
|
||||||
playcount = _number(_extract(node, "playcount"))
|
playcount = _number(_extract(node, "playcount"))
|
||||||
|
|
|
@ -86,6 +86,42 @@ class TestPyLastArtist(PyLastTestCase):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_two_different_things_in_top_list(things, pylast.Album)
|
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):
|
def test_artist_listener_count(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = self.network.get_artist("Test Artist")
|
artist = self.network.get_artist("Test Artist")
|
||||||
|
|
Loading…
Reference in a new issue