From 44318fccc492e590b425aed05ba3eafe5e06398e Mon Sep 17 00:00:00 2001 From: hugovk Date: Sun, 2 Mar 2014 10:00:26 +0200 Subject: [PATCH] Album.get_top_tracks now returns TopItems. Closes #86. --- pylast.py | 15 --------------- test_pylast.py | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/pylast.py b/pylast.py index 2e12146..76d26fa 100644 --- a/pylast.py +++ b/pylast.py @@ -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.""" diff --git a/test_pylast.py b/test_pylast.py index 602ac87..1231567 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -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()