def test_successful_translation(self, sp_album_mock):
        album = translator.to_album(sp_album_mock)

        assert album.uri == 'spotify:album:def'
        assert album.name == 'DEF 456'
        assert list(album.artists) == [
            models.Artist(uri='spotify:artist:abba', name='ABBA')]
        assert album.date == '2001'
Exemple #2
0
    def test_successful_translation(self, sp_album_mock):
        album = translator.to_album(sp_album_mock)

        assert album.uri == 'spotify:album:def'
        assert album.name == 'DEF 456'
        assert list(album.artists) == [
            models.Artist(uri='spotify:artist:abba', name='ABBA')
        ]
        assert album.date == '2001'
Exemple #3
0
    def test_successful_translation(self, sp_album_mock):
        album = translator.to_album(sp_album_mock)

        assert album.uri == "spotify:album:def"
        assert album.name == "DEF 456"
        assert list(album.artists) == [
            models.Artist(uri="spotify:artist:abba", name="ABBA")
        ]
        assert album.date == "2001"
def search(config, session, query=None, uris=None, exact=False):
    # TODO Respect `uris` argument
    # TODO Support `exact` search

    if query is None:
        logger.debug('Ignored search without query')
        return models.SearchResult(uri='spotify:search')

    if 'uri' in query:
        return _search_by_uri(config, session, query)

    sp_query = translator.sp_search_query(query)
    if not sp_query:
        logger.debug('Ignored search with empty query')
        return models.SearchResult(uri='spotify:search')

    uri = 'spotify:search:%s' % urllib.quote(sp_query.encode('utf-8'))
    logger.info('Searching Spotify for: %s', sp_query)

    if session.connection.state is not spotify.ConnectionState.LOGGED_IN:
        logger.info('Spotify search aborted: Spotify is offline')
        return models.SearchResult(uri=uri)

    sp_search = session.search(sp_query,
                               album_count=config['search_album_count'],
                               artist_count=config['search_artist_count'],
                               track_count=config['search_track_count'])
    sp_search.load()

    albums = [translator.to_album(sp_album) for sp_album in sp_search.albums]
    artists = [
        translator.to_artist(sp_artist) for sp_artist in sp_search.artists
    ]
    tracks = [translator.to_track(sp_track) for sp_track in sp_search.tracks]

    return models.SearchResult(uri=uri,
                               albums=albums,
                               artists=artists,
                               tracks=tracks)
Exemple #5
0
def search(config, session, query=None, uris=None, exact=False):
    # TODO Respect `uris` argument
    # TODO Support `exact` search

    if query is None:
        logger.debug('Ignored search without query')
        return models.SearchResult(uri='spotify:search')

    if 'uri' in query:
        return _search_by_uri(config, session, query)

    sp_query = translator.sp_search_query(query)
    if not sp_query:
        logger.debug('Ignored search with empty query')
        return models.SearchResult(uri='spotify:search')

    uri = 'spotify:search:%s' % urllib.quote(sp_query.encode('utf-8'))
    logger.info('Searching Spotify for: %s', sp_query)

    if session.connection.state is not spotify.ConnectionState.LOGGED_IN:
        logger.info('Spotify search aborted: Spotify is offline')
        return models.SearchResult(uri=uri)

    sp_search = session.search(
        sp_query,
        album_count=config['search_album_count'],
        artist_count=config['search_artist_count'],
        track_count=config['search_track_count'])
    sp_search.load()

    albums = [
        translator.to_album(sp_album) for sp_album in sp_search.albums]
    artists = [
        translator.to_artist(sp_artist) for sp_artist in sp_search.artists]
    tracks = [
        translator.to_track(sp_track) for sp_track in sp_search.tracks]

    return models.SearchResult(
        uri=uri, albums=albums, artists=artists, tracks=tracks)
    def test_returns_unknown_date_if_year_is_zero(self, sp_album_mock):
        sp_album_mock.year = 0

        album = translator.to_album(sp_album_mock)

        assert album.date is None
    def test_returns_empty_artists_list_if_artist_is_none(self, sp_album_mock):
        sp_album_mock.artist = None

        album = translator.to_album(sp_album_mock)

        assert list(album.artists) == []
    def test_returns_none_if_unloaded(self, sp_album_mock):
        sp_album_mock.is_loaded = False

        album = translator.to_album(sp_album_mock)

        assert album is None
    def test_caches_results(self, sp_album_mock):
        album1 = translator.to_album(sp_album_mock)
        album2 = translator.to_album(sp_album_mock)

        assert album1 is album2
Exemple #10
0
    def test_returns_unknown_date_if_year_is_zero(self, sp_album_mock):
        sp_album_mock.year = 0

        album = translator.to_album(sp_album_mock)

        assert album.date is None
Exemple #11
0
    def test_returns_empty_artists_list_if_artist_is_none(self, sp_album_mock):
        sp_album_mock.artist = None

        album = translator.to_album(sp_album_mock)

        assert list(album.artists) == []
Exemple #12
0
    def test_returns_none_if_unloaded(self, sp_album_mock):
        sp_album_mock.is_loaded = False

        album = translator.to_album(sp_album_mock)

        assert album is None
Exemple #13
0
    def test_caches_results(self, sp_album_mock):
        album1 = translator.to_album(sp_album_mock)
        album2 = translator.to_album(sp_album_mock)

        assert album1 is album2