Ejemplo n.º 1
0
async def test_add_release_to_collection_already_exists(
    db: Connection,
    graphql_query,
    snapshot,
):
    query = """
        mutation {
            addReleaseToCollection(collectionId: 5, releaseId: 2) {
                collection {
                    ...CollectionFields
                }
                release {
                    ...ReleaseFields
                }
            }
        }
    """
    col = collection.from_id(5, db)
    assert col is not None

    releases_before = collection.releases(col, db)

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

    releases_after = collection.releases(col, db)

    assert releases_before == releases_after
Ejemplo n.º 2
0
async def test_del_release_from_collection_doesnt_exist(
    db: Connection,
    graphql_query,
    snapshot,
):
    query = """
        mutation {
            delReleaseFromCollection(collectionId: 1, releaseId: 1) {
                collection {
                    ...CollectionFields
                }
                release {
                    ...ReleaseFields
                }
            }
        }
    """
    col = collection.from_id(1, db)
    assert col is not None

    releases_before = collection.releases(col, db)

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

    releases_after = collection.releases(col, db)

    assert releases_before == releases_after
Ejemplo n.º 3
0
def resolve_unstar_collection(_, info: GraphQLResolveInfo,
                              id: int) -> collection.T:
    col = collection.from_id(id, info.context.db)
    if not col:
        raise NotFound(f"Collection {id} does not exist.")

    collection.unstar(col, info.context.user.id, info.context.db)
    return col
Ejemplo n.º 4
0
async def test_unstar_collection(db: Connection, graphql_query, snapshot):
    # Collection 7 should be initially starred.
    col = collection.from_id(7, db)
    assert col is not None
    assert collection.starred(col, user_id=1, conn=db)

    query = """
        mutation {
            unstarCollection(id: 7) {
                ...CollectionFields
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    col = collection.from_id(7, db)
    assert col is not None
    assert not collection.starred(col, user_id=1, conn=db)
Ejemplo n.º 5
0
def resolve_update_collection(
    _,
    info: GraphQLResolveInfo,
    id: int,
    **changes,
) -> collection.T:
    col = collection.from_id(id, info.context.db)
    if not col:
        raise NotFound(f"Collection {id} does not exist.")

    return collection.update(col, info.context.db,
                             **convert_keys_case(changes))
Ejemplo n.º 6
0
def resolve_del_release_from_collection(
    _,
    info: GraphQLResolveInfo,
    collectionId: int,
    releaseId: int,
) -> dict:
    col = collection.from_id(collectionId, info.context.db)
    if not col:
        raise NotFound(f"Collection {collectionId} does not exist.")

    col = collection.del_release(col, releaseId, info.context.db)
    rls = release.from_id(releaseId, info.context.db)

    return {"collection": col, "release": rls}
Ejemplo n.º 7
0
async def test_star_collection(db: Connection, graphql_query, snapshot):
    query = """
        mutation {
            starCollection(id: 5) {
                ...CollectionFields
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    col = collection.from_id(5, db)
    assert col is not None
    assert collection.starred(col, user_id=1, conn=db)
Ejemplo n.º 8
0
async def test_update_collection_immutable(db: Connection, graphql_query, snapshot):
    query = """
        mutation {
            updateCollection(id: 1, name: "NewCollection") {
                ...CollectionFields
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    col = collection.from_id(1, db)
    assert col is not None
    assert col.name != "NewCollection"
Ejemplo n.º 9
0
async def test_create_collection(db: Connection, graphql_query, snapshot):
    query = """
        mutation {
            createCollection(name: "NewCollection", type: COLLAGE) {
                ...CollectionFields
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    col = collection.from_id(data["data"]["createCollection"]["id"], db)
    assert col is not None
    assert col.name == "NewCollection"
    assert col.type == CollectionType.COLLAGE
Ejemplo n.º 10
0
async def test_del_release_from_collection(db: Connection, graphql_query, snapshot):
    query = """
        mutation {
            delReleaseFromCollection(collectionId: 5, releaseId: 2) {
                collection {
                    ...CollectionFields
                }
                release {
                    ...ReleaseFields
                }
            }
        }
    """
    success, data = await graphql_query(query)
    assert success is True
    snapshot.assert_match(data)

    col = collection.from_id(5, db)
    assert col is not None
    assert 2 not in [r.id for r in collection.releases(col, db)]
Ejemplo n.º 11
0
def test_insert_into_genre_preexisting(factory: Factory, db: Connection):
    rls = factory.release(conn=db)
    col = factory.collection(type=CollectionType.GENRE, conn=db)

    _insert_into_genre_collections(rls, [col.name], db)
    assert collection.from_id(col.id, db) in release.collections(rls, db)
Ejemplo n.º 12
0
def test_insert_into_label_collection_existing(factory: Factory,
                                               db: Connection):
    rls = factory.release(conn=db)
    col = factory.collection(type=CollectionType.LABEL, conn=db)
    _insert_into_label_collection(rls, col.name, db)
    assert collection.from_id(col.id, db) in release.collections(rls, db)
Ejemplo n.º 13
0
def resolve_collection(obj: Any, info: GraphQLResolveInfo,
                       id: int) -> collection.T:
    if col := collection.from_id(id, info.context.db):
        return col