Example #1
0
def test_by_kfids_simple(dataservice_setup):
    n = 2
    populate_data(n)

    desc = find_descendants_by_kfids(
        DATASERVICE_URL,
        "participants", ["PT_11111111"],
        ignore_gfs_with_hidden_external_contribs=False,
        kfids_only=False)
    assert len(desc["participants"]) == 1
    assert len(desc["biospecimens"]) == n
    # parent level should be populated
    assert isinstance(desc["participants"]["PT_11111111"], dict)

    desc = find_descendants_by_kfids(
        DATASERVICE_URL,
        "participants", ["PT_10111111", "PT_11111111"],
        ignore_gfs_with_hidden_external_contribs=False,
        kfids_only=False)
    assert len(desc["participants"]) == n
    assert len(desc["biospecimens"]) == n * n

    desc = find_descendants_by_kfids(
        DATASERVICE_URL,
        "studies", ["SD_11111111"],
        ignore_gfs_with_hidden_external_contribs=False,
        kfids_only=False)
    assert len(desc["participants"]) == n
    assert len(desc["biospecimens"]) == n * n
Example #2
0
def test_yield_entities_from_filter(dataservice_setup):
    n = 2
    populate_data(n)

    si = 1
    filter = {"study_id": f"SD_{si}1111111"}

    # Get all participants from one study
    endpoint = "participants"
    for ps in [
            list(yield_entities_from_filter(DATASERVICE_URL, endpoint,
                                            filter)),
            list(yield_entities(DATASERVICE_URL, endpoint, filter)),
    ]:
        assert len(ps) == n
        for p in ps:
            assert p["kf_id"].startswith(f"PT_{si}")

    # Get all biospecimens from one study
    endpoint = "biospecimens"
    for bs in [
            list(yield_entities_from_filter(DATASERVICE_URL, endpoint,
                                            filter)),
            list(yield_entities(DATASERVICE_URL, endpoint, filter)),
    ]:
        assert len(bs) == (n * n)
        for b in bs:
            assert b["kf_id"].startswith(f"BS_{si}")
Example #3
0
def test_yield_entities_from_kfids(dataservice_setup):
    n = 2
    populate_data(n)

    kfid_set = {"SD_11111111", "PT_11111111", "BS_11111111"}
    for es in [
            list(yield_entities_from_kfids(DATASERVICE_URL, kfid_set)),
            list(yield_entities(DATASERVICE_URL, None, kfid_set)),
    ]:
        assert len(es) == len(kfid_set)
        found_kfids = {e["kf_id"] for e in es}
        assert kfid_set == found_kfids
def test_hide_unhide_entities(dataservice_setup):
    n = 2
    kfids = populate_data(n)
    to_hide = {"PT_00111111", "BS_11111111"}

    hide_kfids(DATASERVICE_URL, to_hide)
    entities = list(yield_entities_from_kfids(DATASERVICE_URL, kfids))
    hidden = [e for e in entities if e["kf_id"] in to_hide]

    assert not hide_entities(DATASERVICE_URL, hidden)
    entities = list(yield_entities_from_kfids(DATASERVICE_URL, kfids))
    hidden = [e for e in entities if e["kf_id"] in to_hide]
    for e in entities:
        assert e["visible"] ^ (e["kf_id"] in to_hide)

    assert unhide_entities(DATASERVICE_URL, hidden)
    entities = list(yield_entities_from_kfids(DATASERVICE_URL, kfids))
    hidden = [e for e in entities if e["kf_id"] in to_hide]
    for e in entities:
        assert e["visible"]
    
    assert not unhide_entities(DATASERVICE_URL, hidden)
    entities = list(yield_entities_from_kfids(DATASERVICE_URL, kfids))
    hidden = [e for e in entities if e["kf_id"] in to_hide]
    for e in entities:
        assert e["visible"]
def test_hide_unhide_kfids(dataservice_setup):
    n = 2
    kfids = populate_data(n)
    to_hide = {"PT_00111111", "BS_11111111"}

    hide_kfids(DATASERVICE_URL, to_hide)
    for e in yield_entities_from_kfids(DATASERVICE_URL, kfids):
        assert e["visible"] ^ (e["kf_id"] in to_hide)

    unhide_kfids(DATASERVICE_URL, to_hide)
    for e in yield_entities_from_kfids(DATASERVICE_URL, kfids):
        assert e["visible"]
Example #6
0
def test_already_done(dataservice_setup):
    n = 2
    all_kfids = populate_data(n)
    sdids = ["SD_11111111"]

    changed = unhide_descendants_by_kfids(DATASERVICE_URL, "studies", sdids)
    assert not changed

    changed = hide_descendants_by_kfids(DATASERVICE_URL, "studies", sdids)
    assert len(changed) == 1 + n + n * n

    changed = unhide_descendants_by_kfids(DATASERVICE_URL, "studies", sdids)
    assert len(changed) == 1 + n + n * n
def test_delete_many(dataservice_setup):
    # iterating the wrong way clogs an executor
    # see https://github.com/kids-first/kf-utils-python/pull/36#pullrequestreview-685334120
    populate_data(1, 500, 0)
    delete_entities(DATASERVICE_URL)