Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix artist.get_bio_content() to return None if bio is empty #326

Merged
merged 3 commits into from May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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