Extra tests for artist's bio, track/album's wiki content/summary. Closes #87.
This commit is contained in:
parent
cd10d53a82
commit
9edfcb5745
21
pylast.py
21
pylast.py
|
@ -1040,12 +1040,17 @@ class _BaseObject(object):
|
||||||
return hash(self.network) + \
|
return hash(self.network) + \
|
||||||
hash(str(type(self)) + "".join(list(self._get_params().keys()) + list(values)).lower())
|
hash(str(type(self)) + "".join(list(self._get_params().keys()) + list(values)).lower())
|
||||||
|
|
||||||
def _get_events_from_doc(self, doc):
|
def _extract_events_from_doc(self, doc):
|
||||||
events = []
|
events = []
|
||||||
for node in doc.getElementsByTagName("event"):
|
for node in doc.getElementsByTagName("event"):
|
||||||
events.append(Event(_extract(node, "id"), self.network))
|
events.append(Event(_extract(node, "id"), self.network))
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
def _extract_cdata_from_request(self, method_name, tag_name, params):
|
||||||
|
doc = self._request(method_name, True, params)
|
||||||
|
|
||||||
|
return doc.getElementsByTagName(tag_name)[0].firstChild.wholeText.strip()
|
||||||
|
|
||||||
class _Taggable(object):
|
class _Taggable(object):
|
||||||
"""Common functions for classes with tags."""
|
"""Common functions for classes with tags."""
|
||||||
|
|
||||||
|
@ -1496,9 +1501,7 @@ class Artist(_BaseObject, _Taggable):
|
||||||
else:
|
else:
|
||||||
params = None
|
params = None
|
||||||
|
|
||||||
doc = self._request("artist.getInfo", True, params)
|
return self._extract_cdata_from_request("artist.getInfo", "summary", params)
|
||||||
|
|
||||||
return doc.getElementsByTagName('summary')[0].firstChild.wholeText.strip()
|
|
||||||
|
|
||||||
def get_bio_content(self, language=None):
|
def get_bio_content(self, language=None):
|
||||||
"""Returns the content of the artist's biography."""
|
"""Returns the content of the artist's biography."""
|
||||||
|
@ -1509,14 +1512,14 @@ class Artist(_BaseObject, _Taggable):
|
||||||
else:
|
else:
|
||||||
params = None
|
params = None
|
||||||
|
|
||||||
return _extract(self._request("artist.getInfo", True, params), "content")
|
return self._extract_cdata_from_request("artist.getInfo", "content", params)
|
||||||
|
|
||||||
def get_upcoming_events(self):
|
def get_upcoming_events(self):
|
||||||
"""Returns a list of the upcoming Events for this artist."""
|
"""Returns a list of the upcoming Events for this artist."""
|
||||||
|
|
||||||
doc = self._request('artist.getEvents', True)
|
doc = self._request('artist.getEvents', True)
|
||||||
|
|
||||||
return self._get_events_from_doc(doc)
|
return self._extract_events_from_doc(doc)
|
||||||
|
|
||||||
def get_similar(self, limit = None):
|
def get_similar(self, limit = None):
|
||||||
"""Returns the similar artists on the network."""
|
"""Returns the similar artists on the network."""
|
||||||
|
@ -2961,7 +2964,7 @@ class User(_BaseObject):
|
||||||
|
|
||||||
doc = self._request('user.getEvents', True)
|
doc = self._request('user.getEvents', True)
|
||||||
|
|
||||||
return self._get_events_from_doc(doc)
|
return self._extract_events_from_doc(doc)
|
||||||
|
|
||||||
def get_artist_tracks(self, artist):
|
def get_artist_tracks(self, artist):
|
||||||
"""Get a list of tracks by a given artist scrobbled by this user, including scrobble time."""
|
"""Get a list of tracks by a given artist scrobbled by this user, including scrobble time."""
|
||||||
|
@ -3673,14 +3676,14 @@ class Venue(_BaseObject):
|
||||||
|
|
||||||
doc = self._request("venue.getEvents", True)
|
doc = self._request("venue.getEvents", True)
|
||||||
|
|
||||||
return self._get_events_from_doc(doc)
|
return self._extract_events_from_doc(doc)
|
||||||
|
|
||||||
def get_past_events(self):
|
def get_past_events(self):
|
||||||
"""Returns the past events held in this venue."""
|
"""Returns the past events held in this venue."""
|
||||||
|
|
||||||
doc = self._request("venue.getEvents", True)
|
doc = self._request("venue.getEvents", True)
|
||||||
|
|
||||||
return self._get_events_from_doc(doc)
|
return self._extract_events_from_doc(doc)
|
||||||
|
|
||||||
def md5(text):
|
def md5(text):
|
||||||
"""Returns the md5 hash of a string."""
|
"""Returns the md5 hash of a string."""
|
||||||
|
|
|
@ -675,6 +675,18 @@ class TestPyLast(unittest.TestCase):
|
||||||
self.assertEqual(lastfm_user, loaded_user)
|
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()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertIsNotNone(bio)
|
||||||
|
self.assertGreaterEqual(len(bio), 1)
|
||||||
|
|
||||||
|
|
||||||
def test_bio_summary(self):
|
def test_bio_summary(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = pylast.Artist("Test Artist", self.network)
|
artist = pylast.Artist("Test Artist", self.network)
|
||||||
|
@ -687,6 +699,54 @@ class TestPyLast(unittest.TestCase):
|
||||||
self.assertGreaterEqual(len(bio), 1)
|
self.assertGreaterEqual(len(bio), 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_album_wiki_content(self):
|
||||||
|
# Arrange
|
||||||
|
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
wiki = album.get_wiki_content()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertIsNotNone(wiki)
|
||||||
|
self.assertGreaterEqual(len(wiki), 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_album_wiki_summary(self):
|
||||||
|
# Arrange
|
||||||
|
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
wiki = album.get_wiki_summary()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertIsNotNone(wiki)
|
||||||
|
self.assertGreaterEqual(len(wiki), 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_track_wiki_content(self):
|
||||||
|
# Arrange
|
||||||
|
track = pylast.Track("Test Artist", "Test Title", self.network)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
wiki = track.get_wiki_content()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertIsNotNone(wiki)
|
||||||
|
self.assertGreaterEqual(len(wiki), 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_track_wiki_summary(self):
|
||||||
|
# Arrange
|
||||||
|
track = pylast.Track("Test Artist", "Test Title", self.network)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
wiki = track.get_wiki_summary()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertIsNotNone(wiki)
|
||||||
|
self.assertGreaterEqual(len(wiki), 1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
# For quick testing of a single case (eg. test = "test_scrobble")
|
# For quick testing of a single case (eg. test = "test_scrobble")
|
||||||
|
|
Loading…
Reference in a new issue