Merge pull request #326 from pylast/fix-if-bio-is-empty

Fix artist.get_bio_content() to return None if bio is empty
This commit is contained in:
Hugo van Kemenade 2020-05-10 10:14:46 +03:00 committed by GitHub
commit 898a8b5756
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 5 deletions

View file

@ -1,6 +1,6 @@
repos: repos:
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v2.1.0 rev: v2.4.1
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: ["--py3-plus"] args: ["--py3-plus"]
@ -15,13 +15,13 @@ repos:
types: [] types: []
- repo: https://gitlab.com/pycqa/flake8 - repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9 rev: 3.8.0a2
hooks: hooks:
- id: flake8 - id: flake8
additional_dependencies: [flake8-2020, flake8-implicit-str-concat] additional_dependencies: [flake8-2020, flake8-implicit-str-concat]
- repo: https://github.com/asottile/seed-isort-config - repo: https://github.com/asottile/seed-isort-config
rev: v2.1.0 rev: v2.1.1
hooks: hooks:
- id: seed-isort-config - id: seed-isort-config

View file

@ -4,7 +4,8 @@
[Travis CI](https://travis-ci.org/pylast/pylast) should be running cleanly for [Travis CI](https://travis-ci.org/pylast/pylast) should be running cleanly for
all merges to master. all merges to master.
* [ ] Edit release draft, adjust text if needed: https://github.com/pylast/pylast/releases * [ ] Edit release draft, adjust text if needed:
https://github.com/pylast/pylast/releases
* [ ] Check next tag is correct, amend if needed * [ ] Check next tag is correct, amend if needed

View file

@ -1142,7 +1142,12 @@ class _BaseObject:
def _extract_cdata_from_request(self, method_name, tag_name, params): def _extract_cdata_from_request(self, method_name, tag_name, params):
doc = self._request(method_name, True, params) doc = self._request(method_name, True, params)
return doc.getElementsByTagName(tag_name)[0].firstChild.wholeText.strip() first_child = doc.getElementsByTagName(tag_name)[0].firstChild
if first_child is None:
return None
return first_child.wholeText.strip()
def _get_things(self, method, thing, thing_type, params=None, cacheable=True): def _get_things(self, method, thing, thing_type, params=None, cacheable=True):
"""Returns a list of the most played thing_types by this thing.""" """Returns a list of the most played thing_types by this thing."""

View file

@ -52,6 +52,17 @@ class TestPyLastArtist(TestPyLastWithLastFm):
self.assertIsNotNone(bio) self.assertIsNotNone(bio)
self.assertGreaterEqual(len(bio), 1) self.assertGreaterEqual(len(bio), 1)
def test_bio_content_none(self):
# Arrange
# An artist with no biography, with "<content/>" in the API XML
artist = pylast.Artist("Mr Sizef + Unquote", self.network)
# Act
bio = artist.get_bio_content()
# Assert
self.assertIsNone(bio)
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)