Album.get_top_tracks now returns TopItems. Closes #86.

This commit is contained in:
hugovk 2014-03-02 10:00:26 +02:00
parent e388db1e2f
commit 44318fccc4
2 changed files with 16 additions and 18 deletions

View file

@ -1282,21 +1282,6 @@ class Album(_BaseObject, _Taggable):
return _number(_extract(self._request("album.getInfo", cacheable = True), "listeners"))
def get_top_tags(self, limit=None):
"""Returns a list of the most-applied tags to this album."""
doc = self._request("album.getInfo", True)
e = doc.getElementsByTagName("toptags")[0]
seq = []
for name in _extract_all(e, "name"):
seq.append(Tag(name, self.network))
if limit:
seq = seq[:limit]
return seq
def get_tracks(self):
"""Returns the list of Tracks on this album."""

View file

@ -57,6 +57,7 @@ class TestPyLast(unittest.TestCase):
artist = "Test Artist 2"
title = "Test Title 2"
timestamp = self.unix_timestamp()
print timestamp
library = pylast.Library(user = self.username, network = self.network)
self.network.scrobble(artist = artist, title = title, timestamp = timestamp)
lastfm_user = self.network.get_user(self.username)
@ -325,10 +326,21 @@ class TestPyLast(unittest.TestCase):
# Act
network = pylast.LibreFMNetwork(password_hash = password_hash, username = username)
tags = network.get_top_tags()
tags = network.get_top_tags(limit = 1)
# Assert
self.assertGreater(len(tags), 0)
self.assertTrue(type(tags[0]) == pylast.TopItem)
def test_album_tags_are_topitems(self):
# Arrange
albums = self.network.get_user('RJ').get_top_albums()
# Act
tags = albums[0].item.get_top_tags(limit = 1)
# Assert
print len(tags)
self.assertGreater(len(tags), 0)
self.assertTrue(type(tags[0]) == pylast.TopItem)
@ -336,7 +348,8 @@ class TestPyLast(unittest.TestCase):
if __name__ == '__main__':
# suite = unittest.TestSuite()
# suite.addTest(TestPyLast('test_libre_fm'))
# suite.addTest(TestPyLast('test_scrobble'))
# suite.addTest(TestPyLast('test_unscrobble'))
# unittest.TextTestRunner().run(suite)
unittest.main()