def test_donor_object(self): donator = d.Donor('Alan', 3, 4, 5) self.assertEqual(donator.donor, 'Alan') self.assertEqual(donator.donations, (3, 4, 5)) donator2 = d.Donor('Bob') self.assertEqual(donator2.donor, 'Bob') self.assertEqual(donator2.donations, ())
def test_add_donor(self): donator = d.Donor('Alan', 3, 4, 5) donator2 = d.Donor('Bob', 6, 7, 8) collection = d.DonorCollection(donator, donator2) collection.add_donor('Charlie') donator3 = collection.get_donor('Charlie') self.assertIn(donator3, collection.donors)
def test_donor_object(self): donator = d.Donor('Alan', 3, 4, 5) donator2 = d.Donor('Bob', 6, 7, 8) donator3 = d.Donor('Charlie', 9, 10, 11) collection = d.DonorCollection(donator, donator2, donator3) self.assertIn(donator, collection.donors) self.assertIn(donator2, collection.donors) self.assertIn(donator3, collection.donors)
def test_write_donors(self): donator = d.Donor('Alan', 3, 4, 5) donator2 = d.Donor('Bob', 6, 7, 8) donator3 = d.Donor('Charlie', 9, 10, 11) collection = d.DonorCollection(donator, donator2, donator3) collection.write_donors() assert os.path.isfile('Alan.txt') assert os.path.isfile('Bob.txt') assert os.path.isfile('Charlie.txt')
def test_lt(self): donator = d.Donor('Alan', 3, 4, 5) donator2 = d.Donor('Bob', 6, 7, 8) self.assertTrue(donator < donator2) self.assertFalse(donator > donator2) don_list = [donator, donator2] don_list.sort(reverse=True) self.assertEqual(don_list[0].donor, 'Bob') self.assertEqual(don_list[1].donor, 'Alan')
def initialize_donor_dict(): d1 = dm.Donor('Jeff Bezos') d2 = dm.Donor('William Gates, III') d3 = dm.Donor('Paul Allen') d4 = dm.Donor('Mark Zuckerberg') d1.add_donation(1000, 400) d2.add_donation(100, 90) d3.add_donation(556, 4.9) d4.add_donation(1010, 400.9, 99900) my_donors.add_donors(d1, d2, d3, d4)
def test_donorcollection_class(): """Verify basic operations of the donation class""" donors = dm.DonorCollection() donors.add(dm.Donor('Joe Nunnelley', [20, 40])) donors.add(dm.Donor('Mary Margaret', [30, 50])) assert donors.get_donor('Joe Nunnelley').name == 'Joe Nunnelley' assert len(donors.get_donor('Mary Margaret').donations) == 2 donors.delete('Joe Nunnelley') assert len(donors.donors) == 1 assert donors.get_donor('Mary Margaret').name == 'Mary Margaret'
def initialize_donors(): """Add preset entries into the donor log.""" d1, d2 = dm.Donor('George Washington'), dm.Donor('Abraham Lincoln') d3 = dm.Donor('James Madison') d4, d5 = dm.Donor('Theodore Roosevelt'), dm.Donor('Dwight Eisenhower') d1.add_donation(1789.0, 1.0, 1797.0) d2.add_donation(1861.0, 16.0) d3.add_donation(1809.0, 4.0) d4.add_donation(1901.0, 26.0, 60.0) d5.add_donation(1953.00, 34.0) don_list.add_donor(d1, d2, d3, d4, d5)
def initial(): """initializes the dataset""" d1 = dm.Donor('Karen') d2 = dm.Donor('Susan') d3 = dm.Donor('Larry') d4 = dm.Donor('Curly') d5 = dm.Donor('Mo') d1.add_donation(20, 20, 100) d2.add_donation(20) d3.add_donation(40, 50) d4.add_donation(20.99, 20, 100) d5.add_donation(2) _dc.add_donors(d1, d2, d3, d4, d5)
def initial(): """initializes the dataset""" d_1 = dm.Donor('Karen') d_2 = dm.Donor('Susan') d_3 = dm.Donor('Larry') d_4 = dm.Donor('Curly') d_5 = dm.Donor('Mo') d_1.add_donation(20, 20, 100) d_2.add_donation(20) d_3.add_donation(40, 50) d_4.add_donation(20.99, 20, 100) d_5.add_donation(2) _DC.add_donors(d_1, d_2, d_3, d_4, d_5)
def test_report(self): donator = d.Donor('Alan', 3, 4, 5) donator2 = d.Donor('Bob', 6, 7, 8) donator3 = d.Donor('Charlie', 9, 10, 11) collection = d.DonorCollection(donator, donator2, donator3) self.assertEqual( collection.report, '\n' + '{:20}'.format('Donor Name') + ' ' + 'Total Given' + ' ' + 'Num Gifts' + ' ' + 'Average Gift' + '\n' + '\n' '{:20}'.format('Charlie') + ' $' + '{:11.2f}'.format(30) + ' ' + '{:9.0f}'.format(3) + ' $' + '{:12.2f}'.format(10) + '\n' '{:20}'.format('Bob') + ' $' + '{:11.2f}'.format(21) + ' ' + '{:9.0f}'.format(3) + ' $' + '{:12.2f}'.format(7) + '\n' '{:20}'.format('Alan') + ' $' + '{:11.2f}'.format(12) + ' ' + '{:9.0f}'.format(3) + ' $' + '{:12.2f}'.format(4) + '\n')
def test_add_donation(): """ Test adding a donation to a donor """ value = 500.0 mydonor = dm.Donor("Vicky", "Kego",value) mydonor.add_donation(500.0) assert sum(mydonor.donations) == 1000 assert len(mydonor.donations) == 2
def choice_add_donor(donors, input_name): """ function receives the value of the new donor's name, and requests that donation values values be added for that donor and calls the add donations function input variable name is the new donor to be added return none """ print("The donor you entered was not on the list") while True: choice = input("Would you like to add a new donor?(y/exit)") if choice.lower() == 'exit': quit_it() elif choice.lower() == 'y': break else: print('You entered an invalid value') continue list_or_not = 'n' this_donor = donor_models.Donor(input_name) donors.add_donor(this_donor) print('You will need to add donations for ' + input_name.title() + ' by entering the values as requested: ') list_or_not = 'n' return choice_add_donation(this_donor, list_or_not)
def test_email_text(): donor = donor_models.Donor("Bill Gates", 100) email_text_1 = donor.compose_email() print(email_text_1) exemplar_text_1 = "\nDear Bill Gates,\n Thank you for your generous\ gift of $100.00! It will help Local Charity achieve our mission.\n\ Best regards,\n\ Local Charity\n\n" assert email_text_1 == exemplar_text_1 donor.add_donations(200) email_text_2 = donor.compose_email() exemplar_text_2 = "\nDear Bill Gates,\n Thank you for your generous\ gift of $200.00! It will help Local Charity achieve our mission.\n\ Best regards,\n\ Local Charity\n\n" assert email_text_2 == exemplar_text_2 email_text_3 = donor.compose_email(0) # check non-default email exemplar_text_3 = "\nDear Bill Gates,\n Thank you for your generous\ gift of $100.00! It will help Local Charity achieve our mission.\n\ Best regards,\n\ Local Charity\n\n" assert email_text_3 == exemplar_text_3
def send_all_thank_you(): dc = dm.DonorCollection() for i in dc.donor_db: full_name = i[0] last_donation = i[1][-1] d = dm.Donor(full_name, last_donation) d.generate_letter()
def send_a_thank_you(): full_name = user_input_name() donation_amount = user_input_amount() dc = dm.DonorCollection() dc.update_donor_db(full_name.upper(), donation_amount) d = dm.Donor(full_name, donation_amount) d.generate_letter()
def test_add_donors(): """ Test the adding of a donor to the donor collection """ dc = create_data() value = 745.0 mydonor = dm.Donor("Bera", "Youkul",value) dc.add_donor(mydonor) assert len(dc.donors) == 3
def test_get_donor(self): donator = d.Donor('Alan', 3, 4, 5) donator2 = d.Donor('Bob', 6, 7, 8) donator3 = d.Donor('Charlie', 9, 10, 11) collection = d.DonorCollection(donator, donator2, donator3) returned_donor2 = collection.get_donor('Alan') self.assertEqual(returned_donor2.donor, 'Alan') returned_donor = collection.get_donor('Bob') self.assertEqual(returned_donor.donor, 'Bob') self.assertEqual(returned_donor.donations, (6, 7, 8)) returned_donor3 = collection.get_donor('Charlie') self.assertEqual(returned_donor3.donor, 'Charlie') with pytest.raises(IndexError): collection.get_donor('abc') with pytest.raises(IndexError): collection.get_donor('')
def test_modify_donor(): """ Test modifing of a donor """ value = 745.0 mydonor = dm.Donor("Vicky", "Kego",value) mydonor.fname = "Vicki" mydonor.lname = "Fannin" assert mydonor.fullname == "Vicki Fannin"
def send_thankyou(): name = input("Enter Donors Full name <First> <Last>") while name.lower() == "list": print_donors() name = input("Enter Donors Full name <First> <Last>") else: if dc.search_fullname(name): while True: try: response_amount = float(input("Enter a dollar amount")) #add donation to select user dc.add_donation(name, response_amount) #compose the email and print to terminal print(create_email(name, response_amount)) except ValueError: print("Not a valid donation amount") else: createuser = input( "The Person was not found create Donor? Y(es) or N(o)") if createuser.lower() == "y": while True: try: # add user to list #add_donor(name) response_amount = float(input("Enter a dollar amount")) # add donation to select user nameparts = name.split() newdonor = dm.Donor(nameparts[0], nameparts[1], response_amount) dc.add_donor(newdonor) #compose email and print to terninal print(create_email(name, response_amount)) except ValueError: print("Not a valid donation amount")
def test_file_creation(): '''Tests the create_letter function in the Donor class''' don = dm.Donor('File Flisby', [400.00, 800.00, 1200.00]) don.create_letter() testpth = pathlib.Path('./') testdest = testpth.absolute() / 'File_Flisby.txt' assert os.path.isfile(testdest) is True
def test_add_donor(): donor = donor_models.Donor("Bill Gates") assert donor.name == "Bill Gates" assert donor.total_donations == 0 assert donor.number_of_donations == 0 assert donor.average_gift == 0.0
def check_donor(name): for i, x in enumerate(don_list.list_donors): if x.name == name: return don_list.list_donors[i] else: donor_new = dm.Donor(name) don_list.add_donor(donor_new) return donor_new
def test_create_donor(): """ Test the creation of a donor """ value = 745.0 mydonor = dm.Donor("Calvin", "Fannin",value) assert mydonor.fullname == "Calvin Fannin" assert mydonor.fname == "Calvin" assert mydonor.lname == "Fannin" assert sum(mydonor.donations) == 745.0
def add_donor(donor_name): """Add a donor to the donor collection""" print('{} not found in donor list.'.format(donor_name)) response = input('Add as a donor (y | n)? ') if response.lower() == 'y': return d.Donor(donor_name, add_donations()) else: return None
def test_write_donor(self): donator = d.Donor('Alan', 3, 4, 5) self.assertEqual( donator.donor_text, 'Dear {},\n\n Thank you for your generous donation of ${:.2f}! \n It will be put to very good use. \n\nSincerely, \nThe Team\n' .format('Alan', 5)) donator.write_donor() assert os.path.isfile('Alan.txt')
def test_donor_add_donation(self): donator = d.Donor('Alan', 3, 4, 5) donator.add_donation(6) self.assertEqual(donator.donations, (3, 4, 5, 6)) with pytest.raises(ValueError): donator.add_donation('abc') with pytest.raises(ValueError): donator.add_donation(-5)
def donor_check(r_1): """checks if its an existing donor or new""" the_donor = _DC.find_donor(r_1) if the_donor is None: donor_new = dm.Donor(r_1) _DC.add_donors(donor_new) return donor_new else: return the_donor
def donor_check(r1): """revisit and recode this""" for i, x in enumerate(_dc.list_donors): if x.name == r1: return _dc.list_donors[i] else: donor_new = dm.Donor(r1) _dc.add_donors(donor_new) return donor_new
def check_donor_list_names(name): """Goes through each name in my_dpnors to see if the donor has a history""" for i, x in enumerate(my_donors.list_donors): if x.name == name: return my_donors.list_donors[i] else: donor_new = dm.Donor(name) my_donors.add_donors(donor_new) return donor_new