コード例 #1
0
 def test_generate_thank_you_email_to_single_donor(self):
     donor = Donor("jeff bezos", [200000, 75000])
     email_to_donor = (
         "Dear Jeff Bezos,\nWe would like to thank you for your donation. "
         "So far, you have donated $ 275000.00 to our organization and for "
         "that, we are grateful.You are helping us continue our work supporting "
         "and growing our community.\nYou truly make a difference! We could not "
         "do this work without your support.\n\n")
     result = donor.generate_thank_you_email_to_single_donor()
     self.assertEqual(result, email_to_donor)
コード例 #2
0
    def send_thank_you_to_single_donor(cls, donor_collection):
        while True:
            cls.print_thank_you_menu()
            choice = cls.input_choice("Which action would you like to perform? ")

            if choice == '1':
                donor_full_name = cls.input_choice("What is the full name of the donor?: ").lower()
                try:
                    donation_amount = cls.input_choice(
                        "How much did {} donate to the cause? $ ".format(donor_full_name.title())
                    )
                    donation_amount = float(donation_amount)
                except ValueError:
                    cls.print_data_to_user(
                        "\nThe donation amount introduced is not a valid number (i.e: 300.00). Please try again!")
                    continue
                if donation_amount > 0:
                    donor = donor_collection.get_donor_records(donor_full_name)
                    if donor is None:
                        donor = Donor(donor_full_name, [donation_amount])
                        donor_collection.add_donor(donor)
                    else:
                        donor.add_donation(donation_amount)

                    cls.print_data_to_user("{}'s donation for $ {:.2f} will be saved in our records".format(
                        donor.full_name,
                        donation_amount)
                    )
                    email = donor.generate_thank_you_email_to_single_donor()
                    cls.print_data_to_user(email)
                else:
                    cls.print_data_to_user("A donation needs to be higher than zero dollars "
                                           "in order to be added to the donor's records")
            elif choice == '2':
                cls.print_data_to_user(donor_collection.generate_donor_report())
            elif choice == '3':
                break
            else:
                cls.print_data_to_user("Your selection is invalid. Please select a menu option from 1 to 3")