Beispiel #1
0
def resolve_star_playlist(_, info: GraphQLResolveInfo, id: int) -> playlist.T:
    ply = playlist.from_id(id, info.context.db)
    if not ply:
        raise NotFound(f"Playlist {id} does not exist.")

    playlist.star(ply, info.context.user.id, info.context.db)
    return ply
Beispiel #2
0
async def test_unstar_playlist(db: Connection, graphql_query, snapshot):
    # Playlist 5 should be initially starred.
    ply = playlist.from_id(5, db)
    assert ply is not None
    assert playlist.starred(ply, user_id=1, conn=db)

    query = """
        mutation {
            unstarPlaylist(id: 5) {
                ...PlaylistFields
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    ply = playlist.from_id(5, db)
    assert ply is not None
    assert not playlist.starred(ply, user_id=1, conn=db)
Beispiel #3
0
def delete_playlist_entry(
    obj: Any,
    info: GraphQLResolveInfo,
    id: int,
) -> dict:
    if ety := pentry.from_id(id, info.context.db):
        pentry.delete(ety, info.context.db)
        return {
            "playlist": playlist.from_id(ety.playlist_id, info.context.db),
            "track": track.from_id(ety.track_id, info.context.db),
        }
Beispiel #4
0
def resolve_update_playlist(
    _,
    info: GraphQLResolveInfo,
    id: int,
    **changes,
) -> playlist.T:
    ply = playlist.from_id(id, info.context.db)
    if not ply:
        raise NotFound(f"Playlist {id} does not exist.")

    return playlist.update(ply, info.context.db, **convert_keys_case(changes))
Beispiel #5
0
async def test_star_playlist(db: Connection, graphql_query, snapshot):
    query = """
        mutation {
            starPlaylist(id: 3) {
                ...PlaylistFields
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    ply = playlist.from_id(3, db)
    assert ply is not None
    assert playlist.starred(ply, user_id=1, conn=db)
Beispiel #6
0
async def test_update_playlist(db: Connection, graphql_query, snapshot):
    query = """
        mutation {
            updatePlaylist(id: 4, name: "NewPlaylist") {
                ...PlaylistFields
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    ply = playlist.from_id(4, db)
    assert ply is not None
    assert ply.name == "NewPlaylist"
Beispiel #7
0
async def test_create_playlist(db: Connection, graphql_query, snapshot):
    query = """
        mutation {
            createPlaylist(name: "NewPlaylist", type: PLAYLIST) {
                ...PlaylistFields
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    ply = playlist.from_id(data["data"]["createPlaylist"]["id"], db)
    assert ply is not None
    assert ply.name == "NewPlaylist"
    assert ply.type == PlaylistType.PLAYLIST
Beispiel #8
0
def delete_playlist_entries(
    obj: Any,
    info: GraphQLResolveInfo,
    playlistId: int,
    trackId: int,
) -> dict:
    for ety in pentry.from_playlist_and_track(playlistId, trackId, info.context.db):
        pentry.delete(ety, info.context.db)

    ply = playlist.from_id(playlistId, info.context.db)
    if not ply:
        raise NotFound(f"Playlist {playlistId} does not exist.")

    trk = track.from_id(trackId, info.context.db)
    if not trk:
        raise NotFound(f"Track {trackId} does not exist.")

    return {"playlist": ply, "track": trk}
async def test_create_playlist_entry_bad_track(db: Connection, graphql_query,
                                               snapshot):
    query = """
        mutation {
            createPlaylistEntry(playlistId: 1, trackId: 9999) {
                ...PlaylistEntryFields
            }
        }
    """
    ply = playlist.from_id(1, db)
    assert ply is not None

    before_tracks = playlist.entries(ply, db)

    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    after_tracks = playlist.entries(ply, db)

    assert before_tracks == after_tracks
Beispiel #10
0
def resolve_playlist(obj: Any, info: GraphQLResolveInfo,
                     id: int) -> playlist.T:
    if ply := playlist.from_id(id, info.context.db):
        return ply