def test_Donors_Collection_add_new_donor(): donors_collection = donation_history_initialization() new_donor = Donor('New') new_donor.add_donation(40) donors_collection.add_new_donor(new_donor) assert (donors_collection.donors[-1].name == 'New') is True assert (donors_collection.donors[-1].donations == [40]) is True
def test_add_donationfunctions(): d = Donor("Test") d + 5 d + 1 assert d.Donations == [5, 1] assert d.DonationNumber == 2 assert d.DonationTotal == 6 assert d.AverageDonations == 3
def test_write_json(): filename = "mailroomdata_try.json" jsonrecords = json.loads(''' {"John Dill": [10.0, 20.0, 30.0], "Sarah Pickle": [10.0, 20.0, 30.0], "Ornett Salt": [10.0, 20.0, 30.0], "Fanny Pepper": [10.0, 20.0, 30.0], "Jo Fang": [50.0]} ''') objrecords = {} for key, value in jsonrecords.items(): record = Donor(key, value) objrecords[key] = record M5.write_json(objrecords, filename) inrecords = M5.open_json(filename) assert inrecords["Fanny Pepper"].Donations == [10.0, 20.0, 30.0] assert inrecords["Jo Fang"].Donations == [50.0] assert inrecords["John Dill"].Donations == [10.0, 20.0, 30.0]
def test_add_donor(): global donors donors.add_donor('name four') assert donors['name four'] == Donor('name four', [])
def test_donors(): assert donors.donors == {'name one': Donor('name one', [1,2]), 'name two': Donor('name two', [3,4,5])}
def test_sort_key(): assert donors.sort_key(Donor('name', [7,8])) == 15
def test_names_by_donations(): assert donors.names_by_donations() == [Donor('name two', [3,4,5]), Donor('name one', [1,2])]
def test_iter(): assert list(iter(donors)) == [Donor('name one', [1,2]), Donor('name two', [3,4,5])]
def test_getitem(): assert donors['name one'] == Donor('name one', [1,2])
def test_thank_donor(): assert donors.thank_donor('name four',77) == \ Donor('name four', [77]).thank(77)
def test_add_donation(): global donors donors.add_donation('name four', 77) assert donors['name four'] == Donor('name four', [77])
#!/usr/bin/env python """This module contains test functions for the mailroom4 assignment.""" import pytest import datetime import mailroom5 from mailroom5 import DonorDict from mailroom5 import Donor don = Donor('Name Zero',[50, 1]) donors = DonorDict() donors.add_donor('name one', [1,2]) donors.add_donor('name two', [3,4,5]) donors.add_donor('name three', [6]) def test_init(): assert don.name == 'Name Zero' assert don.donations == [50, 1] def test_repr(): assert don.__repr__() == 'Donor(Name Zero, [50, 1])' def test_str(): assert don.__str__() == 'Donor(Name: Name Zero, Donations: [50, 1])' def test_eq(): assert don == Donor('Name Zero',[50, 1]) def test_name(): assert don.name == 'Name Zero'
def test_Donor(): new_donor = Donor('New') assert (new_donor.name == 'New') is True new_donor.add_donation(40) assert (new_donor.donations == [40]) is True
def test_11(): Donor('test', 10) assert 'test' in donations
def test_eq(): assert don == Donor('Name Zero',[50, 1])
def test_12(): Donor('other test', .01) assert 'other test' in donations
def test_donor_init(): d = Donor() assert d.Name == "Name me"