Move duplication into get_bio(), keeping existing get_bio_XXX() to call it

This commit is contained in:
hugovk 2014-03-07 16:01:54 +02:00
parent 4c94c8e53f
commit 4c4e3bfbba
2 changed files with 38 additions and 28 deletions

View file

@ -1474,8 +1474,8 @@ class _BaseObject(object):
""" """
Returns a section of the wiki. Returns a section of the wiki.
Only for Album/Track. Only for Album/Track.
section can be "content", "summary" or "published" section can be "content", "summary" or
(for published date) "published" (for published date)
""" """
doc = self._request(self.ws_prefix + ".getInfo", True) doc = self._request(self.ws_prefix + ".getInfo", True)
@ -1959,35 +1959,32 @@ class Artist(_BaseObject, _Taggable):
return bool(_number(_extract( return bool(_number(_extract(
self._request(self.ws_prefix + ".getInfo", True), "streamable"))) self._request(self.ws_prefix + ".getInfo", True), "streamable")))
def get_bio(self, section, language=None):
"""
Returns a section of the bio.
section can be "content", "summary" or
"published" (for published date)
"""
if language:
params = self._get_params()
params["lang"] = language
else:
params = None
return self._extract_cdata_from_request(
self.ws_prefix + ".getInfo", section, params)
def get_bio_published_date(self): def get_bio_published_date(self):
"""Returns the date on which the artist's biography was published.""" """Returns the date on which the artist's biography was published."""
return self.get_bio("published")
return _extract(
self._request(self.ws_prefix + ".getInfo", True), "published")
def get_bio_summary(self, language=None): def get_bio_summary(self, language=None):
"""Returns the summary of the artist's biography.""" """Returns the summary of the artist's biography."""
return self.get_bio("summary", language)
if language:
params = self._get_params()
params["lang"] = language
else:
params = None
return self._extract_cdata_from_request(
self.ws_prefix + ".getInfo", "summary", params)
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."""
return self.get_bio("content", language)
if language:
params = self._get_params()
params["lang"] = language
else:
params = None
return self._extract_cdata_from_request(
self.ws_prefix + ".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."""

View file

@ -656,6 +656,17 @@ class TestPyLast(unittest.TestCase):
# Assert # Assert
self.assertEqual(lastfm_user, loaded_user) self.assertEqual(lastfm_user, loaded_user)
def test_bio_published_date(self):
# Arrange
artist = pylast.Artist("Test Artist", self.network)
# Act
bio = artist.get_bio_published_date()
# Assert
self.assertIsNotNone(bio)
self.assertGreaterEqual(len(bio), 1)
def test_bio_content(self): def test_bio_content(self):
# Arrange # Arrange
artist = pylast.Artist("Test Artist", self.network) artist = pylast.Artist("Test Artist", self.network)
@ -1337,9 +1348,11 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Integration (not unit) tests for pylast.py", description="Integration (not unit) tests for pylast.py",
formatter_class=argparse.ArgumentDefaultsHelpFormatter) formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-1', '--single', parser.add_argument(
'-1', '--single',
help="Run a single test") help="Run a single test")
parser.add_argument('-m', '--matching', parser.add_argument(
'-m', '--matching',
help="Run tests with this in the name") help="Run tests with this in the name")
args = parser.parse_args() args = parser.parse_args()
@ -1358,7 +1371,7 @@ if __name__ == '__main__':
tests = [] tests = []
for method, _ in methods: for method, _ in methods:
if method.startswith("test_") and args.matching in method: if method.startswith("test_") and args.matching in method:
print method print(method)
suite.addTest(TestPyLast(method)) suite.addTest(TestPyLast(method))
unittest.TextTestRunner().run(suite) unittest.TextTestRunner().run(suite)