diff --git a/pylast.py b/pylast.py index 2fc2efc..bc351c2 100644 --- a/pylast.py +++ b/pylast.py @@ -1474,8 +1474,8 @@ class _BaseObject(object): """ Returns a section of the wiki. Only for Album/Track. - section can be "content", "summary" or "published" - (for published date) + section can be "content", "summary" or + "published" (for published date) """ doc = self._request(self.ws_prefix + ".getInfo", True) @@ -1959,35 +1959,32 @@ class Artist(_BaseObject, _Taggable): return bool(_number(_extract( 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): """Returns the date on which the artist's biography was published.""" - - return _extract( - self._request(self.ws_prefix + ".getInfo", True), "published") + return self.get_bio("published") def get_bio_summary(self, language=None): """Returns the summary of the artist's biography.""" - - if language: - params = self._get_params() - params["lang"] = language - else: - params = None - - return self._extract_cdata_from_request( - self.ws_prefix + ".getInfo", "summary", params) + return self.get_bio("summary", language) def get_bio_content(self, language=None): """Returns the content of the artist's biography.""" - - if language: - params = self._get_params() - params["lang"] = language - else: - params = None - - return self._extract_cdata_from_request( - self.ws_prefix + ".getInfo", "content", params) + return self.get_bio("content", language) def get_upcoming_events(self): """Returns a list of the upcoming Events for this artist.""" diff --git a/test_pylast.py b/test_pylast.py index d93b2f3..513ceda 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -656,6 +656,17 @@ class TestPyLast(unittest.TestCase): # Assert 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): # Arrange artist = pylast.Artist("Test Artist", self.network) @@ -1335,11 +1346,13 @@ class TestPyLast(unittest.TestCase): if __name__ == '__main__': parser = argparse.ArgumentParser( - description = "Integration (not unit) tests for pylast.py", - formatter_class = argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('-1', '--single', + description="Integration (not unit) tests for pylast.py", + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument( + '-1', '--single', help="Run a single test") - parser.add_argument('-m', '--matching', + parser.add_argument( + '-m', '--matching', help="Run tests with this in the name") args = parser.parse_args() @@ -1358,7 +1371,7 @@ if __name__ == '__main__': tests = [] for method, _ in methods: if method.startswith("test_") and args.matching in method: - print method + print(method) suite.addTest(TestPyLast(method)) unittest.TextTestRunner().run(suite)