Source

spotimeta / tests / test_end_to_end.py

Full commit
# -*- coding: utf-8 -*-

from os.path import join
from spotimeta import lookup, search_track, search_album, search_artist

def test_album_lookup():
    res = lookup("spotify:album:6G9fHYDCoyEErUkHrFYfs4")
    album = res["result"]
    assert album
    assert "href" in album
    assert album["href"] == "spotify:album:6G9fHYDCoyEErUkHrFYfs4"
    assert "name" in album
    assert album["name"] == "Remedy"
    assert "artist" in album
    assert album["artist"]["name"] == "Basement Jaxx"
    assert "released" in album
    assert album["released"] == 1999
    assert "artist" in album
    assert album["artist"]["name"] == "Basement Jaxx"
    assert album["artist"]["href"] == "spotify:artist:4YrKBkKSVeqDamzBPWVnSJ"


def test_album_lookup_hard():
    res = lookup("spotify:album:6G9fHYDCoyEErUkHrFYfs4", detail=1)
    album = res["result"]
    assert album
    assert "name" in album
    assert album["name"] == "Remedy"
    assert "artist" in album
    assert album["artist"]["name"] == "Basement Jaxx"
    assert "released" in album
    assert album["released"] == 1999
    assert "artist" in album
    assert album["artist"]["name"] == "Basement Jaxx"
    assert album["artist"]["href"] == "spotify:artist:4YrKBkKSVeqDamzBPWVnSJ"


def test_album_lookup_harder():
    res = lookup("spotify:album:6G9fHYDCoyEErUkHrFYfs4", detail=1)
    album = res["result"]
    assert album
    assert "name" in album
    assert album["name"] == "Remedy"
    assert "artist" in album
    assert album["artist"]["name"] == "Basement Jaxx"
    assert "released" in album
    assert album["released"] == 1999
    assert "artist" in album
    assert album["artist"]["name"] == "Basement Jaxx"
    assert album["artist"]["href"] == "spotify:artist:4YrKBkKSVeqDamzBPWVnSJ"


def test_search_track():
    res = search_track("Trip back to childhood")
    tracks = res["result"]
    assert len(tracks) == min(res["total_results"], res["items_per_page"])


def test_search_album():
    res = search_album("Love")
    albums = res["result"]
    assert len(albums) == min(res["total_results"], res["items_per_page"])


def test_search_artist():
    res = search_artist("The Berlin Project")
    artists = res["result"]
    assert len(artists) == min(res["total_results"], res["items_per_page"])


def test_utf8_query():
    res = search_artist(u"Lillebjørn Nilsen")
    artists = res["result"]
    assert len(artists) == 1
    artist = artists[0]
    assert artist["name"] == u"Lillebjørn Nilsen"