Fixing issue, checking if elements by tag name have at least 1 element

This commit is contained in:
David Sanchez 2021-05-17 19:10:31 -04:00
parent a516a44c32
commit 219ce29f31
2 changed files with 16 additions and 1 deletions

View file

@ -1153,8 +1153,11 @@ 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)
first_child = doc.getElementsByTagName(tag_name)[0].firstChild elements = doc.getElementsByTagName(tag_name)
if len(elements) == 0:
return None
first_child = elements[0].firstChild
if first_child is None: if first_child is None:
return None return None

View file

@ -417,3 +417,15 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
# Assert # Assert
assert int(total) > 10000 assert int(total) > 10000
def test_mbid_biography_issue(self):
# Arrange
mbid = "e2bef0c5-02e7-4505-b87f-90fc96bd70c3"
# Act
artist = self.network.get_artist_by_mbid(mbid)
# Assert
assert isinstance(artist, pylast.Artist)
assert artist.name == "Space 92"
assert artist.get_bio_content() is None