def test_donor_init(): '''Instantiate donors''' with pytest.raises(AttributeError): d = Donor() with pytest.raises(TypeError): d = Donor(15) d = Donor("Morgan Stanley")
def test_donor_validation(): DC = Donor_Collect() JDR = Donor("Jonny D. Rose") DC.append(JDR) Jinny_D_Rose = Donor("Jinny D. Rose") EJ = Donor("Elton John") assert DC.donor_validation(Jinny_D_Rose) == True assert DC.donor_validation(EJ) == False
def test_thankyou_note(): M_S = Donor("Morgan Stanley") M_S.donations = [10] M_S.append(7.50) assert M_S.thank_you( ) == "Thanks Morgan Stanley for your $17.50 in donations."
def test_thankyou_email(): '''Test email text''' M_S = Donor("Morgan Stanley") M_S.donations = [10] M_S.append(7.5) assert M_S.email().startswith("Greetings Morgan Stanley") assert M_S.email().endswith("(DZCAWCRG)\n")
def test_init_donation(): '''Creating first donation''' Paul = Donor('Paul') Paul.donations = [15] assert Paul.donations == [15] Paul.append([16, 17]) assert Paul.donations == [15, 16, 17]
def test_print_report(): '''Confirm list sorting before printing''' dc = Donor_Collect() JDR = Donor('John D. Rockefeller') JDR.donations = [1500] dc.append(JDR) EJ = Donor('Elton John') EJ.donations = [1600] dc.append(EJ) temp_list = dc.print_report() assert isinstance(temp_list, list) assert isinstance(temp_list[0], tuple) assert temp_list[0][0] == str(EJ) assert temp_list[1][0] == str(JDR)
def test_sum_gift(): DC = Donor_Collect() WG = Donor('Bill Gates') WG.donations = [15] WG.append([16, 17]) DC.append(WG) new_dict = DC.calc_report() print(new_dict) assert isinstance(new_dict, dict) assert new_dict[repr(WG)] is not None assert new_dict[repr(WG)][0] == 48.0 assert new_dict[repr(WG)][1] == 3 assert new_dict[repr(WG)][2] == 16.0
def test_col_append(): ''''Testing if Donor appends to Donor_Collection''' dc = Donor_Collect() JDR = Donor('John D. Rockefeller') dc.append(JDR) ans = False for i in dc.donors: if i == JDR: ans = True assert ans with pytest.raises(AttributeError): dc.append('False Item')
def test_initials(): JDR = Donor('John David Rosen') assert JDR.initials == 'JDR'
def test_don_repr(a, b): '''Donor class repr''' a = Donor(b) assert repr(a) == b
def test_don_str(a, b): '''Donor class string''' a = Donor(b) assert str(a) == b
def receiver(): '''For processing user interface for creating a single thank you''' viable_ans = False while viable_ans == False: new_vs_ex = input("Donor Name, List, Quit? ") name = new_vs_ex if new_vs_ex.lower() == "quit": name = "quit" viable_ans = True break elif new_vs_ex.lower() == "list": don_col.print_don_list() don_num = int(input("Select # above: ")) try: name = don_col.donors[don_num-1] except IndexError: print("Must select a value from the list!") name = "quit" if new_vs_ex.lower() != "quit": donation_value = input("What is the value of the donation? ") if donation_value.lower() == "quit": name = "quit" viable_ans = True elif isinstance(donation_value, float): viable_ans = True elif float(donation_value) <= 0: print("All donations must be greater than 0") name = "quit" viable_ans = False if name in don_col.donors: try: name.append(float(donation_value)) viable_ans = True except ValueError: print("Donation must be whole number or decimal value") name = "quit" elif don_col.donor_validation(name): confirmation = input("Confirm donor name:") if confirmation == name: name = Donor(name) name.append(float(donation_value)) don_col.append(name) viable_ans = True else: print("Names not the same please restart") name = "quit" elif name != "quit": name = Donor(name) name.append(float(donation_value)) don_col.append(name) viable_ans = True if name != "quit": try: print("\n" + name.thank_you() + "\n") except AttributeError: name = "quit" return name
#!/usr/bin/env python3 import io import math from Donor_Models import Donor, Donor_Collect '''Initial setup''' don_col = Donor_Collect() MS = Donor("Morgan Stanley") CV = Donor("Cornelius Vanderbilt") JDR = Donor("John D. Rockefeller") SG = Donor("Stephen Girard") AC = Donor("Andrew Carnegie") don_col.append(MS) don_col.append(CV) don_col.append(JDR) don_col.append(SG) don_col.append(AC) MS.append([0.01, 20.00]) CV.append([800, 15, 10.00]) JDR.append([7000, 150.00, 25]) SG.append([60000]) AC.append([0.04, 999.99]) def receiver(): '''For processing user interface for creating a single thank you''' viable_ans = False while viable_ans == False: new_vs_ex = input("Donor Name, List, Quit? ")