コード例 #1
0
def test_get_lastfm_wrong_arguments(lastfm_key):
    """
    `get_lastfm` should fail and return an empty string if they arguments to
    the method are invalid.
    """
    empty = get_lastfm('track.getInfo',
                       lastfm_key=lastfm_key,
                       asdfasdf='asdfasdf')
    assert empty == ''
コード例 #2
0
def test_get_lastfm(lastfm_key):
    """
    The `get_lastfm` function should return a json object with the response
    from the method requested.
    """
    track = get_lastfm('track.getInfo',
                       lastfm_key=lastfm_key,
                       artist='Metallica',
                       track='Master of puppets')
    assert 'track' in track
    assert 'name' in track['track']
    assert 'artist' in track['track']
    assert 'album' in track['track']
コード例 #3
0
def get_album_tracks_lastfm(song):
    """
    Search lastfm for list of tracks in the album this song belongs to.
    """
    song.fetch_album_name()
    if not song.album:
        return []
    tracks = get_lastfm('album.getInfo', artist=song.artist, album=song.album)
    if not tracks:
        return []
    tracks = list(t['name'] for t in tracks['album']['tracks']['track'])
    tracks = list(map(str.lower, tracks))
    return tracks
コード例 #4
0
def test_get_lastfm_wrong_method(lastfm_key):
    """
    `get_lastfm` should fail if the method requested is invalid.
    """
    with pytest.raises(HTTPError):
        get_lastfm('asdfasdf', lastfm_key=lastfm_key)
コード例 #5
0
def test_get_lastfm_wrong_key():
    """
    `get_lastfm` should fail if they key is invalid.
    """
    with pytest.raises(HTTPError):
        get_lastfm('track.getInfo', lastfm_key='asdfasdf')