def test_find_donor(self): dc = DonorCollection() dc.add_donor("first") dc.add_donor("second") assert dc.find_donor("first").name == "first" assert dc.find_donor("second").name == "second" assert not dc.find_donor("noSuchDonor")
def test_donor_collection_create_report(): ''' Tests creating the report for the given donors :return: nothing ''' expected_donor_1 = "Jinee" d_jinee = Donor(expected_donor_1) d_jinee.add_donation(100.00) expected_donor_2 = "Brother" d_brother = Donor("Brother") d_brother.add_donation(200.00) expected_donor_3 = "Mom" d_mom = Donor(expected_donor_3) d_mom.add_donation(300.00) dc = DonorCollection() dc.add_donor(d_jinee, d_brother, d_mom) report = dc.create_report() assert (expected_donor_1 in report) assert (expected_donor_2 in report) assert (expected_donor_3 in report)
def test_get_donor(): dc = DonorCollection() dc.add_donor("Rei", [50]) a = dc.get_donor("Rei") assert a.name == "Rei" assert a.donations == [50] assert dc.get_donor("Usagi") is False
def setup_DonorCollection(): donors = DonorCollection() donors.add_donor(Donor("Fred Jones", [100, 200, 300])) donors.add_donor(Donor("Amy Shumer", [1000, 2000, 3000])) donors.add_donor(Donor("Bill Gates", [200, 400, 750, 400])) donors.add_donor(Donor("John Smith Jr.", [200, 400, 9050.20, 30])) donors.add_donor(Donor("Jeff Bezos", [200, 225.50, 10000, 30])) return donors
def test_donor_collection_list_donors(): dc = DonorCollection() dc.add_donor(Donor("Steve Johnson", [100.00, 200, 400, 300])) dc.add_donor(Donor("Cindy Johnson", [100.00, 200, 400, 300])) dc.add_donor(Donor("Beth Smith", [100.00, 200, 400, 300])) result = list(dc.list_donors()) assert len(result) == 3 assert "Cindy Johnson" in result
def test_donor_collection_duplicates(): dc = DonorCollection() dc.add_donor(Donor("Bob", (123.00, ))) dc.add_donor(Donor("Bob", (456.00, ))) dc.add_donor(Donor("Peter Newhouse Jr.", (7890, ))) assert len(dc) == 2 assert set(dc) == set([Donor("Bob"), Donor("Peter Newhouse Jr.")]) assert dc["Bob"].donations == (123.00, 456.00)
def test_letters_to_all_donors(): dc = DonorCollection() dc.add_donor('first last') dc.add_donor('second name') assert dc.letters_to_all_donors == [ "Dear First Last, we look forward to your first donation!", "Dear Second Name, we look forward to your first donation!" ]
def test_donorcollection_add_existing(): c = DonorCollection(Donor('Homer Simpson', 10.00)) # create a duplicate named donor d = Donor('Homer Simpson', 20.00) # print(c.donors['Homer Simpson'].donations) c.add_donor(d) # print(c.donors['Homer Simpson'].donations) # adding existing donor will add donations to existing donor in database assert c.donors['Homer Simpson'].donations == [10.0, 20.0]
def test_show_donor_list(): donor_collection = DC() donor_collection.add_donor("Jimmy Johns", 100) assert "Jimmy Johns" in donor_collection.show_donor_list assert "Jeff Bezos" in donor_collection.show_donor_list assert "Warren Buffet" in donor_collection.show_donor_list assert "Bill Gates" in donor_collection.show_donor_list assert "Tim Cook" in donor_collection.show_donor_list assert "Jack Ma" in donor_collection.show_donor_list
def test_donors_list(): """testing the donor list function""" donor1 = Donor('Paul Allen') donor_col = DonorCollection() donor_col.add_donor(donor1) donor2 = Donor('Jeff Bezos') donor_col.add_donor(donor2) test_list = donor_col.donor_list() assert 'Paul Allen' in test_list assert 'Jeff Bezos' in test_list
def test_donorcollection_names_sorted(): """Test names_sorted property.""" dc = DonorCollection() dc.add_donor("Test User 1") d = dc.get_donor("Test User 1") for value in [1, 2, 3, 4]: d.add_donation(value) dc.add_donor("Test User 2") d = dc.get_donor("Test User 2") for value in [5, 6, 7, 8]: d.add_donation(value) assert dc.names_sorted == ["Test User 2", "Test User 1"]
def test_donor_collection_add_donor(): ''' Tests the add donor method :return: nothing ''' expected_donor = "Jinee" d = Donor("Jinee") d.add_donation(100.00) dc = DonorCollection() dc.add_donor(d) assert (dc.get_donors()[0].donor_name == expected_donor)
def test_batch_letters(): dc = DonorCollection() dc.add_donor("Rei", [50]) dc.add_donor("Usagi", [50, 150]) dc.batch_letters() assert os.path.isfile("Rei.txt") is True assert os.path.isfile("Usagi.txt") is True with open("Rei.txt", "r") as f: filetext = f.read() assert "Dear Rei," in filetext assert "Thank you for your donation of $50.00." in filetext assert "Your total donations to date are $50.00." in filetext assert "Thanks, the Management." in filetext
def test_add_donor(self): donor1 = Donor("jeff bezos", [200000]) donor2 = Donor("Bill Gates", [150000]) dc = DonorCollection([donor1, donor2]) donor3 = Donor("Steve Jobs", [150000]) dc.add_donor(donor3) assert dc.donor_list == [donor1, donor2, donor3] with pytest.raises(ValueError) as error: dc.add_donor({ 'full_name': 'Jeff Bezos', 'donation_history': 200000 }) assert "invalid type" in error
def test_create_report(): test_data = initialize_donors() dc = DonorCollection() dc.add_donor(*test_data) test_string = ( '\nDonor Name | Total Given | ' 'Num Gifts | Average Gift\n' '--------------------------------------------------------------\n' 'George Washington $ 3,587.00 3 $ 1,195.67\n' 'Theodore Roosevelt $ 1,987.00 3 $ 662.33\n' 'Dwight Eisenhower $ 1,987.00 2 $ 993.50\n' 'Abraham Lincoln $ 1,877.00 2 $ 938.50\n' 'James Madison $ 1,813.00 2 $ 906.50\n') assert dc.create_report() == test_string
def test_add_donor(): """ Verify a new donor can be added to the donor list""" donors = Donors() donor = donors.add_donor("Bob", 125.50) assert donor.name == "Bob" assert donor.donations[0] == 125.50
def test_add_donor(): """ This tests whether donors are added to the dictionary """ d1 = Donor('Marsha Wheeler', 10) d2 = Donor('Andrew Magis', 20) dc = DonorCollection() dc.add_donor(d1) dc.add_donor(d2) print(dc.donor_dict) assert 'Marsha Wheeler' in dc.donor_dict.keys() assert 'Andrew Magis' in dc.donor_dict.keys() assert [10] in dc.donor_dict.values() assert [20] in dc.donor_dict.values()
def test_donor_collection_check_if_donor_present_true(): ''' Tests if the donor is present in the collection :return: nothing ''' expected_donor_1 = "Jinee" d_jinee = Donor(expected_donor_1) d_jinee.add_donation(100.00) expected_donor_2 = "Brother" d_brother = Donor("Brother") d_brother.add_donation(200.00) dc = DonorCollection() dc.add_donor(d_jinee, d_brother) assert (dc.donor_present(expected_donor_1))
def display_thank_you(): #keep doing this until further notice while True: #ask for name or to print list of names donor_name = input(thank_you_prompt) #print out names if donor_name == 'list': print(DonorCollection().list_donors()) #skip loop to reprompt continue #ask for the donation amount donor_amount = input(donation_prompt) #set as a numeric value donor_amount = float(donor_amount) print(Donor(donor_name, donor_amount).send_thank_you()) DonorCollection.add_donor(donor_name, donor_amount) break
def test_add_donor(): d1 = Donor('Nam Vo', [100, 50.0]) d2 = Donor('Vu Vo', [200]) donor_dict = { id(d1): d1, id(d2): d2, } dl = DonorCollection(list(donor_dict.keys())) print(f"dl = {dl}") # Add donation to existing donor index = dl.add_donor('Nam Vo', donor_dict, amount=65.5) assert (dl.donors[index]) == id(d1) print(f"dl = {dl}") # Add new donor obj = dl.add_donor('Paul Allen', donor_dict, amount=100000) donor_dict[id(obj)] = obj assert (dl.donors[2]) == id(obj) print(f"dl = {dl}") print(f"donor_dict = {donor_dict}")
def test_create_report(): donor_collection = DC() donor_collection.add_donor("Jimmy Johns", 50) report = donor_collection.create_report() assert report[ 0] == 'Donor Name | Total Given | Num Gifts | Average Gift' assert report[ 1] == '------------------------------------------------------------------' assert report[ 2] == 'Jack Ma $ 2000.00 1 $ 2000.00' assert report[ 3] == 'Warren Buffet $ 1100.00 2 $ 550.00' assert report[ 4] == 'Bill Gates $ 600.00 2 $ 300.00' assert report[ 5] == 'Tim Cook $ 300.00 1 $ 300.00' assert report[ 6] == 'Jeff Bezos $ 51.00 2 $ 25.50' assert report[ 7] == 'Jimmy Johns $ 50.00 1 $ 50.00'
def test_donor_collection_multiple(): dc = DonorCollection() dc.add_donor(Donor("Bob")) dc.add_donor(Donor("Sean Carrol")) dc.add_donor(Donor("Peter Newhouse Jr.")) assert dc["Bob"] == Donor("Bob") assert dc["Sean Carrol"] == Donor("sean CarrOL") assert dc["Peter Newhouse Jr."] == Donor("Peter NEWhouse Jr.")
def test_generate_report(): dc = DonorCollection() dc.add_donor("Rei", [50]) dc.add_donor("Usagi", [50, 150]) dc.add_donor("Minako") result = dc.generate_report() assert "Donor Name Total Given Num Gifts Average Gift" in result assert "Usagi 200.00 2 100.00" in result assert "Rei 50.00 1 50.00" in result assert "Minako 0.00 0 0.00" in result
def test_add_donor(self): dc = DonorCollection() dc.add_donor("first") assert "first" in dc.donor_data.keys() assert len(dc.donor_data) == 1 dc.add_donor("first") assert "first" in dc.donor_data.keys() assert len(dc.donor_data) == 1 dc.add_donor("second") assert "first" in dc.donor_data.keys() assert "second" in dc.donor_data.keys() assert len(dc.donor_data) == 2
def test_donor_report(): """testing the donor report function""" test_donor = DonorCollection() test_donor.add_donor('Jeff Bezos').add_donations(100.00) test_donor.add_donor('David').add_donations(500.50) test_donor.add_donor('Allen').add_donations(2500.00) report = test_donor.donor_report() assert 'Allen' in report assert '500.50' in report
def test_donor_report(): dc = DonorCollection() dc.add_donor('first last', (1, 2, 3)) dc.add_donor('second name', (4, 5, 6)) assert dc.donor_report == [['First Last', 6, 3, 2], ['Second Name', 15, 3, 5]]
def test_donor_list(): dc = DonorCollection() dc.add_donor('first last') dc.add_donor('second name') assert dc.donor_list == ['First Last', 'Second Name']
def test_add_existing_donor(): dc = DonorCollection() dc.add_donor('first last') with pytest.raises(ValueError): dc.add_donor('first last') assert len(dc.donors) == 1
def test_add_donor(): dc = DonorCollection() dc.add_donor('first last') assert len(dc.donors) == 1
don_col = DonorCollection() donor_letters = DonorLetters() thank_you = ThankYou() main_menu_answers = { '1': thank_you.send_a_thank_you, '2': don_col.generate_report, '3': donor_letters.letters_for_all } if __name__ == "__main__": clear_screen() # This is just to populate the don_col.donors dict with some info to play with for donor, donations in donors.items(): don_col.add_donor(donor, donations[0]) if len(donations) > 1: for donation in donations[1:]: don_col.donors[donor].add_donation(donation) # Continue getting input until user types quit while user_input.lower() != 'quit': user_input = input(("What would you like to do?\n" "1: to Send a Thank You\n" "2: Create a Report\n" "3 to create letters for all donors\n" "quit: to Quit{}").format(input_prompt)) try: main_menu_answers.get(user_input, 'nothing')() except TypeError: