Пример #1
0
 def test_total_donations(self):
     """Test the total donation amount from all donors in the Class Instance"""
     new_group = d.Group(d.Individual('Shane', [3]))
     new_group.add('Joe', 10)
     new_group.add('Joe', 5)
     new_group.add('Joe', 6)
     self.assertEqual(new_group.total_donations(), 24)
Пример #2
0
 def test_challenge3(self):
     """Test minimum donation filter with donation multiplier of 2."""
     new_group = d.Group(d.Individual('Shane', [3]))
     new_group.add('Joe', 10)
     new_group.add('Joe', 5)
     new_group.add('Joe', 6)
     self.assertEqual(new_group.challenge(2, min_donation=10), 10)
Пример #3
0
 def test_sort_list_2(self):
     new_group = d.Group(d.Individual('Shane', [3]))
     donors_f = {
         'Joe': [15, 3, 35],
         'Jack': [9, 2, 4.5],
         'Fred': [2000, 2, 60]
     }
     self.assertEqual(new_group.sort_list(donors_f),
                      ['Fred', 'Joe', 'Jack'])
Пример #4
0
 def test_report(self):
     new_group = d.Group(d.Individual('Shane', [3]))
     new_group.add('Joe', 3)
     new_group.add('Joe', 3)
     new_group.add('Joe', 3)
     new_group.add('Jack', 4)
     new_group.add('Jack', 5)
     assert "Joe        $" in new_group.report
     assert "9.00     3         " in new_group.report
     assert '$        3.00' in new_group.report
Пример #5
0
 def test_summary(self):
     """Add a donor to the list and test that the donor summary
     is correct"""
     new_group = d.Group(d.Individual('Shane', [3]))
     new_group.add('Joe', 3)
     new_group.add('Joe', 3)
     new_group.add('Joe', 3)
     new_group.add('Jack', 4)
     new_group.add('Jack', 5)
     donor_summary = new_group.summary()
     self.assertEqual(donor_summary, {
         'Shane': [3, 1, 3],
         'Joe': [9, 3, 3],
         'Jack': [9, 2, 4.5]
     })
Пример #6
0
    def test_letters_for_all(self):
        new_group = d.Group(d.Individual('Shane', [3]))
        new_group.add('Joe', 3)
        new_group.add('Joe', 3)
        new_group.add('Joe', 3)
        new_group.add('Jack', 4)
        new_group.add('Jack', 5)
        try:
            new_group.letters()
            with open('Jack.txt', 'rU') as f:
                text = f.read()
        finally:
            os.remove('Jack.txt')

        expected_text = 'Dear Jack, thank you so much for your last ' \
                        'contribution of $5.00! You have contributed ' \
                        'a total of $9.00, and we appreciate your ' \
                        'support!'
        self.assertEqual(expected_text, text)
Пример #7
0
 def test_column_total_width_2(self):
     new_group = d.Group(d.Individual('Shane', [3]))
     donors_f = {'Joe': [1555555555555, 3, 3], 'Jack': [9, 2, 4.5]}
     self.assertEqual(new_group.column_total_width(donors_f), 16)
Пример #8
0
 def test_Group_get(self):
     new_group = d.Group(d.Individual('Joe', [3, 3, 3]))
     self.assertEqual(new_group._donor_raw['Joe'].donations, [3, 3, 3])
     self.assertEqual(new_group._donor_raw['Joe'].name, 'Joe')
Пример #9
0
 def test_thankyou(self):
     test_text = 'Thank you so much for the generous gift of $5.00, Shane!'
     new_group = d.Group(d.Individual('Shane', [5]))
     self.assertEqual(d.Individual('Shane', [5]).thank_you, test_text)
Пример #10
0
 def test_Group_Add(self):
     """Test that the new donors are being appended to the donor list."""
     new_group = d.Group(d.Individual('Joe', [3, 3, 3]))
     new_group.add('Jill', 5)
     self.assertEqual(new_group._donor_raw['Jill'].name, 'Jill')
     self.assertEqual(new_group._donor_raw['Jill'].donations, [5])
Пример #11
0
 def test_sum_donations(self):
     new_group = d.Group(d.Individual('Shane', [3]))
     new_group.add('Joe', 3)
     new_group.add('Joe', 3)
     new_group.add('Joe', 3)
     self.assertEqual(new_group._donor_raw['Joe'].sum_donations(), 9)
Пример #12
0
 def test_Group_search1(self):
     """Returns None when name does not exist"""
     new_group = d.Group(d.Individual('Joe', [3, 3, 3]))
     self.assertEqual(new_group.search('Bob'), None)
Пример #13
0

def quit_program():
    sys.exit()


if __name__ == '__main__':

    mail = d.Group.json_load()
    try:
        getattr(mail, '_donor_raw')
    except AttributeError:
        print('The database was empty, please add a donor:')
        name = input('\nName:')
        amount = input('\nAmount:')
        mail = d.Group(d.Individual(name, [float(amount)]))

    switch_dict = {
        '1': more_choices,
        '2': print_report,
        '3': letters_for_all,
        '4': run_projections,
        '5': load_database,
        '6': save_database,
        '7': quit_program
    }
    while True:
        response = input('\nChoose an Action:\n'
                         '1 - Send a Thank You\n'
                         '2 - Create a Report\n'
                         '3 - Send letters to everyone\n'
Пример #14
0
 def test_avg_donations(self):
     new_group = d.Group(d.Individual('Shane', [3]))
     new_group.add('Joe', 10)
     new_group.add('Joe', 5)
     new_group.add('Joe', 6)
     self.assertEqual(new_group._donor_raw['Joe'].avg_donations(), 7)
Пример #15
0
 def test_column_average_width(self):
     new_group = d.Group(d.Individual('Shane', [3]))
     donors_f = {'Joe': [9, 3, 3], 'Jack': [9, 2, 4.5]}
     self.assertEqual(new_group.column_average_width(donors_f), 12)
Пример #16
0
 def test_column_number_width_1(self):
     new_group = d.Group(d.Individual('Shane', [3]))
     donors_f = {'Joe': [9, 33333333333333, 35555], 'Jack': [9, 2, 4.5]}
     self.assertEqual(new_group.column_number_width(donors_f), 17)
Пример #17
0
 def test_Group_search2(self):
     """Returns 'name' when name does exist"""
     new_group = d.Group(d.Individual('Joe', [3, 3, 3]))
     self.assertEqual(new_group.search('Joe'), 'Joe')
Пример #18
0
import os
import donors as d

mail = d.Group(d.Individual('Shane', [200]))


def more_choices():
    while True:
        name = input('\nChoose an Option: \n'
                     'e - to exit\n'
                     'list -To see a list of names, or\n'
                     'Type a name to start your thank you letter >>')
        if name == 'e':
            return
        if name == 'list':
            mail.print_donors()
        else:
            print('\n'
                  'Ok, you want to write a letter for {}, '
                  'lets see what we can do.'.format(name))

            if mail.search(name) is None:
                yes_no = input('The name you entered is not in the database.'
                               'Would you like to add this name? y or n >>')
                if yes_no == 'n':
                    return

            amount = input('\n'
                           'What is the donation amount? or '
                           '\'e\' to exit >')
            if amount == 'e':
Пример #19
0
 def test_number_donations(self):
     new_group = d.Group(d.Individual('Shane', [3]))
     new_group.add('Joe', 1)
     new_group.add('Joe', 4)
     new_group.add('Joe', 5)
     self.assertEqual(new_group._donor_raw['Joe'].number_donations(), 3)