Example #1
0
def test_merge_donations_valid_data():
    test_list = [{
        "name": "John Doe",
        "money": "0.99",
        "id": "*****@*****.**",
        "date": "01/02/03",
        "file_name": "a"
    }, {
        "name": "Jane Doe",
        "money": "9.01",
        "id": "*****@*****.**",
        "date": "04/05/06",
        "file_name": "b"
    }, {
        "name": "Doe Ray Mi",
        "money": "15.000",
        "id": "*****@*****.**",
        "date": "04/02/04",
        "file_name": "c"
    }, {
        "name": "Jake Doe",
        "money": "199.99",
        "id": "*****@*****.**",
        "date": "01/02/03",
        "file_name": "d"
    }, {
        "name": "Jimme Dough",
        "money": "1000.00",
        "id": "*****@*****.**",
        "date": "01/02/03",
        "file_name": "e"
    }]

    results = raffle_program.merge_donations(test_list, "id", "money", "date")

    assert len(results) == 4
    assert results[1]["money"] == 208
    assert results[3]["money"] == 1000
    assert "04/05/06" in results[1]["date"]
    assert "01/02/03" in results[1]["date"]
    assert "b" in results[1]["file_name"]
    assert "d" in results[1]["file_name"]
Example #2
0
def test_merge_donations_invalid_money_data():
    test_list = [{
        "name": "John Doe",
        "money": "0.99",
        "id": "*****@*****.**",
        "date": "01/02/03",
        "file_name": "a"
    }, {
        "name": "Jane Doe",
        "money": "9.O1",
        "id": "*****@*****.**",
        "date": "04/05/06",
        "file_name": "b"
    }, {
        "name": "Doe Ray Mi",
        "money": "15.000",
        "id": "*****@*****.**",
        "date": "04/02/04",
        "file_name": "c"
    }, {
        "name": "Jake Doe",
        "money": "199.99",
        "id": "*****@*****.**",
        "date": "01/02/03",
        "file_name": "d"
    }, {
        "name": "Jimme Dough",
        "money": "1000.O0",
        "id": "*****@*****.**",
        "date": "01/02/03",
        "file_name": "e"
    }]

    results = raffle_program.merge_donations(test_list, "id", "money", "date")

    assert results[2]["money"] == 199
    assert "*****@*****.**" not in [x["id"] for x in results]
Example #3
0
def test_merge_donations_invalid_date_header():
    with pytest.raises(TypeError) as e:
        raffle_program.merge_donations(["non", "empty", "list"], "id",
                                       "contrib", 10)

    assert str(e.value) == "All headers must be strings"
Example #4
0
def test_merge_donations_invalid_csv_data():
    with pytest.raises(TypeError) as e:
        raffle_program.merge_donations("bad_input", "id", "contrib", "date")

    assert str(e.value) == "`csv_data` must be a list"