コード例 #1
0
def challenge(donors):
    """
    Mutiplies donor.donations in range [ll-ul] by [factor] and calls report to display new donations stats
    :param donors: Donors
    :return: None
    """
    factor = ui("Enter a factor by which to jack up your donation")
    if factor[0]:
        don_range = ui(
            "Enter the range for donations in format [upper]-[lower] or 'all' to include all values"
        )
        if don_range[0]:
            if don_range[1] == "all":
                report(
                    Donors.challenge(donors, int(factor[1])),
                    title=f"All donations increased by a factor of {factor[1]}"
                )
            else:
                vals = don_range[1].split("-")
                ll = int(vals[0])
                ul = int(vals[1])
                report(
                    Donors.challenge(donors, int(factor[1]), ll, ul),
                    f"Donations between {ll} and {ul} increased by {factor[1]}"
                )
コード例 #2
0
def test_list_donors():
    d1 = Donor("Fred Flinstone")
    d2 = Donor("James Dean")
    d3 = Donor("Jack the Ripper")
    d_list = Donors([d1, d2, d3])
    list_of_donors = d_list.list_donors()
    assert list_of_donors == [
        "Fred Flinstone", "James Dean", "Jack the Ripper"
    ]
コード例 #3
0
def test_get_donors_summary():
    D = Donors()
    sl = D.sort_donors()
    summary = [['Pam Beesley', '$6000.00', '3', '$2000.00'],
               ['Andy Bernard', '$500.00', '1', '$500.00'],
               ['Michael Scott', '$60.00', '3', '$20.00'],
               ['Dwight Shrute', '$5.00', '2', '$2.50'],
               ['Jim Halpert', '$1.00', '1', '$1.00']]

    assert D.get_donor_summary(sl) == summary
コード例 #4
0
def test_list_donors(capsys):
    D = Donors()
    D.list_donors()
    captured = capsys.readouterr()
    donors = ('Jim Halpert\n'
              'Pam Beesley\n'
              'Dwight Shrute\n'
              'Michael Scott\n'
              'Andy Bernard\n')
    assert captured.out == donors
コード例 #5
0
def test_find_donor():
    d1 = Donor("Fred Flinstone", [100, 200, 300, 400])
    d2 = Donor("James Dean", [500, 600, 700, 800])
    d3 = Donor("Jack the Ripper", [1, 2, 3, 4])
    d4 = Donor("Mickey Mouse", [100, 200, 300, 5, 15, 7])
    d_list = Donors([d1, d2, d3, d4])
    donor_class = d_list.find_donor("Mickey Mouse")
    assert donor_class.donation == [100, 200, 300, 5, 15, 7]
    donor_class = d_list.find_donor("")
    assert donor_class == []
コード例 #6
0
def test_make_thank_strings():
    d1 = Donor("Fred Flinstone", [100, 200, 300, 400])
    d2 = Donor("James Dean", [500, 600, 700, 800])
    d3 = Donor("Jack the Ripper", [1, 2, 3, 4])
    d_list = Donors([d1, d2, d3])
    thank_notes = d_list.make_thank_notes()
    assert thank_notes == [
        'Dear Fred Flinstone, Thank you for your donation of $1000.00. These funds help save the migratory butterflies of New South East.Thank you',
        'Dear James Dean, Thank you for your donation of $2600.00. These funds help save the migratory butterflies of New South East.Thank you',
        'Dear Jack the Ripper, Thank you for your donation of $10.00. These funds help save the migratory butterflies of New South East.Thank you'
    ]
コード例 #7
0
def test_make_filenames():
    d1 = Donor("Fred Flinstone", [100, 200, 300, 400])
    d2 = Donor("James Dean", [500, 600, 700, 800])
    d3 = Donor("Jack the Ripper", [1, 2, 3, 4])
    d4 = Donor("Mickey Mouse", [100, 200, 300, 5, 15, 7])
    d_list = Donors([d1, d2, d3, d4])
    filenames = d_list.make_filenames()
    assert filenames == [
        "Fred_Flinstone.txt", "James_Dean.txt", "Jack_the_Ripper.txt",
        "Mickey_Mouse.txt"
    ]
コード例 #8
0
def test_add_new_donor():
    d1 = Donor("Fred Flinstone")
    d2 = Donor("James Dean")
    d3 = Donor("Jack the Ripper")
    d_list = Donors([d1, d2, d3])
    d4 = Donor("Mickey Mouse")
    d_list.append(d4)
    assert d_list.donor_list[3].name == "Mickey Mouse"
    d_list.donor_list[3].add_donation(100)
    assert d_list.donor_list[3].donation == [
        100,
    ]
コード例 #9
0
def test_create_report(capsys):
    D = Donors()
    D.create_report()
    str1 = (
        'Donor Name                | Total Given | Num Gifts | Average Gift\n'
        'Pam Beesley                $   $6000.00 |         3  $    $2000.00\n'
        'Andy Bernard               $    $500.00 |         1  $     $500.00\n'
        'Michael Scott              $     $60.00 |         3  $      $20.00\n'
        'Dwight Shrute              $      $5.00 |         2  $       $2.50\n'
        'Jim Halpert                $      $1.00 |         1  $       $1.00\n')
    captured = capsys.readouterr()
    assert captured.out == str1
コード例 #10
0
def test_donor_email_total(capsys):
    D = Donors()
    name = 'Pam Beesley'
    donations = sum([1000.00, 2000.00, 3000.00])
    dstr = ('\n\nDear Pam Beesley,\n\n'
            '        Thank you for your very kind'
            ' donations totalling $6000.00.\n\n'
            '        It will be put to very good use.\n\n'
            '               Sincerely,\n'
            '                  -The Team\n\n\n')
    D.donor_email(name, donations)
    captured = capsys.readouterr()
    assert captured.out == dstr
コード例 #11
0
def test_make_report():
    d1 = Donor("Fred Flinstone", [100, 200, 300, 400])
    d2 = Donor("James Dean", [500, 600, 700, 800])
    d3 = Donor("Jack the Ripper", [1, 2, 3, 4])
    d_list = Donors([d1, d2, d3])
    report = d_list.make_report()
    assert d_list.make_headers_string(
    ) == 'Donor Names          Total Given     Num Gifts       Average Gifts  '
    assert report.startswith('Donor')
    assert 'Fred Flinstone       $1000.00         4               $250.00' in report
    assert 'James Dean           $2600.00         4               $650.00' in report
    assert 'Jack the Ripper      $10.00           4               $2.50' in report
    assert report.endswith('\n')
コード例 #12
0
def test_make_Donors():
    d1 = Donor("Fred Flinstone")
    d2 = Donor("James Dean")
    d3 = Donor("Jack the Ripper")
    donor_list = [d1, d2, d3]
    d_list = Donors(donor_list)
    assert d_list.donor_list[0].name == "Fred Flinstone"
コード例 #13
0
def test_sort_donors():
    d1 = Donor("Fred Flinstone", [100, 200, 300, 400])
    d2 = Donor("James Dean", [500, 600, 700, 800])
    d3 = Donor("Jack the Ripper", [1, 2, 3, 4])
    d4 = Donor("Mickey Mouse")
    d_list = Donors([d1, d2, d3])
    d_list.sort_donors()
    list_of_donors = d_list.list_donors()
    assert list_of_donors == [
        "James Dean", "Fred Flinstone", "Jack the Ripper"
    ]
    d_list.append(d4)
    d_list.sort_donors()
    list_of_donors = d_list.list_donors()
    assert list_of_donors == [
        "James Dean", "Fred Flinstone", "Jack the Ripper", "Mickey Mouse"
    ]
コード例 #14
0
def add_new_donor(donors, name):
    """
    Accepts arguments for the add new donor method
    :param donors: Donor
    :param name: (str) Name of the new donor
    :return: None
    """
    if not name:
        recipient = ui("Enter the name of the donor to thank")
        if recipient[0]:
            name = recipient[1]
        else:
            return None

    donation = ui(f"Enter a donation amount for {name}")
    if donation[0]:
        full_name = name.split()
        fnam = " ".join(full_name[:1])
        lnam = " ".join(full_name[1:])
        donor = Donor(fnam, lnam, float(donation[1]))
        Donors.new_or_append(donors, donor)
        print(donor.send_message())
    call_main()
コード例 #15
0
def test_donations_total():
    D = Donors()
    D.donations_total('Pam Beesley') == '$6000.00'
コード例 #16
0
from mailroom import Donor, Donors, main, send_thankyou, report, close

#-----------------------------------------------------------------------*
# Test Donor and Donors methods
#-----------------------------------------------------------------------*
donor = Donor("Bobby", "Orr", 50)
donor_list = Donors()
donor_list.load_default()


def test_load_default():
    assert len(donor_list.donors) > 0


def test_donor_str():
    """ Test the attributes of the donor class"""
    expected = ['add_donation', 'donation', 'fnam', 'lnam', 'keyval']
    attr = [i for i in dir(donor) if not i.startswith('__')]
    assert set(attr).difference(expected).__len__() == 0


def test_donor_initializer():
    d = Donor("Shawn", "Hopkins", 100)
    assert d.fnam == 'Shawn'
    assert d.lnam == 'Hopkins'
    assert sum(d.donation) == 100


def test_add_donation():
    d1 = Donor("Shawn", "Hopkins", 100)
    d1.add_donation(100)
コード例 #17
0
def test_sort_donors():
    D = Donors()
    sl = [('Pam Beesley', [1000.0, 2000.0, 3000.0]), ('Andy Bernard', [500.0]),
          ('Michael Scott', [10.0, 20.0, 30.0]), ('Dwight Shrute', [2.0, 3.0]),
          ('Jim Halpert', [1.0])]
    assert D.sort_donors() == sl
コード例 #18
0
def test_donor_key_found():
    D = Donors()
    D.donor_key_found('Jim Halpert') is True
コード例 #19
0
def test_generate_letters(capsys):
    D = Donors()
    D.generate_letters()
    str1 = '\n\n========== Letters Created ==========\n\n\n'
    captured = capsys.readouterr()
    assert captured.out == str1
コード例 #20
0
def test_donations_average():
    D = Donors()
    D.donations_total('Pam Beesley') == '$2000.00'
コード例 #21
0
        print(donors.send_report())
    call_main()


def call_main():
    dd = {"1": send_thankyou, "2": report, "3": challenge, "4": close}
    main_menu(
        "**Welcome to MailRoom**\nPlease select from the following actions\n\n\t(1)Send a thank you\n\t(2)Create a report\n\t(3)Jack up the donations\n\t(4)Quit\n\nSelect",
        dd)


def main_menu(msg, disp, testarg=0):

    selection = ui(msg)
    if selection[0]:
        return disp[selection[1]](donors)


def close(*args, **kwargs):
    print("Closing...")
    return False


import datetime

if __name__ == '__main__':

    donors = Donors()
    Donors.load(donors, "data.csv")
    call_main()
コード例 #22
0
def test_Donors():
    donors = Donors('test_donors.json')
    for i in donors.donors.values():
        assert isinstance(i[0]['date'], datetime)
コード例 #23
0
def test_make_check_Donors_attributes():
    d1 = Donor("Fred Flinstone", [100, 200, 300, 400])
    d2 = Donor("James Dean", [500, 600, 700, 800])
    d3 = Donor("Jack the Ripper", [1, 2, 3, 4])
    d_list = Donors([d1, d2, d3])
    assert d_list.donor_list[1].donation == [500, 600, 700, 800]
コード例 #24
0
def test_donations_count():
    D = Donors()
    D.donations_total('Pam Beesley') == 3
コード例 #25
0
def test_Donors_add_donor():
    donors = Donors('test_donors.json')
    now = datetime.now()
    bill = Donor('Bill Murray', [{'amount': 600.32, 'date': now}])
    donors.add_donor(bill)
    assert donors.donors['Bill Murray'][0] == {'amount': 600.32, 'date': now}
コード例 #26
0
def d():
    dl = Donors()
    dl.load("data.csv")
    return Donor("Bobby", "Orr", [50, 100, 150]), dl