From 819572550012fc08ae5e0fd9aba451d94ffd1398 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 23 Apr 2016 14:48:29 +0300 Subject: [PATCH 1/4] Skip tests if Last.fm API still broken --- tests/test_pylast.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 6f3038c..9ba77c1 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -68,6 +68,11 @@ class TestPyLast(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: + pytest.skip("Last.fm API is broken.") + @handle_lastfm_exceptions def test_scrobble(self): # Arrange @@ -530,6 +535,7 @@ class TestPyLast(unittest.TestCase): total = search.get_total_result_count() # Assert + self.skip_if_lastfm_api_broken(total) self.assertGreaterEqual(int(total), 0) @handle_lastfm_exceptions @@ -1846,6 +1852,7 @@ class TestPyLast(unittest.TestCase): id = track.get_id() # Assert + self.skip_if_lastfm_api_broken(id) self.assertEqual(id, "14053327") @handle_lastfm_exceptions @@ -1879,6 +1886,7 @@ class TestPyLast(unittest.TestCase): date = album.get_release_date() # Assert + self.skip_if_lastfm_api_broken(date) self.assertIn("2011", date) @handle_lastfm_exceptions @@ -2083,6 +2091,7 @@ class TestPyLast(unittest.TestCase): band_members = artist.get_band_members() # Assert + self.skip_if_lastfm_api_broken(band_members) self.assertGreaterEqual(len(band_members), 4) @handle_lastfm_exceptions From 4c8d2e2a9b00683d52b7d50258e2b433124fb766 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 23 Apr 2016 15:27:28 +0300 Subject: [PATCH 2/4] Split test into passing and failing tests --- tests/test_pylast.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 9ba77c1..620e6ba 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -210,6 +210,10 @@ class TestPyLast(unittest.TestCase): 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) @@ -1912,7 +1916,6 @@ class TestPyLast(unittest.TestCase): tag_repr = repr(tag1) tag_str = str(tag1) name = tag1.get_name(properly_capitalized=True) - similar = tag1.get_similar() url = tag1.get_url() # Assert @@ -1923,6 +1926,16 @@ class TestPyLast(unittest.TestCase): self.assertTrue(tag1 == tag1) self.assertTrue(tag1 != tag2) self.assertEqual(url, "http://www.last.fm/tag/blues") + + @handle_lastfm_exceptions + def test_tags_similar(self): + # Arrange + tag = self.network.get_tag("blues") + + # Act + similar = tag.get_similar() + + # Assert found = False for tag in similar: if tag.name == "delta blues": From ea3307494111c34afe1945c99ef4532802f50c2a Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 23 Apr 2016 15:28:07 +0300 Subject: [PATCH 3/4] Skip test if Last.fm API still broken --- tests/test_pylast.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 620e6ba..8e68127 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -1936,6 +1936,8 @@ class TestPyLast(unittest.TestCase): similar = tag.get_similar() # Assert + if len(similar) == 0: + pytest.skip("Last.fm API is broken.") found = False for tag in similar: if tag.name == "delta blues": From 4732bf3750b205194945855f65b13a8f079cc4c9 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 23 Apr 2016 15:46:49 +0300 Subject: [PATCH 4/4] Skip tests if Last.fm API still broken --- tests/test_pylast.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_pylast.py b/tests/test_pylast.py index 8e68127..58f16bd 100755 --- a/tests/test_pylast.py +++ b/tests/test_pylast.py @@ -70,7 +70,7 @@ class TestPyLast(unittest.TestCase): def skip_if_lastfm_api_broken(self, value): """Skip things not yet restored in Last.fm's broken API""" - if value is None: + if value is None or len(value) == 0: pytest.skip("Last.fm API is broken.") @handle_lastfm_exceptions @@ -926,7 +926,8 @@ class TestPyLast(unittest.TestCase): lastfm_user = self.network.get_authenticated_user() # Act/Assert - self.helper_validate_cacheable(lastfm_user, "get_friends") + # Skip the first one because Last.fm API is broken + # self.helper_validate_cacheable(lastfm_user, "get_friends") self.helper_validate_cacheable(lastfm_user, "get_loved_tracks") self.helper_validate_cacheable(lastfm_user, "get_neighbours") self.helper_validate_cacheable(lastfm_user, "get_past_events") @@ -1184,6 +1185,7 @@ class TestPyLast(unittest.TestCase): 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) @handle_lastfm_exceptions @@ -1936,8 +1938,7 @@ class TestPyLast(unittest.TestCase): similar = tag.get_similar() # Assert - if len(similar) == 0: - pytest.skip("Last.fm API is broken.") + self.skip_if_lastfm_api_broken(similar) found = False for tag in similar: if tag.name == "delta blues":