def test_donorcollection_donorList():
    dList = []
    dList.append(Donor('Homer Simpson', 10.00))
    dList.append(Donor('Charles Burns', 1.00))
    c = DonorCollection.donorList(dList)
    assert isinstance(c.donors['Homer Simpson'], Donor)
    assert isinstance(c.donors['Charles Burns'], Donor)
Beispiel #2
0
 def test_ctor(self):
     dc = DonorCollection()
     assert not dc.donor_data
     first_donor = Donor("firstDonor")
     second_donor = Donor("secondDonor")
     dc = DonorCollection([first_donor, second_donor])
     assert {first_donor.norm_name: first_donor, second_donor.norm_name: second_donor} == dc.donor_data
def test_donor_donation():
    donor1 = Donor('A. Tester', [1.23])
    assert len(donor1.donations) == 1
    assert sum(donor1.donations) == 1.23
    donor2 = Donor('B. Developer', [1.23, 2.34])
    assert len(donor2.donations) == 2
    assert sum(donor2.donations) == 3.57
def test_donor_collection_create_report():
    '''
    Tests creating the report for the given donors
    :return: nothing
    '''

    expected_donor_1 = "Jinee"
    d_jinee = Donor(expected_donor_1)
    d_jinee.add_donation(100.00)

    expected_donor_2 = "Brother"
    d_brother = Donor("Brother")
    d_brother.add_donation(200.00)

    expected_donor_3 = "Mom"
    d_mom = Donor(expected_donor_3)
    d_mom.add_donation(300.00)

    dc = DonorCollection()
    dc.add_donor(d_jinee, d_brother, d_mom)

    report = dc.create_report()

    assert (expected_donor_1 in report)
    assert (expected_donor_2 in report)
    assert (expected_donor_3 in report)
Beispiel #5
0
    def test_load_donor_data_from_file(self):

        donor1 = Donor("jeff bezos", [200000])
        donor2 = Donor("Bill Gates", [150000])
        dc = DonorCollection([donor1, donor2])
        msg = "File donors.txt does not exist. The donors record history is currently empty!"

        with mock.patch("builtins.open", mock.mock_open()) as mock_open:
            mock_open.side_effect = FileNotFoundError()
            result = dc.load_donor_data_from_file('donors.txt')
            assert result == msg
            assert dc.donor_list == []
            mock_open.assert_called_with('donors.txt', 'r')

        dc = DonorCollection()
        msg = "Donors records successfully loaded from donors.txt !"
        donor_text = "jeff bezos;30000.0,50000.0\nbill gates;20000.0,80000.0\n"
        mock_open = mock.mock_open(read_data=donor_text)
        with mock.patch("builtins.open", mock_open):
            result = dc.load_donor_data_from_file('donors.txt')
            assert result == msg
            assert dc.donor_list == [
                Donor('bill gates', [20000.0, 80000.0]),
                Donor('jeff bezos', [30000.0, 50000.0])
            ]
            assert dc.donor_list[0] > dc.donor_list[1]
            mock_open.assert_called_with('donors.txt', 'r')
def test_Donor_2():
    d = Donor("Jeff Bezos", 100)
    assert d.Donations == [100]
    d = Donor("Jeff Bezos")
    assert d.Donations == []
    d = Donor("Jeff Bezos", "amazon")
    assert d.Donations == []
def test_donor_append_donations():
    donor = Donor("Steve Johnson", [100.00])
    donor += Donor("Steve Johnson", [123.21, 15.21])
    result = donor.donations
    assert len(result) == 3
    assert 123.21 in result
    assert 15.21 in result
Beispiel #8
0
def main():

    # Initialize list of donors with their names and the amounts they have donated
    donor_objs = [
                    Donor("William Gates, III", [653772.32, 12.17]),
                    Donor("Jeff Bezos", [877.33]),
                    Donor("Paul Allen", [663.23, 43.87, 1.32]),
                    Donor("Mark Zuckerberg", [1663.23, 4300.87, 10432.0]),
                    Donor("Bill Nordstrom", [2013.25, 23456.78]),
                ]
    donor_dict = {}
    for obj in donor_objs:
        donor_dict[id(obj)] = obj

    donor_db = DonorCollection(list(donor_dict.keys()))

    prompt = "\n".join(("\nWelcome to the mail room!",
            "Please choose from below options:",
            "1 - Send a Thank You",
            "2 - Create a Report",
            "3 - quit",
            ">>> "))

    while True:
        response = input(prompt)  # continuously collect user selection
        # now redirect to feature functions based on the user selection
        if response == "1":
            send_thankyou(donor_db, donor_dict)
        elif response == "2":
            create_report(donor_db, donor_dict)
        elif response == "3":
            exit_program()
        else:
            print("Not a valid option!")
def test_donorcollection_repr():
    """Test DonorCollection object __repr__ dunder."""
    donor1 = Donor("Alexander Boone", 500, 2)
    donor2 = Donor("Alexander", 500, 2)
    collection = DonorCollection(donor1, donor2)
    assert repr(collection) == "[Alexander Boone, $500.00, 2, $250.00]" \
                               "\n[Alexander, $500.00, 2, $250.00]"
def test_update_donors_db():
    donor_1 = Donor('Adan', 'William', 100.75)
    donor_1.add_donation_amount(1200)
    donor_1.add_donation_amount(3200.45)
    donor_2 = Donor('Peter', 'Chiykowski', 25.25)
    donor_2.add_donation_amount(4340.25)
    donor_3 = Donor('Sara', 'Gogo', 650)
    my_donor_list = DonorCollection() # the donor data base
    # test adding new donors to the data base
    my_donor_list.update_donors_db(donor_1)
    my_donor_list.update_donors_db(donor_2)
    my_donor_list.update_donors_db(donor_3)
    assert len(my_donor_list.donorList) == 3 # test total number of donors
    assert my_donor_list.donorList[0].first_name == 'Adan'
    assert my_donor_list.donorList[0].last_name == 'William'
    assert my_donor_list.donorList[0].donation[1] == 1200
    assert my_donor_list.donorList[1].first_name == 'Peter'
    assert my_donor_list.donorList[1].last_name == 'Chiykowski'
    assert my_donor_list.donorList[1].donation[1] == 4340.25
    assert my_donor_list.donorList[2].first_name == 'Sara'
    assert my_donor_list.donorList[2].last_name == 'Gogo'
    assert my_donor_list.donorList[2].donation[0] == 650
    # test adding donation to existing donor
    donor_new = Donor('Sara', 'Gogo', 100)
    my_donor_list.update_donors_db(donor_new)
    assert len(my_donor_list.donorList) == 3 # still three donors
    assert my_donor_list.donorList[2].first_name == 'Sara'
    assert my_donor_list.donorList[2].last_name == 'Gogo'
    assert my_donor_list.donorList[2].total_gifts == 2 # total gifts changed
    assert my_donor_list.donorList[2].total_amount == 750 # tot amount changed
Beispiel #11
0
def test_donors_list():
    """ Test all donor names are returned"""
    donor.add(Donor('Noe', [50]))
    donor.add(Donor('David', [500]))
    assert 'Noe' in donor.donors_list()
    assert 'David' in donor.donors_list()
    assert 'Noe\nDavid' in donor.donors_list()
Beispiel #12
0
def test_init_():
    d = Donor("Benny", [2000])
    assert d.name == "Benny"
    assert d.donations == [2000]
    arg = [200, 300, 400, 100]
    d = Donor("Benny Huggins", arg)
    assert d.name == "Benny Huggins"
    assert d.donations == arg
def test_donorcollection_init():
    """Test DonorCollection object initialization."""
    donor1 = Donor("Alexander Boone", 500, 2)
    donor2 = Donor("Alexander", 500, 2)
    collection = DonorCollection(donor1, donor2)
    assert collection.names == ["Alexander Boone", "Alexander"]
    assert collection.donors == [donor1, donor2]
    assert collection.data == [repr(donor1), repr(donor2)]
def test_donor_collection_list_donors():
    dc = DonorCollection()
    dc.add_donor(Donor("Steve Johnson", [100.00, 200, 400, 300]))
    dc.add_donor(Donor("Cindy Johnson", [100.00, 200, 400, 300]))
    dc.add_donor(Donor("Beth Smith", [100.00, 200, 400, 300]))
    result = list(dc.list_donors())
    assert len(result) == 3
    assert "Cindy Johnson" in result
def test_donorcollection_setter():
    d1 = Donor('Nam Vo', [100, 50.0])
    d2 = Donor('Vu Vo', [200])
    dl = DonorCollection()
    dl.donors = [id(d1), id(d2)]
    print(f"dl = {dl}")
    assert (dl.donors[0]) == id(d1)
    assert (dl.donors[1]) == id(d2)
def test_donors_list():
    """ Test all donor names are returned"""

    donor.add(Donor('ABC', [1001.00]))
    donor.add(Donor('Indu', [400.00]))
    assert 'ABC' in donor.donors_list()
    assert 'Indu' in donor.donors_list()
    assert 'ABC\nIndu' in donor.donors_list()
def setup_DonorCollection():
    donors = DonorCollection()
    donors.add_donor(Donor("Fred Jones", [100, 200, 300]))
    donors.add_donor(Donor("Amy Shumer", [1000, 2000, 3000]))
    donors.add_donor(Donor("Bill Gates", [200, 400, 750, 400]))
    donors.add_donor(Donor("John Smith Jr.", [200, 400, 9050.20, 30]))
    donors.add_donor(Donor("Jeff Bezos", [200, 225.50, 10000, 30]))
    return donors
def test_donor_collection_contains():
    dc = setup_DonorCollection()
    name, fake_name = "Bill Gates", "Not A Name"
    donor = Donor(name)
    assert name in dc
    assert donor in dc
    assert fake_name not in dc
    assert Donor(fake_name) not in dc
Beispiel #19
0
def test_init():
    """
    This only tests that it can be initialized with and without some content but it is a start
    """

    d = Donor()

    d = Donor('Marsha Wheeler', 10)
def test_donorcollection_init():
    d1 = Donor('Nam Vo', [100, 50.0])
    d2 = Donor('Vu Vo', [200])
    dl1 = DonorCollection()
    dl2 = DonorCollection([id(d1), id(d2)])
    print(f"DonorCollection's mro: {DonorCollection.__mro__}")
    print(f"dl1 = {dl1}")
    print(f"dl2 = {dl2}")
def test_donor_collection_duplicates():
    dc = DonorCollection()
    dc.add_donor(Donor("Bob", (123.00, )))
    dc.add_donor(Donor("Bob", (456.00, )))
    dc.add_donor(Donor("Peter Newhouse Jr.", (7890, )))
    assert len(dc) == 2
    assert set(dc) == set([Donor("Bob"), Donor("Peter Newhouse Jr.")])
    assert dc["Bob"].donations == (123.00, 456.00)
def test_collection_list_donors():
    donors = DonorCollection()
    donors.add(Donor('A. Tester', [1.23]))
    donors.add(Donor('B. Developer', [4.56]))
    print(donors.list_donors())
    assert 'A. Tester' in donors.list_donors()
    assert 'B. Developer' in donors.list_donors()
    assert 'A. Tester\nB. Developer' in donors.list_donors()
def test_donors_list():
    """ Test all donor names are returned"""

    donor.add(Donor('Mikhail Bulgakov', [800.00]))
    donor.add(Donor('Ivan Turgenev', [400.00]))
    assert 'Mikhail Bulgakov' in donor.list_of_donors()
    assert 'Ivan Turgenev' in donor.list_of_donors()
    assert 'Mikhail Bulgakov\nIvan Turgenev' in donor.list_of_donors()
def test_collection_add():
    donor = Donor('A. Tester', [1.23])
    donors = DonorCollection()
    donors.add(donor)
    assert 'A. Tester' in donors.donors.keys()
    donor2 = Donor('B. Developer', [1.23, 2.34])
    donors.add(donor2)
    assert 'B. Developer' in donors.donors.keys()
def test_donorcollection_str():
    """Test DonorCollection object __str__ dunder."""
    donor1 = Donor("Alexander Boone", 500, 2)
    donor2 = Donor("Alexander", 500, 2)
    collection = DonorCollection(donor1, donor2)
    assert str(collection) == "A collection of data for " \
                              "the following donors:\n\n" \
                              "Alexander Boone" \
                              "\n" + "Alexander"
def test_donorcollection_add_existing():
    c = DonorCollection(Donor('Homer Simpson', 10.00))
    # create a duplicate named donor
    d = Donor('Homer Simpson', 20.00)
    # print(c.donors['Homer Simpson'].donations)
    c.add_donor(d)
    # print(c.donors['Homer Simpson'].donations)
    # adding existing donor will add donations to existing donor in database
    assert c.donors['Homer Simpson'].donations == [10.0, 20.0]
def test_save_letters_disk():
    """check if file is exist"""
    donor1 = Donor('Paul Allen')
    donor2 = Donor('David')
    donor_col = DonorCollection()
    donor_col.save_letters_to_disk()
    donor_col.save_letters_to_disk()
    assert os.path.isfile('Paul_Allen.txt')
    assert os.path.isfile('David.txt')
def test_collection_print_report():
    cur_dir = os.getcwd()
    donors = DonorCollection()
    donors.add(Donor('Test1', [10]))
    donors.add(Donor('Test2', [27]))
    donor_count = len(donors.donors)
    donors.print_report()
    donor_file_count = len([x for x in os.listdir(cur_dir) if x.endswith('.txt')])
    assert donor_file_count == donor_count
Beispiel #29
0
    def test_ctor(self):
        donor = Donor("First Last")
        assert donor.name == "First Last"
        assert donor.donations == []

        donations = [123.123, 456.456]
        donor = Donor("First Last", donations)
        assert donor.name == "First Last"
        assert donor.donations == donations
def test_donors_list():
    """testing the donor list function"""
    donor1 = Donor('Paul Allen')
    donor_col = DonorCollection()
    donor_col.add_donor(donor1)
    donor2 = Donor('Jeff Bezos')    
    donor_col.add_donor(donor2)
    test_list = donor_col.donor_list()
    assert 'Paul Allen' in test_list
    assert 'Jeff Bezos' in test_list