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 test_11(capfd): d = mc.Donors() tmp_directory = "{}/tmp/".format(os.getcwd()) d.tmp_directory = tmp_directory print(d.tmp_directory) out, err = capfd.readouterr() if tmp_directory in out: test_string = "success" assert test_string == "success"
def test_2(): tmp_directory = "{}/tmp/".format(os.getcwd()) clean_directory(tmp_directory) new_donor = "test_donor2".title() new_donation = [float(102.0)] d = mc.Donors() d.donor_name = new_donor d.donation_amt = new_donation d.esteemed_donors_dict[d.donor_name] = d.donation_amt d.print_letters(tmp_directory) if os.path.isfile(tmp_directory + "\\Test_Donor2_Thank_You_Letter.txt"): assert FileExistsError
def test_1(): exists = "" new_donor = "test_donor1".title() new_donation = [float(101.0)] d = mc.Donors() d.donor_name = new_donor d.donation_amt = new_donation d.esteemed_donors_dict[d.donor_name] = [d.donation_amt] for k, v in list(d.esteemed_donors_dict.items()): if k == new_donor and v[0] == new_donation: exists = "yes" assert exists == "yes" del d.esteemed_donors_dict[d.donor_name]
def test_3(): tmp_directory = "{}/tmp/".format(os.getcwd()) clean_directory(tmp_directory) new_donor = "test_donor3".title() new_donation = [float(103.0)] d = mc.Donors() d.donor_name = new_donor d.donation_amt = new_donation d.esteemed_donors_dict[d.donor_name] = d.donation_amt d.print_letters(tmp_directory) hash_file = tmp_directory + "\\Test_Donor3_Thank_You_Letter.txt" hash = hashlib.md5() with open(hash_file, 'rb') as afile: buf = afile.read() hash.update(buf) print(hash.hexdigest()) assert hash.hexdigest() == "84f2d04d5bab6686066121cf05302b52"
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'