def test_tot_donation():
    d1 = Donor("Ricky", [9, 9, 9])
    assert d1.tot_donation == 27
    d2 = Donor("zzzz", [1, 2])
    assert d2.tot_donation == 3
    d3 = Donor("nothing", [])
    assert d3.tot_donation == 0
def test_add_donor():
    db = DonorCollection()
    db.add_donor(Donor("Rick", [9, 9, 9]))
    assert db.donors["rick"].donations == [9, 9, 9]
    db.add_donor(Donor("Bob", [1, 2, 3]))
    assert db.donors["bob"].donations == [1, 2, 3]
    assert db.donors["rick"].donations == [9, 9, 9]
def test_count_donation():
    d1 = Donor("Ricky", [9, 9, 9])
    assert d1.num_donations == 3
    d2 = Donor("zzzz", [1, 2])
    assert d2.num_donations == 2
    d3 = Donor("nothing", [])
    assert d3.num_donations == 0
def test_load_donations():
    d1 = Donor("Fred", [500])
    assert d1.donations == [500]
    d2 = Donor("Mike", [500, 1000])
    assert d2.donations == [500, 1000]
    d3 = Donor("Smith", ["candy"])
    assert d3.donations == []
    assert d3.load_error == ["candy"]
    d4 = Donor("Santa", [1000, "candy"])
    assert d4.donations == [1000]
    assert d4.load_error == ["candy"]
def thank_you():
    user_donor = input(
        "Enter full name of donor else type 'list' to see donor list: ")
    if requested_list(user_donor):
        print_donor_list()
        return
    elif not db.donor_present(user_donor):
        user_answer = input("Donor not found. Is this a new donor? (y/n): ")
        if user_answer[0].lower() == "y":
            db.add_donor(Donor(user_donor))
        else:
            return
    else:
        print("Donation again :)")
    user_donation = -1
    while not valid_donation(user_donation):
        print("Must be a positive integer")
        try:
            user_donation = int(input("Enter donation amount: "))
        except ValueError:
            user_donation = -1
    db.donors[standardize_name(user_donor)].add_donation(user_donation)
    print_thank_you(db.donors[standardize_name(user_donor)].name,
                    user_donation)
from donors_models import Donor, DonorCollection, standardize_name, valid_donation
import sys, os
""" Initialize data"""
db = DonorCollection([
    Donor("Fred Flintstone", [100, 200, 50]),
    Donor("James Bond", [0, 0, 7]),
    Donor("Lex Luthor", [
        5000,
    ]),
    Donor("Harambe", [3, 2, 1]),
    Donor("Herman Cain", [9, 9, 9]),
    Donor("Placeholder Guy")
])


def requested_list(userEntry):
    return (userEntry.lower() == 'list') or (userEntry.lower() == 'l')


def print_donor_list():
    print()
    print("Donor List")
    print("----------")
    [print(name) for name in db.name_list]
    print()


def print_thank_you(donor, donation):
    print(
        "Thank you {} for your generous donation of ${} from a charity".format(
            donor, donation))
def test_load_db():
    db = DonorCollection([Donor("Rick", [9, 9, 9]), Donor("Bob", [1, 2, 3])])
    assert db.donors["bob"].donations == [1, 2, 3]
    assert db.donors["rick"].donations == [9, 9, 9]
def test_ave_donation():
    d1 = Donor("Rick", [9, 9, 9])
    assert d1.donations == [9, 9, 9]
    assert d1.ave_donation == 9
    d2 = Donor("zzzz", [1, 2, 3])
    assert d2.ave_donation == 2
def test_add_donation():
    d1 = Donor("Fred")
    d1.add_donation(5)
    d1.add_donation(10)
    assert d1.donations == [5, 10]
def test_donor_name_whitespace():
    d1 = Donor("Jake    ")
    assert d1.name == "Jake"
def test_make_donor():
    d1 = Donor("Fred")
    assert d1.name == "Fred"
def test_stats_sort():
    db = DonorCollection([Donor("Other", [1, 3]), Donor("Rick", [9, 9, 9])])
    assert db.stats_sorted == [("Rick", 27, 3, 9), ("Other", 4, 2, 2)]
def test_name_list():
    db = DonorCollection([Donor("Rick", [9, 9, 9])])
    assert db.name_list == ["Rick"]
    db = DonorCollection([Donor("Rick", [9, 9, 9]), Donor("Other", [1, 3])])
    assert db.name_list == ["Rick", "Other"]
def test_donor_present():
    db = DonorCollection([Donor("Rick", [9, 9, 9]), Donor("Bob", [1, 2, 3])])
    assert db.donor_present("Rick")
    assert db.donor_present("boB")
    assert not db.donor_present("Carlos")