Ejemplo n.º 1
0
    def _get_flattened_playlist_refs(self):
        if not self._backend._web_client.logged_in:
            return []

        user_playlists = self._backend._web_client.get_user_playlists()
        return translator.to_playlist_refs(user_playlists,
                                           self._backend._web_client.user_id)
Ejemplo n.º 2
0
    def test_bad_playlist_filtered(self, web_playlist_mock):
        refs = list(
            translator.to_playlist_refs([{}, web_playlist_mock, {"foo": 1}])
        )

        assert len(refs) == 1

        assert refs[0].type == models.Ref.PLAYLIST
        assert refs[0].uri == "spotify:user:alice:playlist:foo"
Ejemplo n.º 3
0
    def test_returns_playlist_refs(self, web_playlist_mock):
        web_playlists = [web_playlist_mock] * 3
        refs = list(translator.to_playlist_refs(web_playlists))

        assert refs == [refs[0], refs[0], refs[0]]

        assert refs[0].type == models.Ref.PLAYLIST
        assert refs[0].uri == "spotify:user:alice:playlist:foo"
        assert refs[0].name == "Foo"
Ejemplo n.º 4
0
def _browse_playlists(web_client, variant):
    if not web_client.logged_in:
        return []

    if variant == "featured":
        items = (web_client.get_one("browse/featured-playlists").get(
            "playlists", {}).get("items", []))
        return list(translator.to_playlist_refs(items))
    else:
        return []
Ejemplo n.º 5
0
def _browse_playlists(web_client, variant):
    if not web_client.logged_in:
        return []

    if variant == "featured":
        items = flatten([
            page.get("playlists", {}).get("items", [])
            for page in web_client.get_all(
                "browse/featured-playlists",
                params={"limit": 50},
            ) if page
        ])
        return list(translator.to_playlist_refs(items))
    else:
        return []
Ejemplo n.º 6
0
    def test_passes_username(self, web_playlist_mock):
        refs = list(translator.to_playlist_refs([web_playlist_mock], "bob"))

        assert refs[0].name == "Foo (by alice)"