def test_save_read_file(): """ verify save donors and read donors we create a donors object, save it, read it, then examine the contents which indirectly tests both save and read """ test_donor_a = Donor(full_name="Joe Smith", donation=100) test_donor_a.add_donation(150) test_donor_b = Donor(full_name="Mary Jo Kline, III", donation=1000) test_donors = Donors(test_donor_a) test_donors.add_donor(test_donor_b) test_donor_file = "test_donor_file" save_donor_file(test_donors, donor_file=test_donor_file) return_donors = load_donor_file(donor_file=test_donor_file) name_matches = [x[0] for x in return_donors.full_name_index] print(name_matches) assert "Joe Smith" in name_matches assert "Mary Jo Kline, III" in name_matches assert "Joe Jo Williams" not in name_matches os.remove(test_donor_file)
def test_donor_entry_normal(): my_donors = Donors() data_entry(my_donors) matches = my_donors.match_donor("Fred Smith") name_matches = [x[0] for x in matches] print(matches) assert "Fred Smith" in name_matches
def test_donor_entry_misc(): """ lazy system test This is pretty brittle and lazy, but implicitly tests that that a wide variety of functions work becase each step needs to act in the predicted manor for you to get to the end result. """ my_donors = Donors() main(my_donors) matches = my_donors.match_donor("Fred Smith") name_matches = [x[0] for x in matches] print(matches) assert "Fred Smith" in name_matches
def test_match_donor(): """ verify the match_donor search functions """ test_donor_a = Donor(full_name="Joe Smith", donation=100) test_donor_a.add_donation(150) test_donor_b = Donor(full_name="Mary Jo Kline, III", donation=1000) test_donors = Donors(test_donor_a) test_donors.add_donor(test_donor_b) matches = test_donors.match_donor("Joe Smith") name_matches = [x[0] for x in matches] print(matches) assert "Joe Smith" in name_matches assert "Mary Jo Kline, III" not in name_matches
def test_donors_str(): """ test repr values represent donors object """ in_donors = Donors( Donor(did='902a4e3e-deff-11e7-bee5-0800274b0a84', first_name='Maggie', last_name='Smith', donations=[{ 'amount': 99.0, 'date': '2017-12-12Z' }], created='2017-12-12T05:44:47.480878Z')) repr_str = repr(in_donors) out_donors = eval(repr_str) assert repr(in_donors) == repr(out_donors)
def test_thank_all_donors(): """ verify the print_thank_you() function """ test_donor_a = Donor(full_name="Joe Smith", donation=100) test_donor_a.add_donation(150) test_donor_b = Donor(full_name="Mary Jo Kline, III", donation=1000) test_donors = Donors(test_donor_a) test_donors.add_donor(test_donor_b) out = io.StringIO() thank_all_donors(test_donors, dest_override=out) output = out.getvalue() out.close() assert "Dearest Mary Jo Kline, III," in output assert "Dearest Joe Smith," in output
def test_donor_iter(): """ verify the Donors object is iterable """ test_donor_a = Donor(full_name="Joe Smith", donation=100) test_donor_b = Donor(full_name="Mary Jo Kline, III", donation=1000) test_donor_c = Donor(full_name="Adam Frank") test_donors = Donors(test_donor_a) test_donors.add_donor(test_donor_b) test_donors.add_donor(test_donor_c) counter = 0 for full_name, did, last_name, first_name in test_donors: print(full_name, did, last_name, first_name) counter += 1 assert counter == 3
def test_list_donors(): """ verify the list_donors() function """ test_donor_a = Donor(full_name="Joe Smith", donation=100) test_donor_a.add_donation(150) test_donor_b = Donor(full_name="Mary Jo Kline, III", donation=1000) test_donors = Donors(test_donor_a) test_donors.add_donor(test_donor_b) out = io.StringIO() list_donors(test_donors, dest=out) output = out.getvalue() out.close() print(output) assert "Donor Name | Total Given | Num Gifts | Average Gift" in output assert "Joe Smith $ 250.00 2 $ 125.00" in output assert "Mary Jo Kline, III $ 1,000.00 1 $ 1,000.00" in output
def test_create_donors(): """ verify create_donors verifies donor objects can be added via the constructor as well as via add_donor() """ test_donor_a = Donor(full_name="Joe Smith", donation=100) test_donor_a.add_donation(150) test_donor_b = Donor(full_name="Mary Jo Kline, III", donation=1000) test_donor_c = Donor(full_name="Adam Frank") test_donors = Donors(test_donor_a) test_donors.add_donor(test_donor_b) test_donors.add_donor(test_donor_c) name_matches = [x[0] for x in test_donors.full_name_index] assert test_donors.number_donors == 3 assert "Adam Frank" in name_matches