Пример #1
0
class TestDonor(unittest.TestCase):
    """Unit tests for the Donor class"""
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.test_name = 'Test Donor'
        self.test_dons = [100, 500, 50.05]
        self.test_total = sum(self.test_dons)
        self.test_ave = self.test_total / len(self.test_dons)

    def setUp(self):
        self.donor = Donor(self.test_name, self.test_dons)

    def tearDown(self):
        pass

    def test_get_donations(self):
        """Test donations attribute"""
        self.assertTrue(self.donor.donations == self.test_dons)

    def test_set_donations(self):
        """Test setting donations attribute"""
        with self.assertRaises(AttributeError):
            self.donor.donations = [100, 20]

    def test_get_num_donations(self):
        """Test num_donations attribute"""
        self.assertTrue(self.donor.num_donations == len(self.test_dons))

    def test_set_num_donations(self):
        """Test setting num_donations attribute"""
        with self.assertRaises(AttributeError):
            self.donor.num_donations = 4

    def test_get_total_donations(self):
        """Test total_donations attribute"""
        self.assertTrue(self.donor.total_donations == self.test_total)

    def test_set_total_donations(self):
        """Test setting total_donations attribute"""
        with self.assertRaises(AttributeError):
            self.donor.total_donations = 100

    def test_get_ave_donations(self):
        """Test average_donations attribute"""
        self.assertTrue(self.donor.average_donations == self.test_ave)

    def test_set_ave_donations(self):
        """Test setting average_donations attribute"""
        with self.assertRaises(AttributeError):
            self.donor.average_donations = 100

    def test_add_donation(self):
        """Test add_donation method"""
        donation = random.randint(0, 10000.0)
        self.donor.add_donation(donation)
        self.assertTrue(self.donor.donations == self.test_dons + [donation])
        self.assertTrue(self.donor.num_donations == len(self.test_dons) + 1)
        self.assertTrue(self.donor.total_donations == self.test_total + donation)
        self.assertTrue(self.donor.average_donations ==
                        (self.test_total + donation) / (len(self.test_dons) + 1))
Пример #2
0
def test_donor_collection():
    dc = DonorCollection()

    dc.add_donor(Donor("Bob"))

    dc.find_donor()

    dc.list_donors()

    dc.thank_donors()
Пример #3
0
def test_add_donations():
    d = Donor("Fred Flintstone", 3000)
    d.add_donations(500)
    assert len(d.donations) is not 0
Пример #4
0
def test_num_donations():
    d = Donor('Jon', 5000)
    assert d.num_donations() == 1
    assert d.num_donations() >= 0
Пример #5
0
def test_donor_name():
    donor = Donor("Fred Flintstone", 3000)
    assert donor.donations is not None
    assert donor.name == "Fred Flintstone"
Пример #6
0
def test_avg_donations():
    d = Donor('Jon', 5000)
    assert d.avg_donations() == 5000
    assert d.avg_donations() != 6000
Пример #7
0
def test_sum_donations():
    d = Donor('Jon', 5000)
    assert d.sum_donations() == 5000
Пример #8
0
def test_letter_to_everyone():
    donor = Donor("Bob", 9000)
    dc = DonorCollection()
    for i in dc.list_donors(donor):
        assert os.path.exists(i + ".txt")
 def setUp(self):
     self.donor = Donor(self.test_name, self.test_dons)
 def setUp(self):
     self.db = DonorDatabase(*[
         Donor(self.d1_name, self.d1_dons),
         Donor(self.d2_name, self.d2_dons),
         Donor(self.d3_name, self.d3_dons)
     ])
Пример #11
0
def test_add_donation():
    donor = Donor("Fred Flintstone")

    donor.add_donation(500)
    assert int(donor.donation) is True
    assert donor.num_donation == 1