Esempio n. 1
0
def test_not_donor():
    """
    Test a non-existent donor.
    """
    donor_db = mailroom.donor_dict
    donor = mailroom.find_donor("Saya Nadella", donor_db)
    assert donor is None
Esempio n. 2
0
def test_find_donor_not_there():
    """
    check that it finds a donor that is there
    """
    donor = mr.find_donor("bob jones")

    assert donor is None
Esempio n. 3
0
def test_find_donor_there():
    """
    check that it finds a donor that is there
    """
    donor = mr.find_donor("Jeff Bezos")

    assert donor[0].lower() == "Jeff Bezos".lower()
Esempio n. 4
0
def test_add_donor():
    name = "Fred Flintstone  "

    donor = mailroom.add_donor(name)
    donor[1].append(300)
    assert donor[0] == "Fred Flintstone"
    assert donor[1] == [300]
    assert mailroom.find_donor(name) == donor
Esempio n. 5
0
def test_add_donation_new_donor():
    """
    tests adding a dontation when the donor is new
    """
    # make sure the DB is clean
    mr.donor_db = mr.get_donor_db()

    name = "John Smith"
    donation_amount = 300.5

    # make sure he's not already there
    assert mr.find_donor(name) is None
    mr.add_donation(name, donation_amount)

    donor = mr.find_donor(name)
    assert donor is not None
    assert donor[1] == [donation_amount]
def test_remove_donor_there():
    # make sure to start with a clean test set
    mr.donor_db = get_test_donors()

    result = mr.remove_donor("jeff bezos")

    assert result is True
    assert mr.find_donor("jeff bezon") is None
Esempio n. 7
0
def test_add_donor():
    mr.donor_db = mr.get_donor_db()
    name = "Fred Flintstone  "

    donor = mr.add_donor(name)
    donor[1].append(300)
    assert donor[0] == "Fred Flintstone"
    assert donor[1] == [300]
    assert mr.find_donor(name) == donor
def test_find_donor_not_there():
    """
    check that it finds a donor that is there
    """
    # make sure to start with a clean test set
    mr.donor_db = get_test_donors()
    donor = mr.find_donor("bob jones")

    assert donor is None
def test_find_donor_there():
    """
    check that it finds a donor that is there
    """
    # make sure to start with a clean test set
    mr.donor_db = get_test_donors()

    donor = mr.find_donor("Jeff Bezos")

    assert donor[0].lower() == "Jeff Bezos".lower()
def test_add_donor():
    """
    adds a new donor

    then tests that the donor is added, and that a donation is properly recorded.
    """
    name = "Fred Flintstone  "

    donor = mailroom.add_donor(name)
    donor[1].append(300)
    assert donor[0] == "Fred Flintstone"
    assert donor[1] == [300]
    assert mailroom.find_donor(name) == donor
def test_add_donor():
    """
    adds a new donor

    then tests that the donor is added, and that a donation is properly recorded.
    """
    # extra spaces should get stripped
    name = "Fred Flintstone  "

    donor = mr.add_donor(name)
    donor[1].append(300)
    assert donor[0] == "Fred Flintstone"
    assert donor[1] == [300]
    assert mr.find_donor(name) == donor
Esempio n. 12
0
def test_find_donor():
    """ checks a donor that isthere, but with odd case and spaces"""
    donor = mailroom.find_donor("jefF beZos ")

    assert donor[0] == "Jeff Bezos"
def test_find_donor_not():
    "test one that's not there"
    donor = mailroom.find_donor("Jeff Bzos")

    assert donor is None
def test_find_donor():
    #pytest.skip("skipping this test")
    """ checks a donor that is there, but with odd case and spaces"""
    donor = mailroom.find_donor("jefF beZos ")

    assert donor[0] == "Jeff Bezos"
Esempio n. 15
0
def test_find_donor_nonexistant():
    result = mailroom.find_donor('Eric Adams')
    assert result is None
Esempio n. 16
0
def test_find_donor_key():
    '''
    Input a valid user from the mailroom.donor_db
    '''
    result = mailroom.find_donor('William Gates, III')
    assert result == 'William Gates, III'
Esempio n. 17
0
def test_find_donor():
    """
    Checks to see if a donor exists but with varied whitespace and cases.
    """
    assert mailroom.find_donor("satYa nADella ", mailroom.donor_dict)
Esempio n. 18
0
def test_find_donor():
    """ checks a donor that is there, but with odd case and spaces"""
    donor = mailroom.find_donor("jefF beZos ")

    assert donor.name == "Jeff Bezos"


# def test_add_donation_negative():
#     # fixme: there should be a better way to get an arbitrary donor
#     donor = sample_db.donor_data.popitem()[1]

#     with pytest.raises(ValueError):
#         donor.add_donation(-100)

#     with pytest.raises(ValueError):
#         donor.add_donation(0.0)

# def test_list_donors():
#     # create a clean one to make sure everything is there.
#     sample_db = mailroom.DonorDB(mailroom.get_sample_data())
#     listing = sample_db.list_donors()

#     # hard to test this throughly -- better not to hard code the entire
#     # thing. But check for a few aspects -- this will catch the likely
#     # errors
#     assert listing.startswith("Donor list:\n")
#     assert "Jeff Bezos" in listing
#     assert "William Gates III" in listing
#     assert len(listing.split('\n')) == 5

# # fixme: add more odd serch test cases -- extra whitespace, etc.
# def test_find_donor():
#     """ checks a donor that is there, but with odd case and spaces"""
#     donor = sample_db.find_donor("jefF beZos ")

#     assert donor.name == "Jeff Bezos"

# def test_find_donor_not():
#     "test one that's not there"
#     donor = sample_db.find_donor("Jeff Bzos")

#     assert donor is None

# def test_gen_letter():
#     """ test the donor letter """

#     # create a sample donor
#     donor = mailroom.Donor("Fred Flintstone", [432.45, 65.45, 230.0])
#     letter = sample_db.gen_letter(donor)
#     # what to test? tricky!
#     assert letter.startswith("Dear Fred Flintstone")
#     assert letter.endswith("-The Team\n")
#     assert "donation of $230.00" in letter

# def test_add_donor():
#     name = "Fred Flintstone  "

#     donor = sample_db.add_donor(name)
#     donor.add_donation(300)
#     assert donor.name == "Fred Flintstone"
#     assert donor.last_donation == 300
#     assert sample_db.find_donor(name) == donor

# def test_generate_donor_report():

#     report = sample_db.generate_donor_report()

#     print(report)  # printing so you can see it if it fails
#     # this is pretty tough to test
#     # these are not great, because they will fail if unimportant parts of the
#     # report are changed.
#     # but at least you know that code's working now.
#     assert report.startswith("Donor Name                | Total Given | Num Gifts | Average Gift")

#     assert "Jeff Bezos                  $    877.33           1   $     877.33" in report

# def test_save_letters_to_disk():
#     """
#     This only tests that the files get created, but that's a start

#     Note that the contents of the letter was already
#     tested with test_gen_letter
#     """

#     # FIXME: this should create a temp dir to save to.
#     sample_db.save_letters_to_disk()

#     assert os.path.isfile('Jeff_Bezos.txt')
#     assert os.path.isfile('William_Gates_III.txt')
#     # check that it's not empty:
#     with open('William_Gates_III.txt') as f:
#         size = len(f.read())
#     assert size > 0

# # if __name__ == "__main__":
# #     # this is best run with a test runner, like pytest
# #     # But if not, at least this will run them all.
# #     test_list_donors()
# #     test_find_donor()
# #     test_find_donor_not()
# #     test_gen_letter()
# #     test_add_donor()
# #     test_generate_donor_report()
# #     test_save_letters_to_disk()
# #     print("All tests Passed")
Esempio n. 19
0
def test_find_donor():
    """ checks a donor that is there, but with odd case and spaces"""
    mr.donor_db = mr.get_donor_db()
    donor = mr.find_donor("jefF beZos ")

    assert donor[0] == "Jeff Bezos"
Esempio n. 20
0
def test_find_donor_not():
    "test one that's not there"
    donor = mailroom.find_donor("Jeff Bzos")

    assert donor is None
Esempio n. 21
0
def test_find_donor_not():
    "test one that's not there"
    mr.donor_db = mr.get_donor_db()
    donor = mr.find_donor("Jeff Bzos")

    assert donor is None