diff --git a/src/pylast/__init__.py b/src/pylast/__init__.py index 1154204..50c1206 100644 --- a/src/pylast/__init__.py +++ b/src/pylast/__init__.py @@ -2358,7 +2358,11 @@ class User(_BaseObject, _Chartable): seq = [] for track in _collect_nodes( - limit + 1, self, self.ws_prefix + ".getRecentTracks", cacheable, params + limit + 1 if limit else None, + self, + self.ws_prefix + ".getRecentTracks", + cacheable, + params, ): if track.hasAttribute("nowplaying"): @@ -2374,8 +2378,10 @@ class User(_BaseObject, _Chartable): PlayedTrack(Track(artist, title, self.network), album, date, timestamp) ) - # Slice, in case we didn't remove a now playing track - return seq[:limit] + if limit: + # Slice, in case we didn't remove a now playing track + seq = seq[:limit] + return seq def get_country(self): """Returns the name of the country of the user.""" diff --git a/tests/test_user.py b/tests/test_user.py index f283014..4d8ac83 100755 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -2,6 +2,8 @@ """ Integration (not unit) tests for pylast.py """ +import calendar +import datetime as dt import os import unittest import warnings @@ -354,12 +356,8 @@ class TestPyLastUser(TestPyLastWithLastFm): def test_get_recent_tracks_from_to(self): # Arrange lastfm_user = self.network.get_user("RJ") - - from datetime import datetime - - start = datetime(2011, 7, 21, 15, 10) - end = datetime(2011, 7, 21, 15, 15) - import calendar + start = dt.datetime(2011, 7, 21, 15, 10) + end = dt.datetime(2011, 7, 21, 15, 15) utc_start = calendar.timegm(start.utctimetuple()) utc_end = calendar.timegm(end.utctimetuple()) @@ -372,6 +370,25 @@ class TestPyLastUser(TestPyLastWithLastFm): self.assertEqual(str(tracks[0].track.artist), "Johnny Cash") self.assertEqual(str(tracks[0].track.title), "Ring of Fire") + def test_get_recent_tracks_limit_none(self): + # Arrange + lastfm_user = self.network.get_user("bbc6music") + start = dt.datetime(2020, 2, 15, 15, 00) + end = dt.datetime(2020, 2, 15, 15, 40) + + utc_start = calendar.timegm(start.utctimetuple()) + utc_end = calendar.timegm(end.utctimetuple()) + + # Act + tracks = lastfm_user.get_recent_tracks( + time_from=utc_start, time_to=utc_end, limit=None + ) + + # Assert + self.assertEqual(len(tracks), 11) + self.assertEqual(str(tracks[0].track.artist), "Seun Kuti & Egypt 80") + self.assertEqual(str(tracks[0].track.title), "Struggles Sounds") + def test_get_playcount(self): # Arrange user = self.network.get_user("RJ") diff --git a/tox.ini b/tox.ini index 9107481..f6e43d7 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,5 @@ [tox] envlist = py38, py37, py36, py35, pypy3 -recreate = False [testenv] extras = tests