Example #1
0
def test_group_becomes_individuals():
    """Tests that when a group's numbers go to 1 it transforms into an "animal" from a "group" """
    df = read_xlsx_data(INPUT_EXAMPLE)
    create_enclosures(df)
    create_species(df)

    animals, groups = find_animals_groups(df)

    create_animals(animals)
    create_groups(groups)

    accession = "111112"
    gp = Group.objects.get(accession_number=accession)
    assert gp.population_total > 1

    # modify the df to have only one population
    df.at[df[df["Accession"] == accession].index[0], "Population _Female"] = 0
    df.at[df[df["Accession"] == accession].index[0], "Population _Unknown"] = 1

    # get_changesets on that dataframe
    changeset = get_changesets(df)

    # assert we are adding an individual
    animal_changes_accession = [
        ch_a["object_kwargs"]["Accession"] for ch_a in changeset["animals"]
        if ch_a["action"] == "add"
    ]
    assert accession in animal_changes_accession

    # assert we are removing the group
    group_changes_accession = [
        ch_a["object_kwargs"]["accession_number"]
        for ch_a in changeset["groups"] if ch_a["action"] == "del"
    ]
    assert accession in group_changes_accession
Example #2
0
def test_create_enclosures():

    encl_name = "example_enclosure"

    df = pd.DataFrame({"Enclosure": encl_name}, index=[0])
    create_enclosures(df)

    test_enclosure = Enclosure.objects.get(name=encl_name)

    assert test_enclosure is not None
Example #3
0
def main():
    parser = argparse.ArgumentParser(description="Parse csv file for animals")
    parser.add_argument("csvfile")
    args = parser.parse_args()

    df = read_xlsx_data(args.csvfile)
    create_enclosures(df)
    create_species(df)

    animals, groups = find_animals_groups(df)
    create_animals(animals)
    create_groups(groups)

    print(f"Processed {args.csvfile}")
Example #4
0
def test_create_groups():
    df = read_xlsx_data(INPUT_EXAMPLE)
    create_enclosures(df)
    create_species(df)

    with pytest.raises(ValueError,
                       match="Cannot create groups. Not all have a pop. > 1"):
        create_groups(df)

    animals, groups = find_animals_groups(df)
    create_groups(groups)

    for acc_num in groups["Accession"]:
        g = Group.objects.get(accession_number=acc_num)
        assert g.population_total > 1

    for acc_num in animals["Accession"]:
        with pytest.raises(ObjectDoesNotExist):
            Group.objects.get(accession_number=acc_num)
Example #5
0
def test_create_animals():
    df = read_xlsx_data(INPUT_EXAMPLE)

    # need to first create species, enclosures
    create_enclosures(df)
    create_species(df)

    with pytest.raises(
            ValueError,
            match="Cannot create individuals. Not all have a pop. of 1"):
        create_animals(df)

    animals, groups = find_animals_groups(df)
    create_animals(animals)

    for acc_num in animals["Accession"]:
        Animal.objects.get(accession_number=acc_num)

    for acc_num in groups["Accession"]:
        with pytest.raises(ObjectDoesNotExist):
            Animal.objects.get(accession_number=acc_num)
Example #6
0
def test_individual_becomes_group():
    """Tests that when an individual's numbers go > 1 it transforms into a "group" from an "animal" """
    df = read_xlsx_data(INPUT_EXAMPLE)
    create_enclosures(df)
    create_species(df)

    animals, groups = find_animals_groups(df)

    create_animals(animals)
    create_groups(groups)

    accession = "111111"

    # this would raise an not found exception if it was not present
    Animal.objects.get(accession_number=accession)

    # modify the df to have > one population
    df.at[df[df["Accession"] == accession].index[0], "Population _Female"] = 1
    df.at[df[df["Accession"] == accession].index[0], "Population _Unknown"] = 1

    # get_changesets on that dataframe
    changeset = get_changesets(df)

    # assert we are adding a group
    add_accession = [
        ch_a["object_kwargs"]["Accession"] for ch_a in changeset["groups"]
        if ch_a["action"] == "add"
    ]
    assert accession in add_accession

    # assert we are removing the animal
    del_accession = [
        ch_a["object_kwargs"]["accession_number"]
        for ch_a in changeset["animals"] if ch_a["action"] == "del"
    ]
    assert accession in del_accession