Пример #1
0
def create_a_report():
    dc = dm.DonorCollection()
    l = (["Donor Name", "Total Given", "Num Gifts", "Average Gift"])
    l1 = []
    a_list = dc.name_list()
    temp_list = dc.report_list()

    m = 0
    while m < len(temp_list):
        l1.append(temp_list[m:m + 4])
        m = m + 4

    l1 = sorted(l1, key=lambda i: i[0])
    l1.insert(0, l)

    new_list = []
    [new_list.append(len(j)) for i in l1 for j in i]
    l = max(new_list)
    space = " " * 10
    width = l

    for a, b, c, d in l1:
        print(
            f'{a:<{width}}{space}{b:>{width}}{space}{c:>{width}}{space}{d:>{width}}'
        )
Пример #2
0
def send_a_thank_you():
    full_name = user_input_name()
    donation_amount = user_input_amount()
    dc = dm.DonorCollection()
    dc.update_donor_db(full_name.upper(), donation_amount)
    d = dm.Donor(full_name, donation_amount)
    d.generate_letter()
Пример #3
0
def send_all_thank_you():
    dc = dm.DonorCollection()
    for i in dc.donor_db:
        full_name = i[0]
        last_donation = i[1][-1]
        d = dm.Donor(full_name, last_donation)
        d.generate_letter()
Пример #4
0
 def test_add_donor(self):
     donator = d.Donor('Alan', 3, 4, 5)
     donator2 = d.Donor('Bob', 6, 7, 8)
     collection = d.DonorCollection(donator, donator2)
     collection.add_donor('Charlie')
     donator3 = collection.get_donor('Charlie')
     self.assertIn(donator3, collection.donors)
Пример #5
0
def test_donor_list():
    donor_collection = donor_models.DonorCollection()
    donor_collection.add_donor("Bill Gates")
    donor_collection.add_donor("Willie Nelson")

    exemplar_text = "\nCurrent donors are:\nBill Gates\nWillie Nelson\n"

    assert donor_collection.get_donor_list_text() == exemplar_text
Пример #6
0
 def test_donor_object(self):
     donator = d.Donor('Alan', 3, 4, 5)
     donator2 = d.Donor('Bob', 6, 7, 8)
     donator3 = d.Donor('Charlie', 9, 10, 11)
     collection = d.DonorCollection(donator, donator2, donator3)
     self.assertIn(donator, collection.donors)
     self.assertIn(donator2, collection.donors)
     self.assertIn(donator3, collection.donors)
Пример #7
0
def test_get_donor_by_name():
    donor_collection = donor_models.DonorCollection()
    donor_collection.add_donor("Willie Nelson")
    donor = donor_collection.get_donor_by_name("Willie Nelson")

    assert donor.name == "Willie Nelson"

    with pytest.raises(NameError):
        donor = donor_collection.get_donor_by_name("Chase Dullinger")
Пример #8
0
 def test_write_donors(self):
     donator = d.Donor('Alan', 3, 4, 5)
     donator2 = d.Donor('Bob', 6, 7, 8)
     donator3 = d.Donor('Charlie', 9, 10, 11)
     collection = d.DonorCollection(donator, donator2, donator3)
     collection.write_donors()
     assert os.path.isfile('Alan.txt')
     assert os.path.isfile('Bob.txt')
     assert os.path.isfile('Charlie.txt')
Пример #9
0
def test_donorcollection_class():
    """Verify basic operations of the donation class"""
    donors = dm.DonorCollection()
    donors.add(dm.Donor('Joe Nunnelley', [20, 40]))
    donors.add(dm.Donor('Mary Margaret', [30, 50]))
    assert donors.get_donor('Joe Nunnelley').name == 'Joe Nunnelley'
    assert len(donors.get_donor('Mary Margaret').donations) == 2
    donors.delete('Joe Nunnelley')
    assert len(donors.donors) == 1
    assert donors.get_donor('Mary Margaret').name == 'Mary Margaret'
Пример #10
0
def test_add_dononation_to_donor_collection():
    donor_collection = donor_models.DonorCollection()
    donor_collection.add_donor("Willie Nelson")
    donor_collection.add_donation_to_donor("Willie Nelson", 100)

    donor = donor_collection.get_donor_by_name("Willie Nelson")

    assert donor.total_donations == 100
    assert donor.number_of_donations == 1
    assert donor.average_gift == 100
Пример #11
0
def test_create_all_letters():
    """Test that all the expected letters were created on disk.
    Note that the letter text was tested in test_email_text
    """
    donor_collection = donor_models.DonorCollection()
    donor_collection.add_donor("Bill Gates")
    donor_collection.add_donor("Willie Nelson")
    donor_collection.create_all_letters()
    for donor in donor_collection.donor_names:
        assert os.path.exists(f"{donor}.txt") is True
Пример #12
0
def test_create_report():
    """Test the create report function"""
    donor_collection = donor_models.DonorCollection()
    donor_collection.add_donor("Paul Allen")
    donor_collection.add_donation_to_donor("Paul Allen", [663.23, 43.87, 1.32])
    text_string = donor_collection.create_report()
    reference_text = "Paul Allen                 $      708.42          3 \
 $      236.14"

    assert text_string.split("\n")[-2] == reference_text
Пример #13
0
def test_save_donation_db():
    """Test that donations can be saved
    """
    donor_collection = donor_models.DonorCollection()
    donor_collection.add_donor("Bill Gates", 100)
    donor_collection.add_donor("Willie Nelson", 200)
    donor_collection.add_donation_to_donor("Willie Nelson", 300)
    donor_collection.add_donor("Jeff Bezos")

    donor_collection.save_donor_db(filename="donor_db_test_save.txt")

    assert os.path.exists("donor_db_test.txt") is True
Пример #14
0
def test_read_donation_db():
    """Test that donations can be read"""
    donor_collection = donor_models.DonorCollection()
    donor_collection.read_donor_db(filename="donor_db_test_read.txt")
    assert "Bill Gates" in donor_collection.donor_names
    assert "Willie Nelson" in donor_collection.donor_names

    donor = donor_collection.get_donor_by_name("Willie Nelson")
    assert donor.total_donations == 500

    donor = donor_collection.get_donor_by_name("Jeff Bezos")
    assert donor.total_donations == 0
    assert donor.number_of_donations == 0
Пример #15
0
 def test_report(self):
     donator = d.Donor('Alan', 3, 4, 5)
     donator2 = d.Donor('Bob', 6, 7, 8)
     donator3 = d.Donor('Charlie', 9, 10, 11)
     collection = d.DonorCollection(donator, donator2, donator3)
     self.assertEqual(
         collection.report,
         '\n' + '{:20}'.format('Donor Name') + '  ' + 'Total Given' + '  ' +
         'Num Gifts' + '  ' + 'Average Gift' + '\n' + '\n'
         '{:20}'.format('Charlie') + ' $' + '{:11.2f}'.format(30) + '  ' +
         '{:9.0f}'.format(3) + ' $' + '{:12.2f}'.format(10) + '\n'
         '{:20}'.format('Bob') + ' $' + '{:11.2f}'.format(21) + '  ' +
         '{:9.0f}'.format(3) + ' $' + '{:12.2f}'.format(7) + '\n'
         '{:20}'.format('Alan') + ' $' + '{:11.2f}'.format(12) + '  ' +
         '{:9.0f}'.format(3) + ' $' + '{:12.2f}'.format(4) + '\n')
Пример #16
0
def test_donorcollection():
    # test if checks for invalid input
    with pytest.raises(TypeError):
        dm.DonorCollection("invalid")
    assert dc.names == [d1.name, d2.name, d3.name]
    assert dc.display_names == [
        d1.display_name, d2.display_name, d3.display_name
    ]
    assert dc.donors[d1.name] == d1
    with pytest.raises(TypeError):
        dc.add_donor("not a Donor")
    d4 = dm.Donor("Dude4")
    dc.add_donor(d4)
    print(d4.__repr__)
    assert d4 in dc.donors.values()
Пример #17
0
 def test_get_donor(self):
     donator = d.Donor('Alan', 3, 4, 5)
     donator2 = d.Donor('Bob', 6, 7, 8)
     donator3 = d.Donor('Charlie', 9, 10, 11)
     collection = d.DonorCollection(donator, donator2, donator3)
     returned_donor2 = collection.get_donor('Alan')
     self.assertEqual(returned_donor2.donor, 'Alan')
     returned_donor = collection.get_donor('Bob')
     self.assertEqual(returned_donor.donor, 'Bob')
     self.assertEqual(returned_donor.donations, (6, 7, 8))
     returned_donor3 = collection.get_donor('Charlie')
     self.assertEqual(returned_donor3.donor, 'Charlie')
     with pytest.raises(IndexError):
         collection.get_donor('abc')
     with pytest.raises(IndexError):
         collection.get_donor('')
Пример #18
0
def test_add_donor_collection():
    donor_collection = donor_models.DonorCollection()

    assert len(donor_collection.donors) == 0

    donor = donor_models.Donor("Bill Gates")

    donor_collection.add_donor_object(donor)

    assert len(donor_collection.donors) == 1

    assert "Bill Gates" in donor_collection.donor_names

    donor_collection.add_donor("Willie Nelson")

    assert len(donor_collection.donors) == 2
    assert "Willie Nelson" in donor_collection.donor_names

    # check to see that commas are removed
    donor_collection.add_donor("William Gates, III")
    assert "William Gates III" in donor_collection.donor_names

    with pytest.raises(NameError):
        donor_collection.add_donor("Willie Nelson")
Пример #19
0
#!/usr/bin/env python3
import tempfile
import time
import sys
import donor_models as dm
"""
A  module for handling command line interface for a donor program
"""

donors = dm.DonorCollection()


def thank_you():
    """
    Print menu options for writing a thank you letter.
    If 'list' is provided, launch list_donors function.
    if 'menu' is provided, this function terminates
    If a name is provided, launch write_letter function
    """
    thank_you_options = {"MENU": False, "LIST": list_donors}
    while True:
        user_selection = (input(
            "\nPlease provide a full name to send thank you note to (options 'list' and 'menu'): "
        ))
        action = thank_you_options.get(user_selection.upper())
        if action is False:
            break
        elif action is None:  # Write letter to user selection if an action option wasn't selected
            write_letter(user_selection)
        else:
            action()
Пример #20
0
 def test_donor_names(self):
     donator = d.Donor('Alan', 3, 4, 5)
     donator2 = d.Donor('Bob', 6, 7, 8)
     donator3 = d.Donor('Charlie', 9, 10, 11)
     collection = d.DonorCollection(donator, donator2, donator3)
     self.assertEqual('Alan\nBob\nCharlie', collection.donor_names)
Пример #21
0
import sys
import donor_models as d

# sample data to start with
d1 = d.DonorCollection(d.Donor("Jeff Bezos", [877.33]))
d1.apply_donation("Paul Allen", [100, 10, 800])


def find_donor():
    while True:
        fullname = input("type list to display names or quit to exit to main menu\n" \
                         "Enter full name of donor: ")
        if fullname == "list":
            print(list_names())
        elif fullname != "quit":
            try:
                donation_amount = float(input("Donation amount: "))
                d1.apply_donation(fullname, donation_amount)
            except ValueError:
                print("not a valid response exiting to donor selection")
            d1.donor_list[fullname].send_thankyou()
        else:
            return


def list_names():
    donor_names = [k for k in sorted(d1.donor_list.keys())]
    return "\n".join(donor_names)


def quit_app():
Пример #22
0
def create_data():
    #Sample data
    names = [("Calvin","Fleming"), ("Mary", "Andrews")]
    donorslist = [dm.Donor(*name,1200.00) for name in names]
    dc = dm.DonorCollection(donorslist)
    return dc
Пример #23
0
def test_create_empty_donorcollection():
    """ Test the creation of a empty donor collection """
    dc = dm.DonorCollection()
    assert dc.list_donors() == []
Пример #24
0
import sys
import donor_models as dm

dc = dm.DonorCollection()


def user_input_name():
    while True:
        full_name = input("Pleass enter Full Name >> ")
        if full_name == "list":
            print("\n".join(dc.name_list()))
        else:
            break
    return full_name.upper()


def user_input_amount():
    try:
        donation_amount = int(input("Enter donation amount >> "))
    except:
        print("please enter integer only")
        exit_program()

    return donation_amount


def send_a_thank_you():
    full_name = user_input_name()
    donation_amount = user_input_amount()
    dc = dm.DonorCollection()
    dc.update_donor_db(full_name.upper(), donation_amount)
Пример #25
0
import sys
import donor_models as dm

don_list = dm.DonorCollection()


def display_menu():
    """Displays the interactive menu to the user."""
    print('This program tracks the donation history for a charity.')
    print('Please select from the following options:\n' +
          '1) Record Donation and Send Thank You\n' + '2) Create A Report\n' +
          '3) Quit')
    user_selection = input('')
    return user_selection


def record_donation():
    """
    Menu Option 1
    Add donation amount for the requested doonr to the donor list.
    """
    response = input('Please enter a full name or "List":').title()

    #Print the list of donors in the log if requested by the user.
    while response == 'List':
        print(don_list)
        response = input('Please enter a full name: ').title()

    try:
        amount = float(input('Please enter a donation amount:'))
    except ValueError:
Пример #26
0
#! /usr/bin/env python3
"""
The Mailroom Program : Part 4 : Object Oriented
Author : Joe Nunnelley
Description:
    A small command line based mailroom application designed to thank donors.
"""
import datetime
import os
import sys
import tempfile
import donor_models as d

DONOR_SET = d.DonorCollection()
DONOR_SET.add(d.Donor("George Jetson", [100.00, 50.00, 200.00]))
DONOR_SET.add(d.Donor("Bugs Bunny", [400.00, 55.00, 5000.00]))
DONOR_SET.add(d.Donor("Daffy Duck", [0.00, 3.00, 5.00, 6.00, 76.00, 8.00]))
DONOR_SET.add(
    d.Donor("Elmer Fudd", [66.00, 666.00, 6666.00, 6666.00, 66666.00]))
DONOR_SET.add(d.Donor("Porky Pig", [0.50, 56.45, 67.89]))

BOUNDARY = '#####'

UI_MENU = {
    'Main': """
        What would you like to do?
        Pick one:
            1.) Send a Thank You to a single donor.
            2.) Create a Report
            3.) Send letters to all donors.
            4.) Quit
def initialization(initial):

    if initial == '1':
        #collection = []
        collection = donor_models.DonorCollection()
        for name in donors:
            collect = donor_models.Donor(name)
            collection.add_donor(collect)
            collection.donors_listed(collect)
        initial = 1
        selection = selections[initial]
        return [collection, selection, initial]

    elif initial is '2':
        collection = donor_models.DonorCollection()
        donor_thom = donor_models.Donor("Thomas Tran".lower())
        donor_thom.donations = [5, 17, 23]
        collection.add_donor(donor_thom)
        collection.donors_listed(donor_thom)

        donor_frank = donor_models.Donor("Frank Merriweather".lower())
        donor_frank.donations = [10, 15, 100]
        collection.add_donor(donor_frank)
        collection.donors_listed(donor_frank)

        donor_stephanie = donor_models.Donor("Stephanie Terrance".lower())
        donor_stephanie.donations = [31, 48, 108]
        collection.add_donor(donor_stephanie)
        collection.donors_listed(donor_stephanie)

        donor_shioban = donor_models.Donor("Shioban Kemp".lower())
        donor_shioban.donations = [2, 23000, 19]
        collection.add_donor(donor_shioban)
        collection.donors_listed(donor_shioban)

        donor_sandy = donor_models.Donor("Sandy Cohen".lower())
        donor_sandy.donations = [29, 41, 70]
        collection.add_donor(donor_sandy)
        collection.donors_listed(donor_sandy)

        donor_sam = donor_models.Donor("Sam Robidas".lower())
        donor_sam.donations = [4, 90, 101]
        collection.add_donor(donor_sam)
        collection.donors_listed(donor_sam)
        initial = 2
        selection = selections[initial]
        #print(initial)
        return [collection, selection, initial]
    if initial is '3':
        collection = donor_models.DonorCollection()
        donor_thom = donor_models.Donor("Thomas Tran".lower())
        donor_thom.donations = [5, 17, 23]
        collection.add_donor(donor_thom)
        collection.donors_listed(donor_thom)
        donor_thom.address = "36-81 Astor Place"
        donor_thom.phone_number = "718-218-3020"
        donor_thom.activity_date = datetime.datetime.strptime(
            "2020-03-28", '%Y-%m-%d')

        donor_frank = donor_models.Donor("Frank Merriweather".lower())
        donor_frank.donations = [10, 15, 100]
        collection.add_donor(donor_frank)
        collection.donors_listed(donor_frank)
        donor_frank.address = "341 8th Avenue"
        donor_frank.phone_number = "212-432-3121"
        donor_frank.activity_date = datetime.datetime.strptime(
            "2020-05-15", '%Y-%m-%d')

        donor_stephanie = donor_models.Donor("Stephanie Terrance".lower())
        donor_stephanie.donations = [31, 48, 108]
        collection.add_donor(donor_stephanie)
        collection.donors_listed(donor_stephanie)
        donor_stephanie.address = "419 Greenpoint Street"
        donor_stephanie.phone_number = "646-256-7463"
        donor_stephanie.activity_date = datetime.datetime.strptime(
            "2020-06-01", '%Y-%m-%d')

        donor_shioban = donor_models.Donor("Shioban Kemp".lower())
        donor_shioban.donations = [2, 23000, 19]
        collection.add_donor(donor_shioban)
        collection.donors_listed(donor_shioban)
        donor_shioban.address = "3456 Tartan Way"
        donor_shioban.phone_number = "718-982-2648"
        donor_shioban.activity_date = datetime.datetime.strptime(
            "2019-03-15", '%Y-%m-%d')

        donor_sandy = donor_models.Donor("Sandy Cohen".lower())
        donor_sandy.donations = [29, 41, 70]
        collection.add_donor(donor_sandy)
        collection.donors_listed(donor_sandy)
        donor_sandy.address = "9827 Grease Court"
        donor_sandy.phone_number = "817-495-3678"
        donor_sandy.activity_date = datetime.datetime.strptime(
            "2021-01-04", '%Y-%m-%d')

        donor_sam = donor_models.Donor("Sam Robidas".lower())
        donor_sam.donations = [4, 90, 101]
        collection.add_donor(donor_sam)
        collection.donors_listed(donor_sam)
        donor_sam.address = "34 21st Street"
        donor_sam.phone_number = "387-466-2354"
        donor_sam.activity_date = datetime.datetime.strptime(
            "2018-09-28", '%Y-%m-%d')
        initial = 3
        selection = selections[initial]
        return [collection, selection, initial]
Пример #28
0
#!/usr/bin/env python3
import pytest
import donor_models as dm
import cli_main as cm
import statistics as st
'''
Test for the object oriented version of the mailroom program.
'''

# instantiate inital classes to test
d1 = dm.Donor("Dude1")
d2 = dm.Donor("Dude2", [100.00])
d3 = dm.Donor("Dude3", [100.00, 200.00])
dc = dm.DonorCollection({d1.name: d1, d2.name: d2, d3.name: d3})

email_string = (
    f"Dear {d3.display_name},\n\n"
    "It is with incredible gratitude that we accept your wonderfully "
    f"generous donation of ${d3.donations[-1]:,.2f}.  Your "
    "contribution will truly make a difference in the path forward "
    "towards funding our common goal."
    "\n\nEver Greatefully Yours,\n\n"
    "X" + ("_" * 20) + "\n")


def test_create_donor():
    assert d1.name == "dude1"
    assert d1.display_name == "Dude1"
    assert d1.donations == []
    assert d2.donations == [100.00]
    assert d3.donations == [100.00, 200.00]
Пример #29
0
#!/usr/bin/env python3
"""main module"""
import sys
import re
#import io
#import os
#import webbrowser
import donor_models as dm

_DC = dm.DonorCollection()


def valid_money():
    """ensures valid dollar amount is inputted"""
    while True:
        r_1 = input("Please enter a donation amount ")
        try:
            amount = float(r_1)
            if amount < 0.01 or amount > 10000:
                print("Invalid value")
            else:
                return amount
        except ValueError:
            print("Invalid value")


def valid_name():
    """ensures valid name is inputted"""
    while True:
        r_1 = input("Please enter a full name ")
        r_2 = re.sub(r'[^a-zA-Z]+', '', r_1)
Пример #30
0
import donor_models as donor_models
import sys

donor_collection = donor_models.DonorCollection()

# Display options
prompt = "\n".join(("Welcome to the donor list!",
          "Please choose from below options:",
          "1 - Send a Thank you",
          "2 - Create a Report",
          "3 - Exit",
          ">>> "))

def display_list():

    '''
    Display the list of current donors
    :return: prints donor names
    '''

    for d in donor_collection.donors:
        print(d.donor_name)


def send_thank_you_note():

    '''
    Check for the user input and send a thank you once user entered
    :return: nothing
    '''