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")
Esempio n. 2
0
    def test_generate_letter_to_all_donors(self, mock_email_generator,
                                           mock_open):
        donor1 = Donor("jeff bezos", [200000])
        donor2 = Donor("Bill Gates", [150000])
        dc = DonorCollection([donor1, donor2])

        handlers = [
            mock.mock_open().return_value,
            mock.mock_open().return_value,
        ]
        mock_open.side_effect = handlers

        msg = "A letter has been successfully sent to every donor in our records!"
        assert dc.generate_letter_to_all_donors() == msg

        assert mock_email_generator.call_count == 2

        fcall_1 = mock.call('jeff_bezos.txt', 'w+')
        fcall_2 = mock.call('bill_gates.txt', 'w+')
        fcalls = [fcall_1, fcall_2]
        mock_open.assert_has_calls(fcalls)
Esempio n. 3
0
 def test_generate_letter_to_all_donors_list_empty(self):
     dc = DonorCollection()
     msg = "There are no donors in our current database records. Please add them"
     assert dc.generate_letter_to_all_donors() == msg