Test some tag functions
This commit is contained in:
parent
50f1a0ac8f
commit
9243e98b94
42
pylast.py
42
pylast.py
|
@ -359,7 +359,8 @@ class _Network(object):
|
||||||
"""Returns the most played artists as a sequence of TopItem objects."""
|
"""Returns the most played artists as a sequence of TopItem objects."""
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
if limit: params["limit"] = limit
|
if limit:
|
||||||
|
params["limit"] = limit
|
||||||
|
|
||||||
doc = _Request(self, "chart.getTopArtists", params).execute(cacheable)
|
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."""
|
"""Returns the most played tracks as a sequence of TopItem objects."""
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
if limit: params["limit"] = limit
|
if limit:
|
||||||
|
params["limit"] = limit
|
||||||
|
|
||||||
doc = _Request(self, "chart.getTopTracks", params).execute(cacheable)
|
doc = _Request(self, "chart.getTopTracks", params).execute(cacheable)
|
||||||
|
|
||||||
|
@ -462,7 +464,8 @@ class _Network(object):
|
||||||
"""
|
"""
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
if country: params["country"] = country
|
if country:
|
||||||
|
params["country"] = country
|
||||||
|
|
||||||
doc = _Request(self, "geo.getMetros", params).execute(cacheable)
|
doc = _Request(self, "geo.getMetros", params).execute(cacheable)
|
||||||
|
|
||||||
|
@ -487,7 +490,8 @@ class _Network(object):
|
||||||
"""
|
"""
|
||||||
params = {"country": country}
|
params = {"country": country}
|
||||||
|
|
||||||
if limit: params["limit"] = limit
|
if limit:
|
||||||
|
params["limit"] = limit
|
||||||
|
|
||||||
doc = _Request(self, "geo.getTopArtists", params).execute(cacheable)
|
doc = _Request(self, "geo.getTopArtists", params).execute(cacheable)
|
||||||
|
|
||||||
|
@ -506,8 +510,10 @@ class _Network(object):
|
||||||
"""
|
"""
|
||||||
params = {"country": country}
|
params = {"country": country}
|
||||||
|
|
||||||
if location: params["location"] = location
|
if location:
|
||||||
if limit: params['limit'] = limit
|
params["location"] = location
|
||||||
|
if limit:
|
||||||
|
params["limit"] = limit
|
||||||
|
|
||||||
doc = _Request(self, "geo.getTopTracks", params).execute(cacheable)
|
doc = _Request(self, "geo.getTopTracks", params).execute(cacheable)
|
||||||
|
|
||||||
|
@ -1784,7 +1790,8 @@ class _Opus(_BaseObject, _Taggable):
|
||||||
def get_userplaycount(self):
|
def get_userplaycount(self):
|
||||||
"""Returns the number of plays by a given username"""
|
"""Returns the number of plays by a given username"""
|
||||||
|
|
||||||
if not self.username: return
|
if not self.username:
|
||||||
|
return
|
||||||
|
|
||||||
params = self._get_params()
|
params = self._get_params()
|
||||||
params['username'] = self.username
|
params['username'] = self.username
|
||||||
|
@ -1938,7 +1945,8 @@ class Artist(_BaseObject, _Taggable):
|
||||||
def get_userplaycount(self):
|
def get_userplaycount(self):
|
||||||
"""Returns the number of plays by a given username"""
|
"""Returns the number of plays by a given username"""
|
||||||
|
|
||||||
if not self.username: return
|
if not self.username:
|
||||||
|
return
|
||||||
|
|
||||||
params = self._get_params()
|
params = self._get_params()
|
||||||
params['username'] = self.username
|
params['username'] = self.username
|
||||||
|
@ -2380,7 +2388,8 @@ class Metro(_BaseObject):
|
||||||
to_date=None, cacheable=True):
|
to_date=None, cacheable=True):
|
||||||
"""Internal helper for getting geo charts."""
|
"""Internal helper for getting geo charts."""
|
||||||
params = self._get_params()
|
params = self._get_params()
|
||||||
if limit: params["limit"] = limit
|
if limit:
|
||||||
|
params["limit"] = limit
|
||||||
if from_date and to_date:
|
if from_date and to_date:
|
||||||
params["from"] = from_date
|
params["from"] = from_date
|
||||||
params["to"] = to_date
|
params["to"] = to_date
|
||||||
|
@ -2936,7 +2945,8 @@ class Track(_Opus):
|
||||||
def get_userloved(self):
|
def get_userloved(self):
|
||||||
"""Whether the user loved this track"""
|
"""Whether the user loved this track"""
|
||||||
|
|
||||||
if not self.username: return
|
if not self.username:
|
||||||
|
return
|
||||||
|
|
||||||
params = self._get_params()
|
params = self._get_params()
|
||||||
params['username'] = self.username
|
params['username'] = self.username
|
||||||
|
@ -3288,7 +3298,8 @@ class User(_BaseObject, _Chartable):
|
||||||
if limit:
|
if limit:
|
||||||
params['limit'] = limit
|
params['limit'] = limit
|
||||||
|
|
||||||
doc = self._request(self.ws_prefix + '.getNeighbours', cacheable, params)
|
doc = self._request(
|
||||||
|
self.ws_prefix + '.getNeighbours', cacheable, params)
|
||||||
|
|
||||||
seq = []
|
seq = []
|
||||||
names = _extract_all(doc, 'name')
|
names = _extract_all(doc, 'name')
|
||||||
|
@ -3481,7 +3492,8 @@ class User(_BaseObject, _Chartable):
|
||||||
|
|
||||||
params = self._get_params()
|
params = self._get_params()
|
||||||
params['period'] = period
|
params['period'] = period
|
||||||
if limit: params['limit'] = limit
|
if limit:
|
||||||
|
params['limit'] = limit
|
||||||
|
|
||||||
doc = self._request(
|
doc = self._request(
|
||||||
self.ws_prefix + '.getTopAlbums', cacheable, params)
|
self.ws_prefix + '.getTopAlbums', cacheable, params)
|
||||||
|
@ -3500,7 +3512,8 @@ class User(_BaseObject, _Chartable):
|
||||||
|
|
||||||
params = self._get_params()
|
params = self._get_params()
|
||||||
params['period'] = period
|
params['period'] = period
|
||||||
if limit: params["limit"] = limit
|
if limit:
|
||||||
|
params["limit"] = limit
|
||||||
|
|
||||||
doc = self._request(self.ws_prefix + '.getTopArtists', True, params)
|
doc = self._request(self.ws_prefix + '.getTopArtists', True, params)
|
||||||
|
|
||||||
|
@ -3515,7 +3528,8 @@ class User(_BaseObject, _Chartable):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
params = self._get_params()
|
params = self._get_params()
|
||||||
if limit: params["limit"] = limit
|
if limit:
|
||||||
|
params["limit"] = limit
|
||||||
|
|
||||||
doc = self._request(self.ws_prefix + ".getTopTags", cacheable, params)
|
doc = self._request(self.ws_prefix + ".getTopTags", cacheable, params)
|
||||||
|
|
||||||
|
|
|
@ -1700,6 +1700,33 @@ class TestPyLast(unittest.TestCase):
|
||||||
self.assertIsInstance(tracks[0], pylast.Track)
|
self.assertIsInstance(tracks[0], pylast.Track)
|
||||||
self.assertEqual(len(tracks), 4)
|
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__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
|
Loading…
Reference in a new issue