From 9243e98b94fbf36aebf7e4fc035cf280c032c659 Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 7 Apr 2014 12:29:50 +0300 Subject: [PATCH] Test some tag functions --- pylast.py | 42 ++++++++++++++++++++++++++++-------------- test_pylast.py | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/pylast.py b/pylast.py index cacff7e..66622c6 100644 --- a/pylast.py +++ b/pylast.py @@ -359,7 +359,8 @@ class _Network(object): """Returns the most played artists as a sequence of TopItem objects.""" params = {} - if limit: params["limit"] = limit + if limit: + params["limit"] = limit doc = _Request(self, "chart.getTopArtists", params).execute(cacheable) @@ -369,7 +370,8 @@ class _Network(object): """Returns the most played tracks as a sequence of TopItem objects.""" params = {} - if limit: params["limit"] = limit + if limit: + params["limit"] = limit doc = _Request(self, "chart.getTopTracks", params).execute(cacheable) @@ -462,7 +464,8 @@ class _Network(object): """ params = {} - if country: params["country"] = country + if country: + params["country"] = country doc = _Request(self, "geo.getMetros", params).execute(cacheable) @@ -487,7 +490,8 @@ class _Network(object): """ params = {"country": country} - if limit: params["limit"] = limit + if limit: + params["limit"] = limit doc = _Request(self, "geo.getTopArtists", params).execute(cacheable) @@ -506,8 +510,10 @@ class _Network(object): """ params = {"country": country} - if location: params["location"] = location - if limit: params['limit'] = limit + if location: + params["location"] = location + if limit: + params["limit"] = limit doc = _Request(self, "geo.getTopTracks", params).execute(cacheable) @@ -1784,7 +1790,8 @@ class _Opus(_BaseObject, _Taggable): def get_userplaycount(self): """Returns the number of plays by a given username""" - if not self.username: return + if not self.username: + return params = self._get_params() params['username'] = self.username @@ -1938,7 +1945,8 @@ class Artist(_BaseObject, _Taggable): def get_userplaycount(self): """Returns the number of plays by a given username""" - if not self.username: return + if not self.username: + return params = self._get_params() params['username'] = self.username @@ -2380,7 +2388,8 @@ class Metro(_BaseObject): to_date=None, cacheable=True): """Internal helper for getting geo charts.""" params = self._get_params() - if limit: params["limit"] = limit + if limit: + params["limit"] = limit if from_date and to_date: params["from"] = from_date params["to"] = to_date @@ -2936,7 +2945,8 @@ class Track(_Opus): def get_userloved(self): """Whether the user loved this track""" - if not self.username: return + if not self.username: + return params = self._get_params() params['username'] = self.username @@ -3288,7 +3298,8 @@ class User(_BaseObject, _Chartable): if limit: params['limit'] = limit - doc = self._request(self.ws_prefix + '.getNeighbours', cacheable, params) + doc = self._request( + self.ws_prefix + '.getNeighbours', cacheable, params) seq = [] names = _extract_all(doc, 'name') @@ -3481,7 +3492,8 @@ class User(_BaseObject, _Chartable): params = self._get_params() params['period'] = period - if limit: params['limit'] = limit + if limit: + params['limit'] = limit doc = self._request( self.ws_prefix + '.getTopAlbums', cacheable, params) @@ -3500,7 +3512,8 @@ class User(_BaseObject, _Chartable): params = self._get_params() params['period'] = period - if limit: params["limit"] = limit + if limit: + params["limit"] = limit doc = self._request(self.ws_prefix + '.getTopArtists', True, params) @@ -3515,7 +3528,8 @@ class User(_BaseObject, _Chartable): """ params = self._get_params() - if limit: params["limit"] = limit + if limit: + params["limit"] = limit doc = self._request(self.ws_prefix + ".getTopTags", cacheable, params) diff --git a/test_pylast.py b/test_pylast.py index 9f0897d..ca53057 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -1700,6 +1700,33 @@ class TestPyLast(unittest.TestCase): self.assertIsInstance(tracks[0], pylast.Track) self.assertEqual(len(tracks), 4) + def test_tags(self): + # Arrange + tag1 = self.network.get_tag("blues") + tag2 = self.network.get_tag("rock") + + # Act + tag_repr = repr(tag1) + tag_str = str(tag1) + name = tag1.get_name(properly_capitalized=True) + similar = tag1.get_similar() + url = tag1.get_url() + + # Assert + self.assertEqual("blues", tag_str) + self.assertIn("pylast.Tag", tag_repr) + self.assertIn("blues", tag_repr) + self.assertEqual("blues", name) + self.assertTrue(tag1 == tag1) + self.assertTrue(tag1 != tag2) + self.assertEqual(url, "http://www.last.fm/tag/blues") + found = False + for tag in similar: + if tag.name == "delta blues": + found = True + break + self.assertTrue(found) + if __name__ == '__main__': parser = argparse.ArgumentParser(