Run pyflakes and pep8 and update
This commit is contained in:
parent
779af598db
commit
1d532c0363
268
test_pylast.py
268
test_pylast.py
|
@ -9,6 +9,7 @@ import unittest
|
|||
|
||||
import pylast
|
||||
|
||||
|
||||
def load_secrets():
|
||||
secrets_file = "test_pylast.yaml"
|
||||
if os.path.isfile(secrets_file):
|
||||
|
@ -41,9 +42,9 @@ class TestPyLast(unittest.TestCase):
|
|||
API_KEY = self.__class__.secrets["api_key"]
|
||||
API_SECRET = self.__class__.secrets["api_secret"]
|
||||
|
||||
self.network = pylast.LastFMNetwork(api_key = API_KEY, api_secret =
|
||||
API_SECRET, username = self.username, password_hash = password_hash)
|
||||
|
||||
self.network = pylast.LastFMNetwork(
|
||||
api_key=API_KEY, api_secret=API_SECRET,
|
||||
username=self.username, password_hash=password_hash)
|
||||
|
||||
def test_scrobble(self):
|
||||
# Arrange
|
||||
|
@ -53,35 +54,36 @@ class TestPyLast(unittest.TestCase):
|
|||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
self.network.scrobble(artist = artist, title = title, timestamp = timestamp)
|
||||
self.network.scrobble(artist=artist, title=title, timestamp=timestamp)
|
||||
|
||||
# Assert
|
||||
last_scrobble = lastfm_user.get_recent_tracks(limit = 2)[0] # 2 to ignore now-playing
|
||||
# limit=2 to ignore now-playing:
|
||||
last_scrobble = lastfm_user.get_recent_tracks(limit=2)[0]
|
||||
self.assertEqual(str(last_scrobble.track.artist), str(artist))
|
||||
self.assertEqual(str(last_scrobble.track.title), str(title))
|
||||
self.assertEqual(str(last_scrobble.timestamp), str(timestamp))
|
||||
|
||||
|
||||
def test_unscrobble(self):
|
||||
# Arrange
|
||||
artist = "Test Artist 2"
|
||||
title = "Test Title 2"
|
||||
timestamp = self.unix_timestamp()
|
||||
library = pylast.Library(user = self.username, network = self.network)
|
||||
self.network.scrobble(artist = artist, title = title, timestamp = timestamp)
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
self.network.scrobble(artist=artist, title=title, timestamp=timestamp)
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
library.remove_scrobble(artist = artist, title = title, timestamp = timestamp)
|
||||
library.remove_scrobble(
|
||||
artist=artist, title=title, timestamp=timestamp)
|
||||
|
||||
# Assert
|
||||
last_scrobble = lastfm_user.get_recent_tracks(limit = 2)[0] # 2 to ignore now-playing
|
||||
# limit=2 to ignore now-playing:
|
||||
last_scrobble = lastfm_user.get_recent_tracks(limit=2)[0]
|
||||
self.assertNotEqual(str(last_scrobble.timestamp), str(timestamp))
|
||||
|
||||
|
||||
def test_add_album(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user = self.username, network = self.network)
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
album = self.network.get_album("Test Artist", "Test Album")
|
||||
|
||||
# Act
|
||||
|
@ -95,12 +97,11 @@ class TestPyLast(unittest.TestCase):
|
|||
break
|
||||
self.assertTrue(value)
|
||||
|
||||
|
||||
def test_remove_album(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user = self.username, network = self.network)
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
# Pick an artist with plenty of albums
|
||||
artist = self.network.get_top_artists(limit = 1)[0].item
|
||||
artist = self.network.get_top_artists(limit=1)[0].item
|
||||
albums = artist.get_top_albums()
|
||||
# Pick a random one to avoid problems running concurrent tests
|
||||
album = choice(albums)[0]
|
||||
|
@ -117,11 +118,10 @@ class TestPyLast(unittest.TestCase):
|
|||
break
|
||||
self.assertFalse(value)
|
||||
|
||||
|
||||
def test_add_artist(self):
|
||||
# Arrange
|
||||
artist = "Test Artist 2"
|
||||
library = pylast.Library(user = self.username, network = self.network)
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
|
||||
# Act
|
||||
library.add_artist(artist)
|
||||
|
@ -134,14 +134,13 @@ class TestPyLast(unittest.TestCase):
|
|||
break
|
||||
self.assertTrue(value)
|
||||
|
||||
|
||||
def test_remove_artist(self):
|
||||
# Arrange
|
||||
# Get plenty of artists
|
||||
artists = self.network.get_top_artists()
|
||||
# Pick a random one to avoid problems running concurrent tests
|
||||
my_artist = choice(artists).item
|
||||
library = pylast.Library(user = self.username, network = self.network)
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
library.add_artist(my_artist)
|
||||
|
||||
# Act
|
||||
|
@ -155,7 +154,6 @@ class TestPyLast(unittest.TestCase):
|
|||
break
|
||||
self.assertFalse(value)
|
||||
|
||||
|
||||
def test_get_venue(self):
|
||||
# Arrange
|
||||
venue_name = "Last.fm Office"
|
||||
|
@ -168,7 +166,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.assertEqual(str(venue.id), "8778225")
|
||||
|
||||
|
||||
def test_get_user_registration(self):
|
||||
# Arrange
|
||||
username = "RJ"
|
||||
|
@ -181,7 +178,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Just check date because of timezones
|
||||
self.assertIn(u"2002-11-20 ", registered)
|
||||
|
||||
|
||||
def test_get_user_unixtime_registration(self):
|
||||
# Arrange
|
||||
username = "RJ"
|
||||
|
@ -194,10 +190,10 @@ class TestPyLast(unittest.TestCase):
|
|||
# Just check date because of timezones
|
||||
self.assertEqual(unixtime_registered, u"1037793040")
|
||||
|
||||
|
||||
def test_get_genderless_user(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user("test_user") # currently no gender set
|
||||
# Currently test_user has no gender set:
|
||||
lastfm_user = self.network.get_user("test_user")
|
||||
|
||||
# Act
|
||||
gender = lastfm_user.get_gender()
|
||||
|
@ -205,10 +201,10 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.assertIsNone(gender)
|
||||
|
||||
|
||||
def test_get_countryless_user(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user("test_user") # currently no country set
|
||||
# Currently test_user has no country set:
|
||||
lastfm_user = self.network.get_user("test_user")
|
||||
|
||||
# Act
|
||||
country = lastfm_user.get_country()
|
||||
|
@ -216,7 +212,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.assertIsNone(country)
|
||||
|
||||
|
||||
def test_love(self):
|
||||
# Arrange
|
||||
artist = "Test Artist"
|
||||
|
@ -228,11 +223,10 @@ class TestPyLast(unittest.TestCase):
|
|||
track.love()
|
||||
|
||||
# Assert
|
||||
loved = lastfm_user.get_loved_tracks(limit = 1)
|
||||
loved = lastfm_user.get_loved_tracks(limit=1)
|
||||
self.assertEqual(str(loved[0].track.artist), "Test Artist")
|
||||
self.assertEqual(str(loved[0].track.title), "Test Title")
|
||||
|
||||
|
||||
def test_unlove(self):
|
||||
# Arrange
|
||||
artist = "Test Artist"
|
||||
|
@ -245,59 +239,55 @@ class TestPyLast(unittest.TestCase):
|
|||
track.unlove()
|
||||
|
||||
# Assert
|
||||
loved = lastfm_user.get_loved_tracks(limit = 1)
|
||||
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")
|
||||
|
||||
|
||||
def test_get_100_albums(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user = self.username, network = self.network)
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
|
||||
# Act
|
||||
albums = library.get_albums(limit = 100)
|
||||
albums = library.get_albums(limit=100)
|
||||
|
||||
# Assert
|
||||
self.assertGreaterEqual(len(albums), 0)
|
||||
|
||||
|
||||
def test_get_limitless_albums(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user = self.username, network = self.network)
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
|
||||
# Act
|
||||
albums = library.get_albums(limit = None)
|
||||
albums = library.get_albums(limit=None)
|
||||
|
||||
# Assert
|
||||
self.assertGreaterEqual(len(albums), 0)
|
||||
|
||||
|
||||
def test_user_equals_none(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
value = (lastfm_user == None)
|
||||
value = (lastfm_user is None)
|
||||
|
||||
# Assert
|
||||
self.assertFalse(value)
|
||||
|
||||
|
||||
def test_user_not_equal_to_none(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
value = (lastfm_user != None)
|
||||
value = (lastfm_user is not None)
|
||||
|
||||
# Assert
|
||||
self.assertTrue(value)
|
||||
|
||||
|
||||
def test_now_playing_user_with_no_scrobbles(self):
|
||||
# Arrange
|
||||
user = self.network.get_user('test-account') # currently has no scrobbles
|
||||
# Currently test-account has no scrobbles:
|
||||
user = self.network.get_user('test-account')
|
||||
|
||||
# Act
|
||||
current_track = user.get_now_playing()
|
||||
|
@ -305,10 +295,10 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.assertIsNone(current_track)
|
||||
|
||||
|
||||
def test_love_limits(self):
|
||||
# Arrange
|
||||
user = self.network.get_user("test-user") # currently at least 23 loved tracks
|
||||
# Currently test-account has at least 23 loved tracks:
|
||||
user = self.network.get_user("test-user")
|
||||
|
||||
# Act/Assert
|
||||
self.assertEqual(len(user.get_loved_tracks(limit=20)), 20)
|
||||
|
@ -316,7 +306,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertGreaterEqual(len(user.get_loved_tracks(limit=None)), 23)
|
||||
self.assertGreaterEqual(len(user.get_loved_tracks(limit=0)), 23)
|
||||
|
||||
|
||||
def test_update_now_playing(self):
|
||||
# Arrange
|
||||
artist = "Test Artist"
|
||||
|
@ -326,7 +315,8 @@ class TestPyLast(unittest.TestCase):
|
|||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
self.network.update_now_playing(artist = artist, title = title, album = album, track_number = track_number)
|
||||
self.network.update_now_playing(
|
||||
artist=artist, title=title, album=album, track_number=track_number)
|
||||
|
||||
# Assert
|
||||
current_track = lastfm_user.get_now_playing()
|
||||
|
@ -334,33 +324,31 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertEqual(str(current_track.title), "Test Title")
|
||||
self.assertEqual(str(current_track.artist), "Test Artist")
|
||||
|
||||
|
||||
def test_libre_fm(self):
|
||||
# Arrange
|
||||
username = self.__class__.secrets["username"]
|
||||
password_hash = self.__class__.secrets["password_hash"]
|
||||
|
||||
# Act
|
||||
network = pylast.LibreFMNetwork(password_hash = password_hash, username = username)
|
||||
tags = network.get_top_tags(limit = 1)
|
||||
network = pylast.LibreFMNetwork(
|
||||
password_hash=password_hash, username=username)
|
||||
tags = network.get_top_tags(limit=1)
|
||||
|
||||
# Assert
|
||||
self.assertGreater(len(tags), 0)
|
||||
self.assertEqual(type(tags[0]), pylast.TopItem)
|
||||
|
||||
|
||||
def test_album_tags_are_topitems(self):
|
||||
# Arrange
|
||||
albums = self.network.get_user('RJ').get_top_albums()
|
||||
|
||||
# Act
|
||||
tags = albums[0].item.get_top_tags(limit = 1)
|
||||
tags = albums[0].item.get_top_tags(limit=1)
|
||||
|
||||
# Assert
|
||||
self.assertGreater(len(tags), 0)
|
||||
self.assertEqual(type(tags[0]), pylast.TopItem)
|
||||
|
||||
|
||||
def helper_is_thing_hashable(self, thing):
|
||||
# Arrange
|
||||
things = set()
|
||||
|
@ -379,7 +367,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_is_thing_hashable(album)
|
||||
|
||||
|
||||
def test_artist_is_hashable(self):
|
||||
# Arrange
|
||||
test_artist = self.network.get_artist("Test Artist")
|
||||
|
@ -389,7 +376,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_is_thing_hashable(artist)
|
||||
|
||||
|
||||
def test_country_is_hashable(self):
|
||||
# Arrange
|
||||
country = self.network.get_country("Italy")
|
||||
|
@ -397,24 +383,21 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_is_thing_hashable(country)
|
||||
|
||||
|
||||
def test_country_is_hashable(self):
|
||||
def test_metro_is_hashable(self):
|
||||
# Arrange
|
||||
metro = self.network.get_metro("Helsinki", "Finland")
|
||||
|
||||
# Act/Assert
|
||||
self.helper_is_thing_hashable(metro)
|
||||
|
||||
|
||||
def test_event_is_hashable(self):
|
||||
# Arrange
|
||||
user = self.network.get_user("RJ")
|
||||
event = user.get_past_events(limit = 1)[0]
|
||||
event = user.get_past_events(limit=1)[0]
|
||||
|
||||
# Act/Assert
|
||||
self.helper_is_thing_hashable(event)
|
||||
|
||||
|
||||
def test_group_is_hashable(self):
|
||||
# Arrange
|
||||
group = self.network.get_group("Audioscrobbler Beta")
|
||||
|
@ -422,31 +405,28 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_is_thing_hashable(group)
|
||||
|
||||
|
||||
def test_library_is_hashable(self):
|
||||
# Arrange
|
||||
library = pylast.Library(user = self.username, network = self.network)
|
||||
library = pylast.Library(user=self.username, network=self.network)
|
||||
|
||||
# Act/Assert
|
||||
self.helper_is_thing_hashable(library)
|
||||
|
||||
|
||||
def test_playlist_is_hashable(self):
|
||||
# Arrange
|
||||
playlist = pylast.Playlist(user = "RJ", id = "1k1qp_doglist", network = self.network)
|
||||
playlist = pylast.Playlist(
|
||||
user="RJ", id="1k1qp_doglist", network=self.network)
|
||||
|
||||
# Act/Assert
|
||||
self.helper_is_thing_hashable(playlist)
|
||||
|
||||
|
||||
def test_tag_is_hashable(self):
|
||||
# Arrange
|
||||
tag = self.network.get_top_tags(limit = 1)[0]
|
||||
tag = self.network.get_top_tags(limit=1)[0]
|
||||
|
||||
# Act/Assert
|
||||
self.helper_is_thing_hashable(tag)
|
||||
|
||||
|
||||
def test_track_is_hashable(self):
|
||||
# Arrange
|
||||
artist = self.network.get_artist("Test Artist")
|
||||
|
@ -456,7 +436,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_is_thing_hashable(track)
|
||||
|
||||
|
||||
def test_user_is_hashable(self):
|
||||
# Arrange
|
||||
artist = self.network.get_artist("Test Artist")
|
||||
|
@ -466,7 +445,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_is_thing_hashable(user)
|
||||
|
||||
|
||||
def test_venue_is_hashable(self):
|
||||
# Arrange
|
||||
venue_id = "8778225" # Last.fm office
|
||||
|
@ -475,15 +453,14 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_is_thing_hashable(venue)
|
||||
|
||||
|
||||
def test_xspf_is_hashable(self):
|
||||
# Arrange
|
||||
xspf = pylast.XSPF(uri = "lastfm://playlist/1k1qp_doglist", network = self.network)
|
||||
xspf = pylast.XSPF(
|
||||
uri="lastfm://playlist/1k1qp_doglist", network=self.network)
|
||||
|
||||
# Act/Assert
|
||||
self.helper_is_thing_hashable(xspf)
|
||||
|
||||
|
||||
def test_invalid_xml(self):
|
||||
# Arrange
|
||||
# Currently causes PCDATA invalid Char value 25
|
||||
|
@ -497,12 +474,13 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.assertGreaterEqual(int(total), 0)
|
||||
|
||||
|
||||
def test_user_play_count_in_track_info(self):
|
||||
# Arrange
|
||||
artist = "Test Artist"
|
||||
title = "Test Title"
|
||||
track = pylast.Track(artist = artist, title = title, network = self.network, username = self.username)
|
||||
track = pylast.Track(
|
||||
artist=artist, title=title,
|
||||
network=self.network, username=self.username)
|
||||
|
||||
# Act
|
||||
count = track.get_userplaycount()
|
||||
|
@ -510,12 +488,13 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.assertGreaterEqual(count, 0)
|
||||
|
||||
|
||||
def test_user_loved_in_track_info(self):
|
||||
# Arrange
|
||||
artist = "Test Artist"
|
||||
title = "Test Title"
|
||||
track = pylast.Track(artist = artist, title = title, network = self.network, username = self.username)
|
||||
track = pylast.Track(
|
||||
artist=artist, title=title,
|
||||
network=self.network, username=self.username)
|
||||
|
||||
# Act
|
||||
loved = track.get_userloved()
|
||||
|
@ -525,29 +504,27 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertIsInstance(loved, bool)
|
||||
self.assertNotIsInstance(loved, str)
|
||||
|
||||
|
||||
def test_album_in_recent_tracks(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
track = lastfm_user.get_recent_tracks(limit = 2)[0] # 2 to ignore now-playing
|
||||
# limit=2 to ignore now-playing:
|
||||
track = lastfm_user.get_recent_tracks(limit=2)[0]
|
||||
|
||||
# Assert
|
||||
self.assertTrue(hasattr(track, 'album'))
|
||||
|
||||
|
||||
def test_album_in_artist_tracks(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
||||
# Act
|
||||
track = lastfm_user.get_artist_tracks(artist = "Test Artist")[0]
|
||||
track = lastfm_user.get_artist_tracks(artist="Test Artist")[0]
|
||||
|
||||
# Assert
|
||||
self.assertTrue(hasattr(track, 'album'))
|
||||
|
||||
|
||||
def test_enable_rate_limiting(self):
|
||||
# Arrange
|
||||
self.assertFalse(self.network.is_rate_limited())
|
||||
|
@ -565,7 +542,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertTrue(self.network.is_rate_limited())
|
||||
self.assertGreaterEqual(now - then, 0.2)
|
||||
|
||||
|
||||
def test_disable_rate_limiting(self):
|
||||
# Arrange
|
||||
self.network.enable_rate_limit()
|
||||
|
@ -573,32 +549,28 @@ class TestPyLast(unittest.TestCase):
|
|||
|
||||
# Act
|
||||
self.network.disable_rate_limit()
|
||||
then = time.time()
|
||||
# Make some network call, limit not applied first time
|
||||
self.network.get_user(self.username)
|
||||
# Make a second network call, limiting should be applied
|
||||
self.network.get_top_artists()
|
||||
now = time.time()
|
||||
|
||||
# Assert
|
||||
self.assertFalse(self.network.is_rate_limited())
|
||||
|
||||
|
||||
# Commented out because (a) it'll take a long time and
|
||||
# (b) it strangely fails due Last.fm's complaining of hitting the rate limit,
|
||||
# even when limited to one call per second. The ToS allows 5 calls per second.
|
||||
# Commented out because (a) it'll take a long time and (b) it strangely
|
||||
# fails due Last.fm's complaining of hitting the rate limit, even when
|
||||
# limited to one call per second. The ToS allows 5 calls per second.
|
||||
# def test_get_all_scrobbles(self):
|
||||
# # Arrange
|
||||
# lastfm_user = self.network.get_user("RJ")
|
||||
# self.network.enable_rate_limit() # this is going to be slow...
|
||||
|
||||
# # Act
|
||||
# tracks = lastfm_user.get_recent_tracks(limit = None)
|
||||
# tracks = lastfm_user.get_recent_tracks(limit=None)
|
||||
|
||||
# # Assert
|
||||
# self.assertGreaterEqual(len(tracks), 0)
|
||||
|
||||
|
||||
def helper_past_events_have_valid_ids(self, thing):
|
||||
# Act
|
||||
events = thing.get_past_events()
|
||||
|
@ -606,7 +578,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.helper_assert_events_have_valid_ids(events)
|
||||
|
||||
|
||||
def helper_upcoming_events_have_valid_ids(self, thing):
|
||||
# Act
|
||||
events = thing.get_upcoming_events()
|
||||
|
@ -614,14 +585,13 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.helper_assert_events_have_valid_ids(events)
|
||||
|
||||
|
||||
def helper_assert_events_have_valid_ids(self, events):
|
||||
# Assert
|
||||
self.assertGreaterEqual(len(events), 1) # if fails, add past/future event for user/Test Artist
|
||||
# If fails, add past/future event for user/Test Artist:
|
||||
self.assertGreaterEqual(len(events), 1)
|
||||
for event in events[:2]: # checking first two should be enough
|
||||
self.assertIsInstance(event.get_headliner(), pylast.Artist)
|
||||
|
||||
|
||||
def test_artist_upcoming_events_returns_valid_ids(self):
|
||||
# Arrange
|
||||
artist = pylast.Artist("Test Artist", self.network)
|
||||
|
@ -629,7 +599,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_upcoming_events_have_valid_ids(artist)
|
||||
|
||||
|
||||
def test_user_past_events_returns_valid_ids(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
@ -637,7 +606,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_past_events_have_valid_ids(lastfm_user)
|
||||
|
||||
|
||||
def test_user_recommended_events_returns_valid_ids(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
@ -648,7 +616,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.helper_assert_events_have_valid_ids(events)
|
||||
|
||||
|
||||
def test_user_upcoming_events_returns_valid_ids(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_user(self.username)
|
||||
|
@ -656,7 +623,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_upcoming_events_have_valid_ids(lastfm_user)
|
||||
|
||||
|
||||
def test_venue_past_events_returns_valid_ids(self):
|
||||
# Arrange
|
||||
venue_id = "8778225" # Last.fm office
|
||||
|
@ -665,7 +631,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_past_events_have_valid_ids(venue)
|
||||
|
||||
|
||||
def test_venue_upcoming_events_returns_valid_ids(self):
|
||||
# Arrange
|
||||
venue_id = "8778225" # Last.fm office
|
||||
|
@ -674,7 +639,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_upcoming_events_have_valid_ids(venue)
|
||||
|
||||
|
||||
def test_pickle(self):
|
||||
# Arrange
|
||||
import pickle
|
||||
|
@ -689,31 +653,28 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.assertEqual(lastfm_user, loaded_user)
|
||||
|
||||
|
||||
def test_bio_content(self):
|
||||
# Arrange
|
||||
artist = pylast.Artist("Test Artist", self.network)
|
||||
|
||||
# Act
|
||||
bio = artist.get_bio_content(language = "en")
|
||||
bio = artist.get_bio_content(language="en")
|
||||
|
||||
# Assert
|
||||
self.assertIsNotNone(bio)
|
||||
self.assertGreaterEqual(len(bio), 1)
|
||||
|
||||
|
||||
def test_bio_summary(self):
|
||||
# Arrange
|
||||
artist = pylast.Artist("Test Artist", self.network)
|
||||
|
||||
# Act
|
||||
bio = artist.get_bio_summary(language = "en")
|
||||
bio = artist.get_bio_summary(language="en")
|
||||
|
||||
# Assert
|
||||
self.assertIsNotNone(bio)
|
||||
self.assertGreaterEqual(len(bio), 1)
|
||||
|
||||
|
||||
def test_album_wiki_content(self):
|
||||
# Arrange
|
||||
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||
|
@ -725,7 +686,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertIsNotNone(wiki)
|
||||
self.assertGreaterEqual(len(wiki), 1)
|
||||
|
||||
|
||||
def test_album_wiki_summary(self):
|
||||
# Arrange
|
||||
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||
|
@ -737,7 +697,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertIsNotNone(wiki)
|
||||
self.assertGreaterEqual(len(wiki), 1)
|
||||
|
||||
|
||||
def test_track_wiki_content(self):
|
||||
# Arrange
|
||||
track = pylast.Track("Test Artist", "Test Title", self.network)
|
||||
|
@ -749,7 +708,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertIsNotNone(wiki)
|
||||
self.assertGreaterEqual(len(wiki), 1)
|
||||
|
||||
|
||||
def test_track_wiki_summary(self):
|
||||
# Arrange
|
||||
track = pylast.Track("Test Artist", "Test Title", self.network)
|
||||
|
@ -761,7 +719,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertIsNotNone(wiki)
|
||||
self.assertGreaterEqual(len(wiki), 1)
|
||||
|
||||
|
||||
def test_lastfm_network_name(self):
|
||||
# Act
|
||||
name = str(self.network)
|
||||
|
@ -769,7 +726,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Assert
|
||||
self.assertEqual(name, "Last.fm Network")
|
||||
|
||||
|
||||
def test_artist_get_images_deprecated(self):
|
||||
# Arrange
|
||||
artist = self.network.get_artist("Test Artist")
|
||||
|
@ -778,7 +734,6 @@ class TestPyLast(unittest.TestCase):
|
|||
with self.assertRaisesRegexp(pylast.WSError, 'deprecated'):
|
||||
artist.get_images()
|
||||
|
||||
|
||||
def helper_validate_results(self, a, b, c):
|
||||
# Assert
|
||||
self.assertIsNotNone(a)
|
||||
|
@ -790,21 +745,19 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertEqual(a, b)
|
||||
self.assertEqual(b, c)
|
||||
|
||||
|
||||
def helper_validate_cacheable(self, thing, function_name):
|
||||
# Arrange
|
||||
# get thing.function_name()
|
||||
func = getattr(thing, function_name, None)
|
||||
|
||||
# Act
|
||||
result1 = func(limit = 1, cacheable = False)
|
||||
result2 = func(limit = 1, cacheable = True)
|
||||
result3 = func(limit = 1)
|
||||
result1 = func(limit=1, cacheable=False)
|
||||
result2 = func(limit=1, cacheable=True)
|
||||
result3 = func(limit=1)
|
||||
|
||||
# Assert
|
||||
self.helper_validate_results(result1, result2, result3)
|
||||
|
||||
|
||||
def test_cacheable_artist_get_shouts(self):
|
||||
# Arrange
|
||||
artist = self.network.get_artist("Test Artist")
|
||||
|
@ -812,16 +765,14 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_validate_cacheable(artist, "get_shouts")
|
||||
|
||||
|
||||
def test_cacheable_event_get_shouts(self):
|
||||
# Arrange
|
||||
user = self.network.get_user("RJ")
|
||||
event = user.get_past_events(limit = 1)[0]
|
||||
event = user.get_past_events(limit=1)[0]
|
||||
|
||||
# Act/Assert
|
||||
self.helper_validate_cacheable(event, "get_shouts")
|
||||
|
||||
|
||||
def test_cacheable_track_get_shouts(self):
|
||||
# Arrange
|
||||
track = self.network.get_top_tracks()[0].item
|
||||
|
@ -829,7 +780,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_validate_cacheable(track, "get_shouts")
|
||||
|
||||
|
||||
def test_cacheable_group_get_members(self):
|
||||
# Arrange
|
||||
group = self.network.get_group("Audioscrobbler Beta")
|
||||
|
@ -837,7 +787,6 @@ class TestPyLast(unittest.TestCase):
|
|||
# Act/Assert
|
||||
self.helper_validate_cacheable(group, "get_members")
|
||||
|
||||
|
||||
def test_cacheable_library(self):
|
||||
# Arrange
|
||||
library = pylast.Library(self.username, self.network)
|
||||
|
@ -847,20 +796,18 @@ class TestPyLast(unittest.TestCase):
|
|||
self.helper_validate_cacheable(library, "get_artists")
|
||||
self.helper_validate_cacheable(library, "get_tracks")
|
||||
|
||||
|
||||
def test_cacheable_user_artist_tracks(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_authenticated_user()
|
||||
|
||||
# Act
|
||||
result1 = lastfm_user.get_artist_tracks(artist = "Test Artist", cacheable = False)
|
||||
result2 = lastfm_user.get_artist_tracks(artist = "Test Artist", cacheable = True)
|
||||
result3 = lastfm_user.get_artist_tracks(artist = "Test Artist")
|
||||
result1 = lastfm_user.get_artist_tracks("Test Artist", cacheable=False)
|
||||
result2 = lastfm_user.get_artist_tracks("Test Artist", cacheable=True)
|
||||
result3 = lastfm_user.get_artist_tracks("Test Artist")
|
||||
|
||||
# Assert
|
||||
self.helper_validate_results(result1, result2, result3)
|
||||
|
||||
|
||||
def test_cacheable_user(self):
|
||||
# Arrange
|
||||
lastfm_user = self.network.get_authenticated_user()
|
||||
|
@ -874,11 +821,11 @@ class TestPyLast(unittest.TestCase):
|
|||
self.helper_validate_cacheable(lastfm_user, "get_recommended_events")
|
||||
self.helper_validate_cacheable(lastfm_user, "get_shouts")
|
||||
|
||||
|
||||
def test_geo_get_events_in_location(self):
|
||||
# Arrange
|
||||
# Act
|
||||
events = self.network.get_geo_events(location = "London", tag = "blues", limit = 1)
|
||||
events = self.network.get_geo_events(
|
||||
location="London", tag="blues", limit=1)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(events), 1)
|
||||
|
@ -886,11 +833,11 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertEqual(type(event), pylast.Event)
|
||||
self.assertEqual(event.get_venue().location['city'], "London")
|
||||
|
||||
|
||||
def test_geo_get_events_in_latlong(self):
|
||||
# Arrange
|
||||
# Act
|
||||
events = self.network.get_geo_events(lat = 40.67, long = -73.94, distance = 5, limit = 1)
|
||||
events = self.network.get_geo_events(
|
||||
lat=40.67, long=-73.94, distance=5, limit=1)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(events), 1)
|
||||
|
@ -898,11 +845,11 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertEqual(type(event), pylast.Event)
|
||||
self.assertEqual(event.get_venue().location['city'], "New York")
|
||||
|
||||
|
||||
def test_geo_get_events_festival(self):
|
||||
# Arrange
|
||||
# Act
|
||||
events = self.network.get_geo_events(location = "Reading", festivalsonly = True, limit = 1)
|
||||
events = self.network.get_geo_events(
|
||||
location="Reading", festivalsonly=True, limit=1)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(events), 1)
|
||||
|
@ -910,7 +857,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertEqual(type(event), pylast.Event)
|
||||
self.assertEqual(event.get_venue().location['city'], "Reading")
|
||||
|
||||
|
||||
def test_get_metro_weekly_chart_dates(self):
|
||||
# Arrange
|
||||
# Act
|
||||
|
@ -922,8 +868,7 @@ class TestPyLast(unittest.TestCase):
|
|||
(start, end) = dates[0]
|
||||
self.assertLess(start, end)
|
||||
|
||||
|
||||
def helper_geo_chart(self, function_name, expected_type = pylast.Artist):
|
||||
def helper_geo_chart(self, function_name, expected_type=pylast.Artist):
|
||||
# Arrange
|
||||
metro = self.network.get_metro("Madrid", "Spain")
|
||||
dates = self.network.get_metro_weekly_chart_dates()
|
||||
|
@ -933,77 +878,71 @@ class TestPyLast(unittest.TestCase):
|
|||
func = getattr(metro, function_name, None)
|
||||
|
||||
# Act
|
||||
chart = func(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), expected_type)
|
||||
|
||||
|
||||
def test_get_metro_artist_chart(self):
|
||||
# Arrange/Act/Assert
|
||||
self.helper_geo_chart("get_artist_chart")
|
||||
|
||||
|
||||
def test_get_metro_hype_artist_chart(self):
|
||||
# Arrange/Act/Assert
|
||||
self.helper_geo_chart("get_hype_artist_chart")
|
||||
|
||||
|
||||
def test_get_metro_unique_artist_chart(self):
|
||||
# Arrange/Act/Assert
|
||||
self.helper_geo_chart("get_unique_artist_chart")
|
||||
|
||||
|
||||
def test_get_metro_track_chart(self):
|
||||
# Arrange/Act/Assert
|
||||
self.helper_geo_chart("get_track_chart", expected_type = pylast.Track)
|
||||
|
||||
self.helper_geo_chart("get_track_chart", expected_type=pylast.Track)
|
||||
|
||||
def test_get_metro_hype_track_chart(self):
|
||||
# Arrange/Act/Assert
|
||||
self.helper_geo_chart("get_hype_track_chart", expected_type = pylast.Track)
|
||||
|
||||
self.helper_geo_chart(
|
||||
"get_hype_track_chart", expected_type=pylast.Track)
|
||||
|
||||
def test_get_metro_unique_track_chart(self):
|
||||
# Arrange/Act/Assert
|
||||
self.helper_geo_chart("get_unique_track_chart", expected_type = pylast.Track)
|
||||
|
||||
self.helper_geo_chart(
|
||||
"get_unique_track_chart", expected_type=pylast.Track)
|
||||
|
||||
def test_geo_get_metros(self):
|
||||
# Arrange
|
||||
# Act
|
||||
metros = self.network.get_metros(country = "Poland")
|
||||
metros = self.network.get_metros(country="Poland")
|
||||
|
||||
# Assert
|
||||
self.assertGreaterEqual(len(metros), 1)
|
||||
self.assertEqual(type(metros[0]), pylast.Metro)
|
||||
self.assertEqual(metros[0].get_country(), "Poland")
|
||||
|
||||
|
||||
def test_geo_get_top_artists(self):
|
||||
# Arrange
|
||||
# Act
|
||||
artists = self.network.get_geo_top_artists(country = "United Kingdom", limit = 1)
|
||||
artists = self.network.get_geo_top_artists(
|
||||
country="United Kingdom", limit=1)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(artists), 1)
|
||||
self.assertEqual(type(artists[0]), pylast.TopItem)
|
||||
self.assertEqual(type(artists[0].item), pylast.Artist)
|
||||
|
||||
|
||||
def test_geo_get_top_tracks(self):
|
||||
# Arrange
|
||||
# Act
|
||||
tracks = self.network.get_geo_top_tracks(country = "United Kingdom", location = "Manchester", limit = 1)
|
||||
tracks = self.network.get_geo_top_tracks(
|
||||
country="United Kingdom", location="Manchester", limit=1)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(len(tracks), 1)
|
||||
self.assertEqual(type(tracks[0]), pylast.TopItem)
|
||||
self.assertEqual(type(tracks[0].item), pylast.Track)
|
||||
|
||||
|
||||
def test_metro_class(self):
|
||||
# Arrange
|
||||
# Act
|
||||
|
@ -1014,13 +953,14 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertEqual(metro.get_country(), "Norway")
|
||||
self.assertEqual(str(metro), "Bergen, Norway")
|
||||
self.assertEqual(metro, pylast.Metro("Bergen", "Norway", self.network))
|
||||
self.assertNotEqual(metro, pylast.Metro("Wellington", "New Zealand", self.network))
|
||||
|
||||
self.assertNotEqual(
|
||||
metro,
|
||||
pylast.Metro("Wellington", "New Zealand", self.network))
|
||||
|
||||
def test_get_album_play_links(self):
|
||||
# Arrange
|
||||
album1 = self.network.get_album(artist = "Portishead", title = "Dummy")
|
||||
album2 = self.network.get_album(artist = "Radiohead", title = "OK Computer")
|
||||
album1 = self.network.get_album("Portishead", "Dummy")
|
||||
album2 = self.network.get_album("Radiohead", "OK Computer")
|
||||
albums = [album1, album2]
|
||||
|
||||
# Act
|
||||
|
@ -1032,7 +972,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertIn("spotify:album:", links[0])
|
||||
self.assertIn("spotify:album:", links[1])
|
||||
|
||||
|
||||
def test_get_artist_play_links(self):
|
||||
# Arrange
|
||||
artists = ["Portishead", "Radiohead"]
|
||||
|
@ -1045,11 +984,10 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertIn("spotify:artist:", links[0])
|
||||
self.assertIn("spotify:artist:", links[1])
|
||||
|
||||
|
||||
def test_get_track_play_links(self):
|
||||
# Arrange
|
||||
track1 = self.network.get_track(artist = "Portishead", title = "Mysterons")
|
||||
track2 = self.network.get_track(artist = "Radiohead", title = "Creep")
|
||||
track1 = self.network.get_track(artist="Portishead", title="Mysterons")
|
||||
track2 = self.network.get_track(artist="Radiohead", title="Creep")
|
||||
tracks = [track1, track2]
|
||||
|
||||
# Act
|
||||
|
@ -1061,7 +999,6 @@ class TestPyLast(unittest.TestCase):
|
|||
self.assertIn("spotify:track:", links[0])
|
||||
self.assertIn("spotify:track:", links[1])
|
||||
|
||||
|
||||
def helper_only_one_thing_in_top_list(self, things, expected_type):
|
||||
# Assert
|
||||
self.assertEqual(len(things), 1)
|
||||
|
@ -1074,34 +1011,31 @@ class TestPyLast(unittest.TestCase):
|
|||
user = self.network.get_user("RJ")
|
||||
|
||||
# Act
|
||||
tags = user.get_top_tags(limit = 1)
|
||||
tags = user.get_top_tags(limit=1)
|
||||
|
||||
# Assert
|
||||
self.helper_only_one_thing_in_top_list(tags, pylast.Tag)
|
||||
|
||||
|
||||
def test_network_get_top_artists_with_limit(self):
|
||||
# Arrange
|
||||
# Act
|
||||
artists = self.network.get_top_artists(limit = 1)
|
||||
artists = self.network.get_top_artists(limit=1)
|
||||
|
||||
# Assert
|
||||
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
|
||||
|
||||
|
||||
def test_network_get_top_tags_with_limit(self):
|
||||
# Arrange
|
||||
# Act
|
||||
tags = self.network.get_top_tags(limit = 1)
|
||||
tags = self.network.get_top_tags(limit=1)
|
||||
|
||||
# Assert
|
||||
self.helper_only_one_thing_in_top_list(tags, pylast.Tag)
|
||||
|
||||
|
||||
def test_network_get_top_tracks_with_limit(self):
|
||||
# Arrange
|
||||
# Act
|
||||
tracks = self.network.get_top_tracks(limit = 1)
|
||||
tracks = self.network.get_top_tracks(limit=1)
|
||||
|
||||
# Assert
|
||||
self.helper_only_one_thing_in_top_list(tracks, pylast.Track)
|
||||
|
|
Loading…
Reference in a new issue