Esempio n. 1
0
async def test_del_artist_from_track_doesnt_exist(
    db: Connection,
    graphql_query,
    snapshot,
):
    query = """
        mutation {
            delArtistFromTrack(trackId: 1, artistId: 2, role: FEATURE) {
                track {
                    ...TrackFields
                }
                trackArtist {
                    role
                    artist {
                        ...ArtistFields
                    }
                }
            }
        }
    """
    trk = track.from_id(1, db)
    assert trk is not None

    before_artists = track.artists(trk, db)

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

    after_artists = track.artists(trk, db)

    assert before_artists == after_artists
Esempio n. 2
0
async def test_add_artist_to_track_already_exists(
    db: Connection,
    graphql_query,
    snapshot,
):
    query = """
        mutation {
            addArtistToTrack(trackId: 1, artistId: 2, role: MAIN) {
                track {
                    ...TrackFields
                }
                trackArtist {
                    role
                    artist {
                        ...ArtistFields
                    }
                }
            }
        }
    """
    trk = track.from_id(1, db)
    assert trk is not None

    before_artists = track.artists(trk, db)

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

    after_artists = track.artists(trk, db)

    assert before_artists == after_artists
Esempio n. 3
0
def _fix_album_artists(conn: Connection) -> None:
    """
    Because not all albums contain the album artist tag, we look at all releases with no
    album artists and either assign them their track artists or assign them to the
    Unknown Artist.

    If the album's tracks have artists, then we conditionally assign the album artist
    based off the track's artists. See the code for the specific logic.

    :param conn: A connection to the database.
    """
    logger.info("Fixing album artists...")

    cursor = conn.execute("""
        SELECT rls.id
        FROM music__releases AS rls
        WHERE NOT EXISTS(
            SELECT 1 FROM music__releases_artists WHERE release_id = rls.id
        )
        """)
    release_ids = [row[0] for row in cursor]

    for rid in release_ids:
        rls = release.from_id(rid, conn)
        assert rls is not None

        tracks = release.tracks(rls, conn)
        amaps = chain.from_iterable(track.artists(trk, conn) for trk in tracks)
        artists = {
            amap["artist"]
            for amap in amaps if amap["role"] in MAIN_ROLES
        }

        for art in artists:
            release.add_artist(rls, art.id, ArtistRole.MAIN, conn)
Esempio n. 4
0
def test_catalog_file_duplicate_artist(
    tagfile: mock.MagicMock,
    calc_sha: mock.MagicMock,
    mock_fetch_or_create_release: mock.MagicMock,
    factory: Factory,
    db: Connection,
):
    filepath = "/tmp/music.m4a"
    rls = factory.release(conn=db)
    mock_fetch_or_create_release.return_value = mock.Mock(id=rls.id)
    calc_sha.return_value = b"0" * 32
    tagfile.return_value = mock.Mock(
        artist={ArtistRole.MAIN: ["art1", "art1"]},
        title=None,
        version=None,
        path=Path(filepath),
        mut=mock.Mock(info=mock.Mock(length=1)),
        track_number="1",
        disc_number="1",
    )

    catalog_file(filepath, db)

    trk = track.from_filepath(filepath, db)
    assert trk is not None
    assert len(track.artists(trk, db)) == 1
Esempio n. 5
0
def test_catalog_file(
    mock_fetch_or_create_release: mock.MagicMock,
    factory: Factory,
    db: Connection,
    snapshot,
):
    rls = factory.release(conn=db)

    mock_fetch_or_create_release.return_value = mock.Mock(id=rls.id)

    filepath = NEW_ALBUM / "track1.flac"
    trk = catalog_file(str(filepath), db)
    assert trk is not None

    # Because filepath is not a reproducible value (depends on environment),
    # we exclude it from our snapshot and test it separately.
    track_dict = asdict(trk)
    del track_dict["filepath"]

    assert str(trk.filepath).endswith("/track1.flac")
    snapshot.assert_match(track_dict)
    snapshot.assert_match(track.artists(trk, db))
Esempio n. 6
0
async def test_del_artist_from_track(db: Connection, graphql_query, snapshot):
    query = """
        mutation {
            delArtistFromTrack(trackId: 1, artistId: 2, role: MAIN) {
                track {
                    ...TrackFields
                }
                trackArtist {
                    role
                    artist {
                        ...ArtistFields
                    }
                }
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    trk = track.from_id(1, db)
    assert trk is not None
    assert 2 not in [a["artist"].id for a in track.artists(trk, db)]
Esempio n. 7
0
def resolve_top_genres(obj: track.T, info: GraphQLResolveInfo) -> list[dict]:
    return track.artists(obj, info.context.db)