Implement geo.getMetroHypeArtistChart and refactor
This commit is contained in:
parent
c587600e16
commit
2938255e2f
28
pylast.py
28
pylast.py
|
@ -2158,14 +2158,8 @@ class Metro(_BaseObject):
|
|||
|
||||
return self.country
|
||||
|
||||
def get_artist_chart(self, limit=None, from_date=None, to_date=None, cacheable=True):
|
||||
"""Get a chart of artists for a metro.
|
||||
Parameters:
|
||||
from_date (Optional) : Beginning timestamp of the weekly range requested
|
||||
to_date (Optional) : Ending timestamp of the weekly range requested
|
||||
limit (Optional) : The number of results to fetch per page. Defaults to 50.
|
||||
"""
|
||||
|
||||
def _get_chart(self, method, limit=None, from_date=None, to_date=None, cacheable=True):
|
||||
"""Internal helper for getting geo charts."""
|
||||
params = self._get_params()
|
||||
if limit: params["limit"] = limit
|
||||
if from_date and to_date:
|
||||
|
@ -2182,6 +2176,24 @@ class Metro(_BaseObject):
|
|||
|
||||
return seq
|
||||
|
||||
def get_artist_chart(self, limit=None, from_date=None, to_date=None, cacheable=True):
|
||||
"""Get a chart of artists for a metro.
|
||||
Parameters:
|
||||
from_date (Optional) : Beginning timestamp of the weekly range requested
|
||||
to_date (Optional) : Ending timestamp of the weekly range requested
|
||||
limit (Optional) : The number of results to fetch per page. Defaults to 50.
|
||||
"""
|
||||
return self._get_chart("geo.getMetroArtistChart", limit, from_date, to_date, cacheable)
|
||||
|
||||
def get_hype_artist_chart(self, limit=None, from_date=None, to_date=None, cacheable=True):
|
||||
"""Get a chart of hyped (up and coming) artists for a metro.
|
||||
Parameters:
|
||||
from_date (Optional) : Beginning timestamp of the weekly range requested
|
||||
to_date (Optional) : Ending timestamp of the weekly range requested
|
||||
limit (Optional) : The number of results to fetch per page. Defaults to 50.
|
||||
"""
|
||||
return self._get_chart("geo.getMetroHypeArtistChart", limit, from_date, to_date, cacheable)
|
||||
|
||||
|
||||
# TODO?
|
||||
# geo.getMetroHypeArtistChart
|
||||
|
|
|
@ -916,20 +916,34 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertLess(start, end)
|
||||
|
||||
|
||||
def test_get_metro_artist_chart(self):
|
||||
def helper_get_metro_and_dates(self, function_name):
|
||||
# Arrange
|
||||
metro = self.network.get_metro("Salamanca", "Spain")
|
||||
dates = self.network.get_metro_weekly_chart_dates()
|
||||
(from_date, to_date) = dates[0]
|
||||
|
||||
# get metro.function_name()
|
||||
func = getattr(metro, function_name, None)
|
||||
|
||||
# Act
|
||||
chart = metro.get_artist_chart(from_date = from_date, to_date = to_date, limit = 1)
|
||||
chart = func(from_date = from_date, to_date = to_date, limit = 1)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(chart), 1)
|
||||
self.assertEqual(type(chart[0]), pylast.TopItem)
|
||||
self.assertEqual(type(chart[0].item), pylast.Artist)
|
||||
|
||||
|
||||
def test_get_metro_artist_chart(self):
|
||||
# Arrange/Act/Assert
|
||||
self.helper_get_metro_and_dates("get_artist_chart")
|
||||
|
||||
|
||||
def test_get_metro_hype_artist_chart(self):
|
||||
# Arrange/Act/Assert
|
||||
self.helper_get_metro_and_dates("get_hype_artist_chart")
|
||||
|
||||
|
||||
def test_geo_get_metros(self):
|
||||
# Arrange
|
||||
# Act
|
||||
|
|
Loading…
Reference in a new issue