From c0a25fbabe2cfc265613739eabe7e42427d2f8ec Mon Sep 17 00:00:00 2001 From: hugovk Date: Fri, 20 Oct 2017 00:29:57 +0300 Subject: [PATCH 1/5] Remove dead Last.fm artist band members --- pylast/__init__.py | 11 ----------- tests/test_pylast_artist.py | 21 --------------------- 2 files changed, 32 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 06fe302..8a57787 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -1738,17 +1738,6 @@ class Artist(_BaseObject, _Taggable): return self.network._get_url( domain_name, "artist") % {'artist': artist} - def get_band_members(self): - """Returns a list of band members or None if unknown.""" - - names = None - doc = self._request(self.ws_prefix + ".getInfo", True) - - for node in doc.getElementsByTagName("bandmembers"): - names = _extract_all(node, "name") - - return names - class Country(_BaseObject): """A country at Last.fm.""" diff --git a/tests/test_pylast_artist.py b/tests/test_pylast_artist.py index 75c951d..0d45f64 100755 --- a/tests/test_pylast_artist.py +++ b/tests/test_pylast_artist.py @@ -237,27 +237,6 @@ class TestPyLastArtist(PyLastTestCase): # Act / Assert self.assertTrue(artist1 != artist2) - def test_band_members(self): - # Arrange - artist = pylast.Artist("The Beatles", self.network) - - # Act - band_members = artist.get_band_members() - - # Assert - self.skip_if_lastfm_api_broken(band_members) - self.assertGreaterEqual(len(band_members), 4) - - def test_no_band_members(self): - # Arrange - artist = pylast.Artist("John Lennon", self.network) - - # Act - band_members = artist.get_band_members() - - # Assert - self.assertIsNone(band_members) - def test_artist_get_correction(self): # Arrange artist = pylast.Artist("guns and roses", self.network) From 00b6c0a61901411c09955e6d452aba2627b6b3a3 Mon Sep 17 00:00:00 2001 From: hugovk Date: Fri, 20 Oct 2017 00:32:40 +0300 Subject: [PATCH 2/5] Remove dead Last.fm tag.getSimilar --- pylast/__init__.py | 12 ------------ tests/test_pylast_tag.py | 16 ---------------- 2 files changed, 28 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 8a57787..f7d99dc 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -1904,18 +1904,6 @@ class Tag(_BaseObject, _Chartable): return self.name - def get_similar(self): - """Returns the tags similar to this one, ordered by similarity. """ - - doc = self._request(self.ws_prefix + '.getSimilar', True) - - seq = [] - names = _extract_all(doc, 'name') - for name in names: - seq.append(Tag(name, self.network)) - - return seq - def get_top_albums(self, limit=None, cacheable=True): """Returns a list of the top albums.""" params = self._get_params() diff --git a/tests/test_pylast_tag.py b/tests/test_pylast_tag.py index d1a5f72..8d5440e 100755 --- a/tests/test_pylast_tag.py +++ b/tests/test_pylast_tag.py @@ -58,22 +58,6 @@ class TestPyLastTag(PyLastTestCase): self.assertTrue(tag1 != tag2) self.assertEqual(url, "https://www.last.fm/tag/blues") - def test_tags_similar(self): - # Arrange - tag = self.network.get_tag("blues") - - # Act - similar = tag.get_similar() - - # Assert - self.skip_if_lastfm_api_broken(similar) - found = False - for tag in similar: - if tag.name == "delta blues": - found = True - break - self.assertTrue(found) - if __name__ == '__main__': unittest.main(failfast=True) From 666181df506dd4be1075ab1f21a5ffaada7ae1f4 Mon Sep 17 00:00:00 2001 From: hugovk Date: Fri, 20 Oct 2017 00:39:02 +0300 Subject: [PATCH 3/5] Last.fm API broken but allow either yyyy-mm-dd or Unix timestamp --- tests/test_pylast_user.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_pylast_user.py b/tests/test_pylast_user.py index b64e0ee..3cc9969 100755 --- a/tests/test_pylast_user.py +++ b/tests/test_pylast_user.py @@ -72,12 +72,13 @@ class TestPyLastUser(PyLastTestCase): registered = user.get_registered() # Assert - # Last.fm API broken? Should be yyyy-mm-dd not Unix timestamp if int(registered): - pytest.skip("Last.fm API is broken.") - - # Just check date because of timezones - self.assertIn(u"2002-11-20 ", registered) + # Last.fm API broken? Used to be yyyy-mm-dd not Unix timestamp + self.assertEqual(registered, "1037793040") + else: + # Old way + # Just check date because of timezones + self.assertIn(u"2002-11-20 ", registered) def test_get_user_unixtime_registration(self): # Arrange From b55b40c3fe720a30887542838261eb2c1e241b5b Mon Sep 17 00:00:00 2001 From: hugovk Date: Fri, 20 Oct 2017 00:45:17 +0300 Subject: [PATCH 4/5] Remove dead Last.fm album/track get ID --- pylast/__init__.py | 6 ------ tests/test_pylast_user.py | 13 ------------- 2 files changed, 19 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index f7d99dc..df23ad6 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -1429,12 +1429,6 @@ class _Opus(_BaseObject, _Taggable): return self.get_title(properly_capitalized) - def get_id(self): - """Returns the ID on the network.""" - - return _extract( - self._request(self.ws_prefix + ".getInfo", cacheable=True), "id") - def get_playcount(self): """Returns the number of plays on the network""" diff --git a/tests/test_pylast_user.py b/tests/test_pylast_user.py index 3cc9969..53bb1fc 100755 --- a/tests/test_pylast_user.py +++ b/tests/test_pylast_user.py @@ -5,8 +5,6 @@ Integration (not unit) tests for pylast.py import os import unittest -import pytest - import pylast from .test_pylast import PyLastTestCase @@ -393,17 +391,6 @@ class TestPyLastUser(PyLastTestCase): # Assert self.assertNotEqual(track1, track2) - def test_track_id(self): - # Arrange - track = pylast.Track("Test Artist", "test title", self.network) - - # Act - id = track.get_id() - - # Assert - self.skip_if_lastfm_api_broken(id) - self.assertEqual(id, "14053327") - def test_track_title_prop_caps(self): # Arrange track = pylast.Track("test artist", "test title", self.network) From b55949536650a66e996a99428fead672c6ac93e7 Mon Sep 17 00:00:00 2001 From: hugovk Date: Fri, 20 Oct 2017 00:51:34 +0300 Subject: [PATCH 5/5] Assume no illegal XML and no more skipping broken Last.fm --- pylast/__init__.py | 15 --------------- tests/test_pylast.py | 5 ----- tests/test_pylast_network.py | 14 -------------- tests/test_pylast_user.py | 1 - 4 files changed, 35 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index df23ad6..3d1a219 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -22,7 +22,6 @@ from xml.dom import minidom, Node import collections -import re import hashlib import shelve import six @@ -108,18 +107,6 @@ SCROBBLE_MODE_LOVED = "L" SCROBBLE_MODE_BANNED = "B" SCROBBLE_MODE_SKIPPED = "S" -# From http://boodebr.org/main/python/all-about-python-and-unicode#UNI_XML -RE_XML_ILLEGAL = (u'([\u0000-\u0008\u000b-\u000c\u000e-\u001f\ufffe-\uffff])' + - u'|' + - u'([%s-%s][^%s-%s])|([^%s-%s][%s-%s])|([%s-%s]$)|(^[%s-%s])' - % - (unichr(0xd800), unichr(0xdbff), unichr(0xdc00), - unichr(0xdfff), unichr(0xd800), unichr(0xdbff), - unichr(0xdc00), unichr(0xdfff), unichr(0xd800), - unichr(0xdbff), unichr(0xdc00), unichr(0xdfff))) - -XML_ILLEGAL = re.compile(RE_XML_ILLEGAL) - # Python >3.4 and >2.7.9 has sane defaults SSL_CONTEXT = ssl.create_default_context() @@ -862,8 +849,6 @@ class _Request(object): except Exception as e: raise MalformedResponseError(self.network, e) - response_text = XML_ILLEGAL.sub("?", response_text) - self._check_response_for_errors(response_text) conn.close() return response_text diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 9279112..9ebbcc1 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -52,11 +52,6 @@ class PyLastTestCase(unittest.TestCase): api_key=API_KEY, api_secret=API_SECRET, username=self.username, password_hash=password_hash) - def skip_if_lastfm_api_broken(self, value): - """Skip things not yet restored in Last.fm's broken API""" - if value is None or len(value) == 0: - pytest.skip("Last.fm API is broken.") - def helper_is_thing_hashable(self, thing): # Arrange things = set() diff --git a/tests/test_pylast_network.py b/tests/test_pylast_network.py index 7ea6432..733a80e 100755 --- a/tests/test_pylast_network.py +++ b/tests/test_pylast_network.py @@ -47,20 +47,6 @@ class TestPyLastNetwork(PyLastTestCase): self.assertEqual(str(current_track.title), "test title") self.assertEqual(str(current_track.artist), "Test Artist") - def test_invalid_xml(self): - # Arrange - # Currently causes PCDATA invalid Char value 25 - artist = "Blind Willie Johnson" - title = "It's nobody's fault but mine" - - # Act - search = self.network.search_for_track(artist, title) - total = search.get_total_result_count() - - # Assert - self.skip_if_lastfm_api_broken(total) - self.assertGreaterEqual(int(total), 0) - def test_enable_rate_limiting(self): # Arrange self.assertFalse(self.network.is_rate_limited()) diff --git a/tests/test_pylast_user.py b/tests/test_pylast_user.py index 53bb1fc..66beb40 100755 --- a/tests/test_pylast_user.py +++ b/tests/test_pylast_user.py @@ -218,7 +218,6 @@ class TestPyLastUser(PyLastTestCase): tags = user.get_top_tags(limit=1) # Assert - self.skip_if_lastfm_api_broken(tags) self.helper_only_one_thing_in_top_list(tags, pylast.Tag) def test_user_top_tracks(self):