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 when getElementsByTagName #368

Closed
wants to merge 1 commit into from

Conversation

emulienfou
Copy link

This Pull Request is related to #326

  • Checking if the code doc.getElementsByTagName(tag_name) return at least 1 element in the dictionary.
  • Adding tests to be able to return None instead of exception:
 first_child = doc.getElementsByTagName(tag_name)[0].firstChild
 IndexError: list index out of range

@hugovk
Copy link
Member

hugovk commented May 28, 2021

When I run the test locally, I get pylast.WSError: The artist you supplied could not be found:

$ pytest tests/test_network.py -k test_mbid_biography_issue
=============================================== test session starts ================================================
platform darwin -- Python 3.9.5, pytest-6.2.4, py-1.9.0, pluggy-0.13.1
rootdir: /Users/hugo/github/pylast, configfile: pytest.ini
plugins: hypothesis-6.9.2, requests-mock-1.8.0, rerunfailures-9.1.1, cov-2.12.0, flaky-3.7.0, mockito-0.0.4, xdist-2.2.1, testmon-1.0.3, timeout-1.4.2, forked-1.3.0
collected 31 items / 30 deselected / 1 selected

tests/test_network.py F                                                                                      [100%]

===================================================== FAILURES =====================================================
___________________________________ TestPyLastNetwork.test_mbid_biography_issue ____________________________________

self = <tests.test_network.TestPyLastNetwork object at 0x11010ef70>

    def test_mbid_biography_issue(self):
        # Arrange
        mbid = "e2bef0c5-02e7-4505-b87f-90fc96bd70c3"

        # Act
>       artist = self.network.get_artist_by_mbid(mbid)

tests/test_network.py:426:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/pylast/__init__.py:478: in get_artist_by_mbid
    doc = _Request(self, "artist.getInfo", params).execute(True)
src/pylast/__init__.py:973: in execute
    response = self._download_response()
src/pylast/__init__.py:962: in _download_response
    self._check_response_for_errors(response_text)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pylast._Request object at 0x11010e970>
response = '<?xml version="1.0" encoding="UTF-8" ?>\n<lfm status="failed"><error code="6">The artist you supplied could not be found</error>\n</lfm>\n'

    def _check_response_for_errors(self, response):
        """Checks the response for errors and raises one if any exists."""

        try:
            doc = minidom.parseString(_string(response).replace("opensearch:", ""))
        except Exception as e:
            raise MalformedResponseError(self.network, e) from e

        e = doc.getElementsByTagName("lfm")[0]
        # logger.debug(doc.toprettyxml())

        if e.getAttribute("status") != "ok":
            e = doc.getElementsByTagName("error")[0]
            status = e.getAttribute("code")
            details = e.firstChild.data.strip()
>           raise WSError(self.network, status, details)
E           pylast.WSError: The artist you supplied could not be found

src/pylast/__init__.py:992: WSError
===Flaky Test Report===

test_mbid_biography_issue failed and was not selected for rerun.
	<class 'pylast.WSError'>
	The artist you supplied could not be found
	[<TracebackEntry /Users/hugo/github/pylast/tests/test_network.py:426>, <TracebackEntry /Users/hugo/github/pylast/src/pylast/__init__.py:478>, <TracebackEntry /Users/hugo/github/pylast/src/pylast/__init__.py:973>, <TracebackEntry /Users/hugo/github/pylast/src/pylast/__init__.py:962>, <TracebackEntry /Users/hugo/github/pylast/src/pylast/__init__.py:992>]

===End Flaky Test Report===
============================================= short test summary info ==============================================
FAILED tests/test_network.py::TestPyLastNetwork::test_mbid_biography_issue - pylast.WSError: The artist you suppl...
========================================= 1 failed, 30 deselected in 3.01s =========================================

@emulienfou
Copy link
Author

@hugovk That's weird because it was working perfectly with this MBID 11 days ago.
Tested an other artist with a valid MBID it's not working either.
It's like they removed some MBID from their DB

@hugovk
Copy link
Member

hugovk commented May 28, 2021

@emulienfou
Copy link
Author

Yes, seems the relation between LastFM and MusicBrainz using this ID in their database has been removed.
Will have to find an other artist with existing relation to be able to make the test work

@hugovk
Copy link
Member

hugovk commented Aug 2, 2021

This may have been fixed by #370, please could you retest with master?

@hugovk
Copy link
Member

hugovk commented Oct 19, 2021

Assuming this is now fixed, can re-open if necessary.

@hugovk hugovk closed this Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants