def test_7(capfd): d = mc.Donor() new_donation1 = 107.0 new_donation1 = 107.0 new_donor = "test_donor7".title() d.add_donation(new_donor, new_donation1) donors = mc.Donors() summed_donor_list = donors.sum_donors() tmp_donor_list = sorted(summed_donor_list, key=lambda x: x[1], reverse=True) print("{name:<40}{total_donation:<20}{donation_cnt:<30}{ave_donation:}". format(name=mc.Mailroom.esteemed_donors_headers[0], total_donation=mc.Mailroom.esteemed_donors_headers[1], donation_cnt=mc.Mailroom.esteemed_donors_headers[2], ave_donation=mc.Mailroom.esteemed_donors_headers[3])) tmp_donor_list = sorted(summed_donor_list, key=lambda x: x[1], reverse=True) [ print( "{name:<40}{total_donation:<20}{donation_cnt:<30}{ave_donation:}". format(name=row[0], total_donation=row[1], donation_cnt=row[2], ave_donation=row[3])) for row in tmp_donor_list ] out, err = capfd.readouterr() if "test_donor7 214.0 2 107.0": test_string = "success" assert test_string == "success"
def thank_you(): """Function to send a thank you letter.""" while True: input_name = input("Enter full name: ") if input_name in donor_set.data.keys(): while True: try: donation = float(input("Enter donation amount:")) except ValueError: print("Donation needs to be a number.") else: break donor_set.add_donation(input_name, donation) #ddonors[input_name].append(donation) print(donor_set.write_letter(input_name, donation)) break elif input_name == 'list': donor_set.display_list() else: print("Adding {} to donor database".format(input_name)) while True: try: donation = float(input("Enter donation amount:")) except ValueError: print("Donation needs to be a number.") else: break new_guy = mc.Donor(input_name, [donation]) donor_set.new_donor(new_guy) print(donor_set.write_letter(input_name, donation)) #print(ddonors) break
def test_5(): d = mc.Donor() ls_cnt_before = len(list(mc.Mailroom.esteemed_donors_dict.keys())) new_donation = 105.0 new_donor = "test_donor5".title() d.add_donation(new_donor, new_donation) ls_cnt_after = len(list(mc.Mailroom.esteemed_donors_dict.keys())) assert ls_cnt_before + 1 == ls_cnt_after
def test_thank_you_new_donor(): AR = mc.Donor("Alexander Rossi", [1]) donor_set.new_donor(AR) assert donor_set.data == { 'James Hinchcliffe': [12.2, 2.51, 3.2, 42.0], 'Robert Wickens': [1024.14, 22.21, 323.45], 'Sam Schmidt': [3.2, 5.55, 4.2], 'Alexander Rossi': [1] }
def test_9(capfd): d = mc.Donor() new_donor = "test_donor9".title() d.donor_name = new_donor print(d.donor_name) out, err = capfd.readouterr() if new_donor in out: test_string = "success" assert test_string == "success"
def test_5(): d = mc.Donor() new_donation1 = 105.0 new_donation2 = 105.0 new_donor = "test_donor5".title() d.add_donation(new_donor, new_donation1) d.add_donation(new_donor, new_donation2) new_donor_total = d.donor_total(new_donor) assert new_donor_total == 210.0
def test_10(capfd): test_string = "" d = mc.Donor() new_donation = [float(110.0)] d.donation_amt = new_donation print(*d.donation_amt) out, err = capfd.readouterr() if "110.0" in out: test_string = "success" assert test_string == "success"
def test_6(): d = mc.Donor() new_donation1 = 106.0 new_donation2 = 106.0 new_donor = "test_donor6".title() d.add_donation(new_donor, new_donation1) d.add_donation(new_donor, new_donation2) ds = mc.Donors() donors_list = ds.sum_donors() search = new_donor for sublist in donors_list: if sublist[0] == search: donor_sum = sublist[1] donation_cnt = sublist[2] donor_ave = sublist[3] break assert donor_sum == 212.0 and donation_cnt == 2 and donor_ave == 106.0
#!/usr/bin/env python3 import mailroom as m import mailroom_classes as mc import pytest import os # Adding this to import preset data. a = mc.Donor("James Hinchcliffe", [12.2, 2.51, 3.20]) b = mc.Donor("Robert Wickens", [1024.14, 22.21, 323.45]) c = mc.Donor("Sam Schmidt", [3.2, 5.55, 4.20]) donor_set = mc.Donors() donor_set.new_donor(a) donor_set.new_donor(b) donor_set.new_donor(c) def test_display_list(capsys): donor_set.display_list() out, err = capsys.readouterr() assert out == "James Hinchcliffe\nRobert Wickens\nSam Schmidt\n" def test_write_letter(): expected = "Dear James,\nThank you for donating $5.00 to the Human Fund. " \ "Your money will be used appropriately." assert donor_set.write_letter("James", 5) == expected def test_write_report(capsys): expected_1 = 'Donor Name | Total Given | Num Gifts | Average Gift\n'