def test_donor_init(): """ Test the initialization of the Donor Class """ donor = Donor() assert isinstance(donor, Donor) donor.fname = 'Erick' assert donor.fname == 'Erick' donor.lname = 'Smith' assert donor.lname == 'Smith'
def test_thank_you(): """ Test thank_you function, in Donor class that sends thank you email to donor for donation """ donor = Donor() donor.fname = 'Erick' donor.lname = 'Smith' amount = 100 donor.add_donation(amount) email = donor.thank_you_email() assert email == f"Thank you {donor.fname} {donor.lname} for your generous donation of ${amount:.2f} dollars"
def test_search(): """ Test the searching of a donor in the DonorDb class, search() method """ db = DonorDb() donor = Donor() donor.fname = 'Bill' donor.lname = 'Gates' isFound = db.search(donor) assert isFound is not None assert isinstance(isFound, Donor)
def test_add_donor(): """ Test the adding of a donor object to the DonorDb, via the add_donor() method in the DonorDb class """ donor = Donor() donor.fname = 'Erick' donor.lname = 'Smith' donor.add_donation(100) db = DonorDb() db.add_donor(donor) key = donor.fname + ' ' + donor.lname assert key in db.database
def add_db_sample(self): """ Function adds sample data to the database. This is meant to be called by __init__ in order to simplify testing """ data = [('William', 'Gates', [50000.0, 500.12]), ('Mark', 'Zuckerberg', [20000.0, 8500.99]), ('Jeff', 'Bezos', [100000.0, 40000.0, 700.99]), ('Paul', 'Allen', [200000.0, 1440.0, 300.00]), ('Bill', 'Gates', [30000.0, 70000.0, 450.0])] for info in data: donor = Donor() donor.fname = info[0] donor.lname = info[1] key = donor.fname + ' ' + donor.lname donor.donation_history.extend(info[2]) self.database[key] = donor
def test_letter(): """ Test the a single formatted letter to an individual donor, in the Donor class, letter() method. """ donor = Donor() donor.fname = 'Erick' donor.lname = 'Smith' donor.add_donation(100) expected_template = f"""Dear {donor.fname + ' ' + donor.lname}, Thank you for your kind donation of ${donor.donation_history[-1]}. It will be put to very good use. Sincerely, - The Cloud Squad""" assert expected_template == donor.letter()