def print_thank_you_message(self, donor_name_input):
        """ Print a formatted message with donors name and recent donation amount """
        print(("{:^42}\n"
               "{:^42}\n"
               "For your incredibly generous donation of:\n"
               "{:>19}{:<23,}\n\n").format(
                   'Thank you so much', donor_name_input, '$',
                   int(don_col.donors[donor_name_input].donations[-1])))


def clear_screen():
    """ Clears the terminal screen """
    os.system('cls') if os.name == 'nt' else os.system('clear')


don_col = DonorCollection()
donor_letters = DonorLetters()
thank_you = ThankYou()

main_menu_answers = {
    '1': thank_you.send_a_thank_you,
    '2': don_col.generate_report,
    '3': donor_letters.letters_for_all
}

if __name__ == "__main__":
    clear_screen()

    # This is just to populate the don_col.donors dict with some info to play with
    for donor, donations in donors.items():
        don_col.add_donor(donor, donations[0])
Exemplo n.º 2
0
        print("\nLetter to {} has been sent".format(name))


def exit_program():
    # exit the interactive script
    print("Bye!")
    sys.exit()


def main():
    #dict with the user options and the functions
    switch_dict = {
        '1': send_thank_you,
        '2': create_report,
        '3': letter_to_all,
        '4': exit_program
    }

    while True:
        try:
            response = main_menu()
            switch_dict[response]()
        except KeyError:
            print(
                "\n'{}'  is not a valid option, please enter 1, 2, 3, or 4!. \n >> "
                .format(response))


if __name__ == "__main__":
    dc = DonorCollection()
    main()
Exemplo n.º 3
0
def test_collection_donor_exists():
    donors = DonorCollection()
    donors.add(Donor('Test1', [10]))
    donors.add(Donor('Test2', [27]))
    assert donors.donor_exists('Test1')
    assert donors.donor_exists('Test2')
#!/usr/bin/env python3
'''
This is the command interface for the mailroom.  Now that I know that donor
manipulations work correctly (At least according to pytest.  I mean, I wrote
the tests so the likelihood of human error here is high, you know?).
'''
import sys
from donor_models import DonorCollection
from mail_box import MailBox
'''
Module imports
'''

#pylint: disable=C0103
alms = DonorCollection()

'''
Because my sense of humor is odd, that's why.  Also setting an object
'''

class MailRoom:
    '''
    All the calls and commands will be through this class.  Manipulation of
    donor information is done in donor_models.py, and all of the execution for
    this subprogram is from mailroom_oo.py
    '''
    @staticmethod
    def list_donors():
        '''
        Lists existing donors.
        '''
Exemplo n.º 5
0
            outfile.write("Dear {:} {:}, \n".format(donor.first_name,
                                                    donor.last_name))
            outfile.write(
                f"Thank you for your accumulative donation of ${donor.total:.2f}. \n"
            )
            outfile.write(
                'Your contribution will do a great deal to help our worthy cause'
            )


def quit():
    print("Quitting program")
    return "exit menu"


def menu_selection(prompt, dispatch_dict):
    while True:
        try:
            response = input(prompt)
            if dispatch_dict[response]() == "exit menu":
                break
        except KeyError:
            print('input must be one of the following: 1, 2, 3, or 4:')


MAIN_DISPATCH = {'1': thanks, '2': report, '3': letters, '4': quit}

if __name__ == '__main__':
    donors = DonorCollection()
    donors.load_donors()
    menu_selection(MAIN_PROMPT, MAIN_DISPATCH)
Exemplo n.º 6
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
Exemplo n.º 7
0
#Mark McDuffie
#6/12/20
#Client class

import os
from donor_models import Donor
from donor_models import DonorCollection

donors = DonorCollection.initialize_dict({
    "Jim Johnson": [20000.0, 3500.0, 1600.0],
    "Mike Lee": [10000.0, 450.0, 1000.0],
    "Joe Smith": [100.0, 50.0],
    "Bob Miller": [900.0, 1200.0],
    "Steve James": [100000.0]
})


# Main Menu
def prompt():
    choice = input(
        "You have the following options: \n 1: Send a Thank You \n 2: Send Letters to all Donors "
        "\n 3: Create a Report \n 4: Quit \n")
    return choice


# Send a Thank you note to Donor
def send_thankyou():
    donor_name = input(
        "Please enter the donor's name (first, last) \nor type 'list' to see current donors \n"
    )
    while donor_name.lower() == "list":
Exemplo n.º 8
0
def test_donor_collection_append():
    donor = Donor("Peter Pan", [5.00, 10.00, 15.00, 20.00, 25.00])
    donor_collection = DonorCollection(donors_data)

    donor_collection.append(donor)
    assert "Peter Pan" in donor_collection.donors
Exemplo n.º 9
0
#/usr/bin/env python3
import sys
import contextlib
from io import StringIO

from donor_models import Donor, DonorCollection

donations = DonorCollection(Donor("Natasha Singer", 120, '02-08-2010'))
donations.add_donation("Bob Marquardt", 40, '05-08-1994')


def test_send_thank_you():
    temp_stdout = StringIO()
    with contextlib.redirect_stdout(temp_stdout):
        donations.send_thank_you("Natasha Singer")
    output = temp_stdout.getvalue().strip()
    assert "Natasha Singer" in output


def test_get_report():
    temp_stdout = StringIO()
    with contextlib.redirect_stdout(temp_stdout):
        donations.get_report()
    output = temp_stdout.getvalue().strip()
    assert "Natasha Singer" in output


def test_send_letter_all():
    donations.send_letters()
    with open('Natasha_Singer.txt', 'r') as f:
        assert "Natasha Singer" in f.read()
Exemplo n.º 10
0
def test_donors():
    donor_collection = DonorCollection(donors_data)
    donor_donors = donor_collection.donors
    print(f'td.... donor_donors --  {donor_donors}')
    for donor in check_donor_names:
        assert donor in donor_donors
Exemplo n.º 11
0
def test_donor_collection_creation_no_donors():
    donor_collection = DonorCollection()
    assert donor_collection.donors == ()
    assert len(donor_collection.donors) == 0
Exemplo n.º 12
0
def test_dc__len__():
    donor_collection = DonorCollection(donors_data)
    print(f't__len__.... len(donor_collection) {len(donor_collection)}')
    assert len(donor_collection) == 5
Exemplo n.º 13
0
def test_donor_collection_tuple():
    donor_collection = DonorCollection(tuple(donors_data))
    for donor in check_donor_names:
        assert donor in donor_collection.donors
Exemplo n.º 14
0
def test_donor_collection__init():
    donor_collection = DonorCollection(donors_data)
    print(f'tidc.... len(donor_collection) {len(donor_collection)}')
    assert len(donor_collection) == 5
    for donor in check_donor_names:
        assert donor in donor_collection.donors
Exemplo n.º 15
0
def test_donorcollection_init():
    # Test that donor collection initializes with empty dict
    dc = DonorCollection()
    assert dc.donors == {}
    assert dc.donorNames == []
Exemplo n.º 16
0
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 22 14:02:03 2020

@author: miriam
"""

from donor_models import Donor
from donor_models import DonorCollection
import os.path
import pathlib
import pytest

donor = DonorCollection()


def test_donors_history():
    """ Test donor in the History of dictionary of donors created """
    donor = Donor('Urias Gramajo')
    assert donor.name == 'Urias Gramajo'


def test_donors_list():
    """ Test all donor names are returned"""
    donor.add(Donor('Noe', [50]))
    donor.add(Donor('David', [500]))
    assert 'Noe' in donor.donors_list()
    assert 'David' in donor.donors_list()
    assert 'Noe\nDavid' in donor.donors_list()

Exemplo n.º 17
0
def test_add_donor():
    # Test that donors can be added to collection
    dc = DonorCollection()
    dc.updateDonor('Jason Mendoza', 25.)
    donors = dc.donors
    assert 'Jason Mendoza' in donors
Exemplo n.º 18
0
def test_create_donor_collection():
    dc = DonorCollection()
    assert isinstance(dc, DonorCollection)
Exemplo n.º 19
0
 def test_get_donor_records(self):
     donor1 = Donor("jeff bezos", [200000])
     donor2 = Donor("Bill Gates", [150000])
     dc = DonorCollection([donor1, donor2])
     assert dc.get_donor_records("Jeff Bezos") == donor1
     assert dc.get_donor_records("Steve Jobs") is None
Exemplo n.º 20
0
def test_add_donor():
    dc = DonorCollection()
    dc.add_donor('first last')
    assert len(dc.donors) == 1
Exemplo n.º 21
0
def create_report():
    print("Charity Donor History")
    print("Donor Name" + " " * 16 + "| Total Given | Num Gifts | Average Gift")
    print("-" * 66)
    for donor in DonorCollection.make_report(donors):
        print("{:<25} ${:>12.2f}  {:>9d}   ${:>11.2f}".format(*donor))
Exemplo n.º 22
0
def test_add_existing_donor():
    dc = DonorCollection()
    dc.add_donor('first last')
    with pytest.raises(ValueError):
        dc.add_donor('first last')
    assert len(dc.donors) == 1
Exemplo n.º 23
0
def test_thank_you_letter():
    d = Donor("Nathan Explosion", [10, 100])
    # checks if donor name is in thank you letter
    assert 'Nathan Explosion' in d.thank_you_letter()
    # checks that the last donation is in thank you letter
    assert '100' in d.thank_you_letter()


# testing DonorCollection model

donor_dict = {
    "William": [87470],
    "Pickles": [87838],
}
donors = DonorCollection.initialize_donor_dict(donor_dict)


def test_initialize_donor_dict():
    # checks that there are2 donors
    assert len(donors.donors) == 2
    # checks donation amount for second donor is correct
    assert donors.donors["Pickles"].donation_amount == [87838]


def test_add_donor():
    d = Donor("Erik", [100])
    donors.add_donor(d)
    # checks if the DonorCollection has added a new donor
    assert len(donors.donors) == 3
Exemplo n.º 24
0
def test_donor_list():
    dc = DonorCollection()
    dc.add_donor('first last')
    dc.add_donor('second name')
    assert dc.donor_list == ['First Last', 'Second Name']
Exemplo n.º 25
0
    donors : DonorCollection
        DonorCollection to operate on
    """

    donors.write_thank_yous(directory='.')
    print('All letters written to current directory.\n')


def _exit_(*args, **kwargs):
    exit(0)


if __name__ == "__main__":
    """Main Mailroom Executable"""

    dc = DonorCollection(*INITIAL_DONORS)

    # Build up dispatch dictionary
    actions = {}
    for r in _thankyou_responses:
        actions[r] = send_thank_you
    for r in _report_responses:
        actions[r] = report_action
    for r in _all_thank_responses:
        actions[r] = all_thanks
    for r in _quit_responses:
        actions[r] = _exit_

    # Print intro
    print("\nWelcome to the Mailroom Program!\n")
    print(
Exemplo n.º 26
0
def test_donor_report():
    dc = DonorCollection()
    dc.add_donor('first last', (1, 2, 3))
    dc.add_donor('second name', (4, 5, 6))
    assert dc.donor_report == [['First Last', 6, 3, 2],
                               ['Second Name', 15, 3, 5]]
Exemplo n.º 27
0
def test_collection_init():
    donors = DonorCollection()
    assert type(donors) is DonorCollection
Exemplo n.º 28
0
    notes and detailed donor reports.
"""

import sys
from donor_models import Donor, DonorCollection

# Initial donations
initial_donations = {
    "Rhianna": [747, 3030303, 1968950],
    "Grumps": [5.99],
    "EatPraySlay": [100000, 200000, 300000],
    "Muir": [469503, 50000, 186409],
    "Spacewalker": [4406, 342]
}

donors = DonorCollection.from_dict(initial_donations)


def get_donor_name():
    """Get donor name from user."""

    while True:
        donor_name = input("Who would you like to thank? (Type 'list' "
                           "to see a list of donors.)\n  Full Name: ")

        # Print list of existing donors to choose from
        if donor_name.lower() == "list":
            print("\n".join(donors.list()))

        # Ensure the user has entered a name
        elif donor_name.replace(" ", "").replace(".", "").replace(",", "").\
def test_coll_find_donor():
    charity = DonorCollection()
    charity.create_donor("Judy Jetson")

    assert charity.find_donor(
        "Judy Jetson") == charity.donors_dict["Judy Jetson"]
Exemplo n.º 30
0
def test_report():
    dc = DonorCollection()
    report = dc.report()
    assert "Donor Name     |    Total Given     |     Num Gifts      |    Average Gift" in report
    for patron in dc.donor_list:
        assert patron.name in report