Skip to content

Commit

Permalink
Merge pull request #326 from pylast/fix-if-bio-is-empty
Browse files Browse the repository at this point in the history
Fix artist.get_bio_content() to return None if bio is empty
  • Loading branch information
hugovk committed May 10, 2020
2 parents 2aaa594 + 925cae2 commit 898a8b5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.1.0
rev: v2.4.1
hooks:
- id: pyupgrade
args: ["--py3-plus"]
Expand All @@ -15,13 +15,13 @@ repos:
types: []

- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
rev: 3.8.0a2
hooks:
- id: flake8
additional_dependencies: [flake8-2020, flake8-implicit-str-concat]

- repo: https://github.com/asottile/seed-isort-config
rev: v2.1.0
rev: v2.1.1
hooks:
- id: seed-isort-config

Expand Down
3 changes: 2 additions & 1 deletion RELEASING.md
Expand Up @@ -4,7 +4,8 @@
[Travis CI](https://travis-ci.org/pylast/pylast) should be running cleanly for
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

Expand Down
7 changes: 6 additions & 1 deletion src/pylast/__init__.py
Expand Up @@ -1142,7 +1142,12 @@ def __hash__(self):
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()
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):
"""Returns a list of the most played thing_types by this thing."""
Expand Down
11 changes: 11 additions & 0 deletions tests/test_artist.py
Expand Up @@ -52,6 +52,17 @@ def test_bio_content(self):
self.assertIsNotNone(bio)
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):
# Arrange
artist = pylast.Artist("Test Artist", self.network)
Expand Down

0 comments on commit 898a8b5

Please sign in to comment.