def test_add_contribution(): donors = mro.DonorCollection() donors.add_contribution("Funky", [25.0, 50.0]) donors.add_contribution("Gordian", [30.0, 45.0]) assert sum(donors.donor_db["Funky"]) == 75.0 assert donors.donor_db["Funky"] == [25.0, 50.0] assert sum(donors.donor_db["Gordian"]) == 75.0
def test_update_donor(): ''' Verifies a donation amount is added to donor_collection if method update donor called ''' donor = mail.Donor('Bill Gates', 500) donor_collection = mail.DonorCollection() donor_collection.update_donor(donor) assert 500 in donor_collection.donor_dict.get('Bill Gates')
def test_add_donor(): ''' Verifies a new donor can be added to donor_collection if method update add_donor called ''' donor = mail.Donor('Jimi Hendrix', 1000) donor_collection = mail.DonorCollection() donor_collection.add_donor(donor) assert 'Jimi Hendrix' in donor_collection.donor_dict assert 1000 in donor_collection.donor_dict.get('Jimi Hendrix')
def test_create_report(): dc = m.DonorCollection(d1, d2, d3, d4) result = dc.create_report() expected = """ Donor Name | Total Given | Num Gift | Average Gift ------------------------------------------------------------ William Gates, III $ 103807.74 2 $ 51903.87 Jeff Bezos $ 71692.12 3 $ 23897.37 Mark Zuckerberg $ 60052.25 3 $ 20017.42 Paul Allen $ 46872.02 1 $ 46872.02 """ try: assert result == expected except AssertionError: print('Check if the result is correct')
def test_sort_donors(): ''' Verifies the sorting method works to sort donor_collections by total donated ''' donor_dict = { "Bill Gates": [539000, 235642], "Jeff Bezos": [108356, 204295, 897345], "Satya Nadella": [236000, 305352], "Mark Zuckerberg": [153956.35], "Mark Cuban": [459035, 369.50, 570.89] } donor_collection = mail.DonorCollection() sorted_donors = donor_collection.sort_donors() assert sorted_donors[0][0] == "Jeff Bezos" assert sorted_donors[1][0] == "Bill Gates" assert sorted_donors[2][0] == "Satya Nadella" assert sorted_donors[3][0] == "Mark Cuban" assert sorted_donors[4][0] == "Mark Zuckerberg"
print(f"Not allowed to write to '{new_dir}'.") except OSError: print(f"Specified folder '{new_dir}' is not valid.") if __name__ == '__main__': # Initial donor list and the amounts they have donated donor_history = { 'Red Herring': [65820.5, 31126.37, 15000, 2500], 'Papa Smurf': [210.64, 1000, 57.86, 2804.83, 351.22, 48], 'Pat Panda': [55324.4, 35570.53, 14920.50], 'Karl-Heinz Berthold': [3545.2, 10579.31], 'Mama Murphy': [156316.99, 8500.3, 12054.33, 600, 785.20], 'Daphne Dastardly': [82] } coll = mailroom_oo.DonorCollection() for name, amts in donor_history.items(): for amt in amts: coll.add(name, amt) # coll.print_donors() # coll.create_report() # for k, v in coll.donors.items(): # print(v.form_letter) # coll.save_letters() dui = DonorUI(coll) dui.manage_donors() del coll, dui, mailroom_oo
def test_adding_a_new_donor(): dc = m.DonorCollection(d1, d2, d3, d4) dc.add_donation("Bob", [3333.33]) assert dc.donors.get("Bob") assert dc.donors.get("Bob").donations == [3333.33]
def test_donor_collection(): dc = m.DonorCollection(d1, d2, d3, d4) assert dc.donors[d1.name].donations == [54842.49, 48965.25] assert dc.donors[d2.name].total == sum(database['Mark Zuckerberg'])