Ejemplo n.º 1
0
def test_report_generator():
    """ Test if the report for the sample donor database is accurate"""
    donor_Db = Donor_Collection(get_sampleDB())

    report = donor_Db.report_generator()

    assert report.startswith(
        "Donor Name                 |  Total Given  | Num Gifts|  Average Gift |"
    )
    assert "Christina Levermore        $       10000.00          1 $       10000.00" in report
Ejemplo n.º 2
0
def test_report_generator():
    """ Test if the report for the sample donor database is accurate"""
    print(report)
    sampleDB = {
        "Fred Jones": Donor("Fred Jones", 500),
        "Christina Levermore": Donor("Christina Levermore", 10000)
    }
    donor_Db = Donor_Collection()
    donor_Db.copy_constructor(sampleDB, "Christina Levermore", 10000)

    report = donor_Db.report_generator()
    assert report.startswith("      Donor Name           | ")
    assert "Christina Levermore" in report
def main():
    """
    main function which contains the switch_case dictionary
    tests to make sure the user input a correct entry
    """
    # d1 = Donor("Jeff Bezos",[1000,500,20])
    # d2 = Donor('blue berry',[1233,513])
    donor_collection = Donor_Collection()
    switch = {
        "1":thank_you,
        "2":thank_you_new,
        "3":create_report,
        "4":send_letters,
        "5":halt
    }
    
    while True:
        choice = input("""What would you like to do?
            1: Send a Thank You to a single existing donor
            2: Send a Thank You to a new donor
            3: Create a Report
            4: Send letters to all donors
            5: Quit
            >>> """).strip()
        if choice not in switch.keys():
            print(f'You input {choice}, please input 1 through 5')
        else:
            switch[choice](donor_collection)
Ejemplo n.º 4
0
def test_donor_collection():
    #make sure a new donor_collection instance can be created with no inputs
    no_donors = Donor_Collection()
    assert no_donors.donor_data == {}
    #test to make sure the donor_collection instance can be added to with a list of donor objects
    donors = Donor_Collection([Donor('Jack', [1000, 2000, 3000])])
    #test to make sure that the donor name "Jack" appears in the search_donor function
    assert donors.search_donor("Jack")
    donors.add_donor(Donor("Pepe", [500, 200, 100]))
    assert donors.search_donor("Pepe")
Ejemplo n.º 5
0
def test_sort_report():
    """ Test to sort the dictionary correctly """
    sampleDB = {
        "Fred Jones": Donor("Fred Jones", 500),
        "Christina Levermore": Donor("Christina Levermore", 10000)
    }
    donorDB = Donor_Collection()
    donorDB.copy_constructor(sampleDB, "Christina Levermore", 10000)
    donorDB.sort_report()

    assert donorDB.get_sorted_dict()[0][0] == "Christina Levermore"
Ejemplo n.º 6
0
                         "1 - Input", "2 - Output", "e - Exit", ">>>  "))

err_prompt = "\n".join(("Please provide a valid option!", "1 - Input",
                        "2 - Output", "e - Exit", ">>>  "))

donor_in_prompt = "\n".join(
    ("Welcome to donor database!", "Choose an action:", "1 - Add a donation",
     "e - Exit to main panel", ">>>  "))

donor_out_prompt = "\n".join(
    ("Welcome to donor database!", "Choose an action:",
     "1 - Generate thank you letter for last donation",
     "2 - Generate donation report", "3 - Save all thank you to disk",
     "e - Exit to main panel", ">>>  "))

donorDb = Donor_Collection()
last_donor = ""
last_donation_amount = 0
OUT_PATH = "thank_you_letters"


def input_handler():
    while True:
        response = input(donor_in_prompt)
        # create a dictionary for user's selections
        switch_donorDB_dict = {
            "1": pre_add_donor,
            "e": main,
            "E": main,
        }
        # choose a function depending on response, if the choice is not in dict, catch exception
Ejemplo n.º 7
0
    """
    Export thank you notes for all donors.
    """
    print("\n\nLets thank everybody!")
    print(
        str("\nThis will prepare a letter to send to everyone has donated to "
            "Studio Starchelle in the past."))
    print(
        str("All letters will be saved as text (.txt) files in the default directory a "
            "different directory is specified."))

    save_dir = FileHelpers.get_user_output_path()

    if save_dir is None:
        print("\nCancelling send to all.  Returning to main menu...\n")
        return

    for donor in donor_list:
        file_path = path.join(save_dir, f"{donor.name}.txt")
        FileHelpers.write_file(file_path,
                               donor.get_email(donor_list.email_template))

    print(f"Donor letters successfully saved to: {save_dir}")


if __name__ == "__main__":
    args = parser.parse_args()
    donor_list = Donor_Collection.from_file(args.donors, args.email)

    main(args)
Ejemplo n.º 8
0
def test_donor_collection_send_letters():
    donors = Donor_Collection([Donor("Jack", 100)])
    assert donors.send_letters()[0][0].lower().strip().replace(
        " ", ""
    ) == 'dearjack,\n\n\nonbehalfoflocalcharitywewouldliketoextendoursincerestthanksforyourmostrecent$100.00donation.\n\nwithoutpeoplelikeyouwecouldnotcontinueblahblahblah\n\novertimeyouhavegivenusatotalof$100.00over1donation(s)whichaveragesoutto$100.00perdonation!\n\nagainthankyou\n\nsincerely,\n\nlocalcharity'
Ejemplo n.º 9
0
def test_donor_collection_gen_report():
    donors = Donor_Collection([Donor("Jack", 100)])
    assert "".join(donors.gen_report()[1].lower().strip().replace(
        " ", "")) == "jack$100.001$100.00"