Ejemplo n.º 1
0
def test_add_donor():
    """ Verify a new donor can be added to the donor list"""
    donors = Donors()
    donor = donors.add_donor("Bob", 125.50)

    assert donor.name == "Bob"
    assert donor.donations[0] == 125.50
Ejemplo n.º 2
0
def test_donor_exists():
    """ Verify the return value for an existing donor using the default list by checking if the return value is a list
    and the list contains the object related to the donor """
    donors = Donors()
    result = donors.donor_exists("Neymar")

    assert isinstance(result, list)
    assert result[0].name == "Neymar"
Ejemplo n.º 3
0
def test_donor_doesnt_exists():
    """ Verify the return value for a non-existing donor using the default list by checking if the return value is an
    empty list """
    donors = Donors()
    result = donors.donor_exists("Bob")

    assert isinstance(result, list)
    with pytest.raises(IndexError):
        result[0]
def test_DonorCollect_letters():
    """ tests if letters are generated with correct content """
    donors = Donors()
    donors.letters()
    d = pathlib.Path('.').absolute()
    p = d / 'ThankYouLetters'
    f1 = "Peregrin_Took.txt"
    f2 = "Smeagol.txt"
    f3 = "Samwise_Gamgee.txt"
    assert p / f1 in p.iterdir()
    assert p / f2 in p.iterdir()
    assert p / f3 in p.iterdir()
    with open(p / f2, 'r') as f:
        content = f.read()
    assert content.startswith("Dear Smeagol,")
Ejemplo n.º 5
0
def test_create_report():
    """ Use the default donor_list to verify the method creates a list of donors containing:
    donor name, total donation amount, number of donation, average donation """
    donors = Donors()
    report_data = donors.create_report()

    assert ['Lionel Messi', 100, 1, 100.0] in report_data
    assert ['Cristiano Ronaldo', 14475, 3, 4825.0] in report_data
    assert ['Gianluigi Buffon', 1002500.5, 2, 501250.25] in report_data
    assert ['Neymar', 405.24, 4, 101.31] in report_data
    assert ['Paolo Maldini', 24039.95, 4, 6009.9875] in report_data

    # The list is sorted by total donation amount so check the first and last items are correct
    assert "Gianluigi Buffon" in report_data[0]
    assert "Lionel Messi" in report_data[4]
def test_DonorCollect_report():
    """ tests whether report list is being generated and sorted """
    donors = Donors()
    report = donors.report()
    assert report[0] == ["Samwise Gamgee", 10601.93, 3, 3533.98]
    assert report[4] == ["Smeagol", 45.01, 1, 45.01]
def test_DonorCollect_update():
    """ tests whether an existing donor's information can be updated """
    donors = Donors()
    donor = donors.update_donor("Smeagol", 500)
    n = donor.donation_number
    assert n == 2
def test_DonorCollect_add():
    """ tests whether a new donor can be added """
    donors = Donors()
    donors.add_donor("Gimli", [90, 20])
    find = donors.search_donor("Gimli")
    assert "Gimli" in find
def test_DonorCollect_search():
    """ tests that search by name returns list with name if exists """
    donors = Donors()
    find = donors.search_donor("Smeagol")
    assert "Smeagol" in find
Ejemplo n.º 10
0
def test_DonorCollect_list():
    """ tests string that lists existing donor names """
    donors = Donors()
    assert donors.list_donors().startswith("\nPeregrin Took")
    assert donors.list_donors().endswith("Frodo Baggins\n")
Ejemplo n.º 11
0
        )


def send_to_everyone():
    """ Create a report for every donor """
    donors.send_to_everyone()


def exit_menu(*args):
    """ Exits the current menu or program
    :param: Using *args as some methods in menus require parameters but this method does not
    :return: String to exit """
    return "exit"


# Main menu options to be presented to the user
menu_options = ("\n1 - Send Thank You", "\n2 - Create Report",
                "\n3 - Send Letters to Everyone", "\n0 - Exit")
menu_dict = {
    "0": exit_menu,
    "1": send_thank_you,
    "2": print_report,
    "3": send_to_everyone
}

if __name__ == '__main__':

    donors = Donors()
    prompt_user(menu_options, menu_dict)
    print("\nProgram Over")
Ejemplo n.º 12
0
def test_get_donation_padding():
    """ Verify the method produces the expected int result using the default donor list """
    donors = Donors()
    donation_padding = donors.get_donation_padding(['Gianluigi Buffon', 1002500.5, 2, 501250.25])

    assert donation_padding is 14
Ejemplo n.º 13
0
def test_get_name_padding():
    """ Verify the method produces the expected int result using the default donor list """
    donors = Donors()
    name_padding = donors.get_name_padding

    assert name_padding is 21
Ejemplo n.º 14
0
def test_list_donors():
    """ Verify the method creates a string containing the expected donors """
    donors = Donors()
    donor_list = donors.list_donors

    assert donor_list == "\nLionel Messi\nCristiano Ronaldo\nGianluigi Buffon\nNeymar\nPaolo Maldini\n"