def test_thank_all_1(): """Create the correct number of files with the correct tiles.""" donors = DonorCollection.from_dict(sample_donations) thank_all() txt_files = {f for f in os.listdir() if f.endswith('.txt')} expected_files = {donor + ".txt" for donor in donors.list()} assert len(txt_files) >= len(donors.list()) assert expected_files.issubset(txt_files)
def test_thank_all_2(): """Create files with the correct content.""" donors = DonorCollection.from_dict(sample_donations) thank_all() with open("EatPraySlay.txt", 'r') as f: assert f.read() == "To the esteemed EatPraySlay:\n\nThank you for" \ " your generous donation of $300000.00. You're" \ " a champion!"
def test_create_report(): """Ensure donor records are sorted correctly.""" donors = DonorCollection.from_dict(sample_donations) # Create an ordered list of donor sums sum_list = [donor.sum_donations for donor in donors.sorted()] # Ensure each sum is greater or equal to than all subsequent sums for count, value in enumerate(sum_list): for x, y in enumerate(sum_list): assert not (x > count and y > value)
notes and detailed donor reports. """ import sys from donor_models import Donor, DonorCollection # Initial donations initial_donations = { "Rhianna": [747, 3030303, 1968950], "Grumps": [5.99], "EatPraySlay": [100000, 200000, 300000], "Muir": [469503, 50000, 186409], "Spacewalker": [4406, 342] } donors = DonorCollection.from_dict(initial_donations) def get_donor_name(): """Get donor name from user.""" while True: donor_name = input("Who would you like to thank? (Type 'list' " "to see a list of donors.)\n Full Name: ") # Print list of existing donors to choose from if donor_name.lower() == "list": print("\n".join(donors.list())) # Ensure the user has entered a name elif donor_name.replace(" ", "").replace(".", "").replace(",", "").\
import sys from donor_models import Donor from donor_models import DonorCollection donors = DonorCollection.from_dict( {'Sandy Pie': [75], 'Judy Smith': [75, 100, 1000], 'Mike Jones': [75, 1000], 'Joe Smith': [75, 100, 2000], 'Kelly Blue': [75, 150, 275]}) def menu(): """Display user menu and process selections.""" while True: print() print('''Menu: 1. Enter a Donation. 2. Generate Thank You messages. 3. View Donation Report. 4. Quit.''') print() try: response = int(input("Please enter a number to make your selection. "))-1 switch_func_dict = { 0: ask_donor_name, 1: generate_letters,