def create_test_donor(): c = Donor("Chris") c.add_donation(12345.67) c.add_donation(9876.54) return c
#!/usr/bin/env python3 """ Command Line Interface for Mailroom """ from donor_models import Donor, DonorCollection WK = Donor("Wassily Kandinsky") JJ = Donor("Jasper Johns") MR = Donor("Mark Rothko") RS = Donor("Richard Serra") YT = Donor("Yves Tanguy") WK.add_donation(43928.13) WK.add_donation(131.34) WK.add_donation(1928.0) JJ.add_donation(3134.43) JJ.add_donation(153.34) MR.add_donation(135353.33) RS.add_donation(153757.87) RS.add_donation(28457.12) RS.add_donation(1293451.0) YT.add_donation(1534.23) YT.add_donation(2542.19) DONOR_DB = DonorCollection(WK, JJ, MR, RS, YT) PROMPT = "\n".join(("\nMain Menu", "Type a number from the options below", "1 - Send a Thank You to a single donor", "2 - Create a Report", "3 - Quit\n"))
def test_donor_summary(): d = Donor('Homer Simpson', 25.50) d.add_donation(12.25) d.add_donation(10.25) print(d.summary) assert d.summary == ['Homer Simpson', 48, 3, 16]
def test_donor_add_donation(): c = Donor("Chris Gantt") c.add_donation(12345.67) assert c.donations[0] == 12345.67 c.add_donation(9876.54) assert c.donations == [12345.67, 9876.54]
def test_add_wrong_donation_type(): d = Donor('Homer Simpson', 25.50) with pytest.raises(ValueError): d.add_donation('wrong')
def test_add_negative_donation(): d = Donor('Homer Simpson', 25.50) with pytest.raises(ValueError): d.add_donation(-15.0)
def test_donor_add_donation_negative(): name, donation = "Fred Flintstone", -500.00 donor = Donor(name) with pytest.raises(TypeError): donor.add_donation(donation)
def test_add_donation(): d = Donor('Homer Simpson', 25.50) d.add_donation(15.00) assert d.donations == [25.50, 15.00]
"""Test for mailroom""" import os import time import pytest from donor_models import Donor, DonorCollection p1, p2 = Donor('Mo'), Donor('Larry') p2.add_donation(20) p1.add_donation(4, 2) dt = DonorCollection() dt.add_donors(p1, p2) def test_create_donor(): """Test create of donor""" assert p1._name == 'Mo' assert p2._name == 'Larry' def test_add_donation(): """Test donation added""" assert p1._donations[1] == 2 def test_math(): """Test math: total, num, avg""" assert p1.d_tot == 6 assert p1.d_num == 2 assert p1.d_avg == 3
def test_donor_add_donation(): name, donation = "Fred Flintstone", 500 donor = Donor(name) donor.add_donation(donation) assert donor.num_donations == 1
def test_add_donation(): d = Donor('Fred Armisen', [240, 422, 1000]) d.add_donation(600) assert d.donations == [240, 422, 1000, 600]
def test_compose_message(): """ Verify the donor message is correct """ donor = Donor("Bob", [100]) donor.add_donation(100) assert donor.compose_message == "\nTo: Bob\nSubject: Thank you.\n\nBob thank you for your previous generous " \ "donation of 100.00.\nYour total donations to date are now: 200.00."
def test_total_donations(): """ Verify donation total for a donor is correct """ donor = Donor("Bob", [100]) donor.add_donation(100) assert donor.donations_total == 200
def test_add_donation_fail(): """ Verify a donation value can not be added to a donor unless it can be cast to a float """ donor = Donor("Bob", [100]) with pytest.raises(ValueError): donor.add_donation("tom")
def test_add_donation(): """ Verify a donation can be added to a donor """ donor = Donor("Bob", [100]) donor.add_donation(100) assert donor.donations == [100, 100]