Exemplo n.º 1
0
 def display_donor_list(self):
     """Display all the stored donor names for the user."""
     if md.DonorCollection().name_list():
         print(self.DONOR_LIST_HEADER)
         for name in md.DonorCollection().name_list():
             print(name)
     else:
         print("\n\tThe name list is empty.")
def test_donor_collection_list_multiple():
    """
    Tests that donor list is a class attribute as intended, such that multiple
    instances of 'DonorCollection' objects can access the same donor list.
    """
    donor1 = md.DonorCollection()
    donor1.donor_list = []
    donor1.new_donor("JoDee", "Messina")
    donor2 = md.DonorCollection()
    donor2.new_donor("Reba", "MacIntire")
    assert len(donor2.donor_list) == 2
def test_donor_collection_return_list():
    """Tests that strings of donor names are correctly returned"""
    donor = md.DonorCollection()
    donor.donor_list = []
    donor.new_donor("Faith", "Hill")
    donor_list = donor.name_list()
    assert "Faith" in donor_list[0]
def test_donor_collection_search():
    """Tests that existing donors return True and non-existent return False"""
    donor = md.DonorCollection()
    donor.donor_list = []
    donor.new_donor("Jon", "Pardi")
    assert donor.search("Jon", "Pardi") is True
    assert donor.search("Trisha", "Yearwood") is False
def test_donor_collection_add_donation_existing_donor():
    """Tests that a donation can be correctly attributed to an existing donor."""
    donor = md.DonorCollection()
    donor.donor_list = []
    donor.new_donor("Eric", "Church")
    donor.new_donation("Eric", "Church", 5000)
    assert donor.donor_list[0].total == 5000
Exemplo n.º 6
0
 def report(self):
     """Display donation data report to user."""
     print(self.REPORT_HEADER_1, self.REPORT_HEADER_2)
     report = md.DonorCollection().report()
     if report:
         for item in report:
             print("{:<26}${:>12,}{:^17}${:>11,}".format(
                 item[0], item[1], item[2], item[3]))
     else:
         print("\t\t\t*** No data exists to display ***")
Exemplo n.º 7
0
 def email():
     """Write text(s) to file simulating email(s) thanking donor(s)."""
     emails = md.DonorCollection().group_email()
     for email in emails:
         try:
             with open(f"{email}.txt", "w") as file:
                 file.write(emails[email])
         except KeyError:
             print("An error occurred with the preparation of the emails.")
         except TypeError:
             print("An invalid data type (i.e. not a string) was used and "
                   "could not be written to file.")
Exemplo n.º 8
0
 def new_donation(self):
     """Organize process flow for calling and validating user input for new donations"""
     try:
         first, last = self.validate_name()
     except TypeError:
         self.main_menu()
     else:
         if last.lower() not in ("quit", ""):
             first = first.capitalize()
             last = last.capitalize()
             amount = self.get_donation_amount()
             if amount is not None:
                 print(md.DonorCollection().new_donation(
                     first, last, amount))
def test_donor_collection_report():
    """
    Tests that all donor calcs for the report are made correctly for
    both types of donors: those who have made donations, and those who
    are in the system but haven't made a donation.
    """
    donor = md.DonorCollection()
    donor.donor_list = []
    donor.new_donor("Alan", "Jackson")
    donor.new_donor("Chris", "Stapleton")
    donor.new_donation("Chris", "Stapleton", 15000)
    donor.new_donation("Chris", "Stapleton", 5000)
    assert donor.report()[0] == ["Chris Stapleton", 20000, 2, 10000]
    assert donor.report()[1] == ["Alan Jackson", 0, 0, 0]
def test_donor_collection_email():
    """
    Tests that strings are correctly formatted to personalize emails to be sent to donors.
    Also verifies that names in the donor list who haven't made donations do not
    receive emails (i.e. they're not in the keys of the dictionary).
    """
    donor = md.DonorCollection()
    donor.donor_list = []
    donor.new_donor("Dierks", "Bentley")
    donor.new_donor("Thomas", "Rhett")
    donor.new_donor("Luke", "Bryan")
    donor.new_donation("Dierks", "Bentley", 10000)
    donor.new_donation("Dierks", "Bentley", 10000)
    donor.new_donation("Thomas", "Rhett", 5000)
    emails = donor.group_email()
    assert "donations totaling $20,000" in emails["Dierks Bentley"]
    assert "donation of $5,000" in emails["Thomas Rhett"]
    assert "Luke Bryan" not in emails.keys()
def test_donor_collection_add_donation_new_donor():
    """Tests that a new donor can be created and then credited with the donations."""
    donor = md.DonorCollection()
    donor.donor_list = []
    donor.new_donation("Montgomery", "Gentry", 12000)
    assert donor.donor_list[0].total == 12000
def test_donor_collection_list():
    """Test that donor list correctly stores donors as objects"""
    donor = md.DonorCollection()
    donor.new_donor("George", "Strait")
    assert len(donor.donor_list) == 1
    assert isinstance((donor.donor_list[0]), object)