From 30d512fd0e565db1a98ad918063aa8f71058b744 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 20 May 2018 18:41:27 +0300 Subject: [PATCH 1/4] Fix pep8-naming --- pylast/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 5fef12f..1d0c6d9 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -833,7 +833,7 @@ class _Request(object): 'User-Agent': "pylast" + '/' + __version__ } - (HOST_NAME, HOST_SUBDIR) = self.network.ws_server + (host_name, host_subdir) = self.network.ws_server if self.network.is_proxy_enabled(): conn = HTTPSConnection( @@ -843,17 +843,17 @@ class _Request(object): try: conn.request( - method='POST', url="https://" + HOST_NAME + HOST_SUBDIR, + method='POST', url="https://" + host_name + host_subdir, body=data, headers=headers) except Exception as e: raise NetworkError(self.network, e) else: - conn = HTTPSConnection(context=SSL_CONTEXT, host=HOST_NAME) + conn = HTTPSConnection(context=SSL_CONTEXT, host=host_name) try: conn.request( - method='POST', url=HOST_SUBDIR, body=data, headers=headers) + method='POST', url=host_subdir, body=data, headers=headers) except Exception as e: raise NetworkError(self.network, e) From b3a4ac5388cdff263f590786a25279b8dc5dd813 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 27 May 2018 19:23:54 +0300 Subject: [PATCH 2/4] Fix: 'list' object has no attribute 'track' --- tests/test_track.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_track.py b/tests/test_track.py index b68c065..53f84dd 100755 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -40,8 +40,8 @@ class TestPyLastTrack(TestPyLastWithLastFm): # Assert loved = lastfm_user.get_loved_tracks(limit=1) if len(loved): # OK to be empty but if not: - self.assertNotEqual(str(loved.track.artist), "Test Artist") - self.assertNotEqual(str(loved.track.title), "test title") + self.assertNotEqual(str(loved[0].track.artist), "Test Artist") + self.assertNotEqual(str(loved[0].track.title), "test title") def test_user_play_count_in_track_info(self): # Arrange From 4aefda5d39596d86e535ecc3bf82d02bfebe28ea Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 27 May 2018 19:28:59 +0300 Subject: [PATCH 3/4] A user without a country can now have 'None' --- pylast/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 1d0c6d9..896f440 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -2300,7 +2300,7 @@ class User(_BaseObject, _Chartable): country = _extract(doc, "country") - if country is None: + if country is None or country == "None": return None else: return Country(country, self.network) From 000993c3289405c9d5a50c896c47795a52075608 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 27 May 2018 20:14:13 +0300 Subject: [PATCH 4/4] Fix test_cacheable_user[_artist_tracks] --- pylast/__init__.py | 7 ++----- tests/test_pylast.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 896f440..2c316df 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -889,6 +889,7 @@ class _Request(object): raise MalformedResponseError(self.network, e) e = doc.getElementsByTagName('lfm')[0] + # logger.debug(doc.toprettyxml()) if e.getAttribute('status') != "ok": e = doc.getElementsByTagName('error')[0] @@ -2496,17 +2497,13 @@ class User(_BaseObject, _Chartable): class AuthenticatedUser(User): def __init__(self, network): - User.__init__(self, "", network) + User.__init__(self, network.username, network) def _get_params(self): return {"user": self.get_name()} def get_name(self): """Returns the name of the authenticated user.""" - - doc = self._request("user.getInfo", True, {"user": ""}) # hack - - self.name = _extract(doc, "name") return self.name diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 2bee953..5321bab 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -39,7 +39,7 @@ class PyLastTestCase(unittest.TestCase): self.assertTrue(str.endswith(suffix, start, end)) -@flaky(max_runs=3, min_passes=1) +@flaky(max_runs=1, min_passes=1) class TestPyLastWithLastFm(PyLastTestCase): secrets = None