def main():
    # Loading donors data if it exists
    filename = 'donors.txt'
    donor_collection = DonorCollection()
    msg = donor_collection.load_donor_data_from_file(filename)
    IO.print_data_to_user(msg)

    # Display the menu
    while True:
        IO.print_main_menu()
        choice = IO.input_choice("Which action would you like to perform? ")

        if choice == '1':
            IO.send_thank_you_to_single_donor(donor_collection)
        elif choice == '2':
            IO.print_data_to_user(donor_collection.generate_donor_report())
        elif choice == '3':
            IO.print_data_to_user(donor_collection.generate_letter_to_all_donors())
        elif choice == '4':
            if len(donor_collection.donor_list):
                donor_collection.save_donor_data_to_file(filename)
            IO.print_data_to_user("GoodBye!")
            break
        else:
            IO.print_data_to_user("Your selection is invalid. Please select a menu option from 1 to 4")
Пример #2
0
 def test_save_donor_data_to_file(self):
     donor1 = Donor("jeff bezos", [200000])
     donor2 = Donor("Bill Gates", [150000])
     dc = DonorCollection([donor1, donor2])
     with mock.patch("builtins.open", mock.mock_open()) as mock_open:
         dc.save_donor_data_to_file('donors.txt')
         mock_open.assert_called_with('donors.txt', 'w+')
         call_1 = mock.call('Jeff Bezos;200000\n')
         call_2 = mock.call('Bill Gates;150000\n')
         calls = [call_1, call_2]
         mock_open().write.assert_has_calls(calls)