Ejemplo n.º 1
0
 def test_validate_and_create_thank_you_bad_name(self):
     dc = DonorCollection()
     output = dc.validate_and_create_thank_you(self.bad_name,
                                               self.good_amount)
     self.assertEqual(
         output,
         'Could not send thank you.  The first and last name of donor must be provided\n'
     )
Ejemplo n.º 2
0
    def test_write_letters(self):
        dc = DonorCollection()
        donation_count = 0
        for donor in dc.donor_list:
            donation_count += len(donor.amount_list)
        dc.write_letters()
        letter_list = [
            f for f in os.listdir(dc.letter_directory) if '.txt' in f
        ]

        self.assertEqual(donation_count, len(letter_list))
Ejemplo n.º 3
0
    def test_validate_and_create_thank_you_good_values(self):
        d = Donor(self.good_name, [500, 100, 200])
        dc = DonorCollection([d])

        amount_list = d.amount_list[:]
        amount_list.append(float(self.good_amount))

        output = dc.validate_and_create_thank_you(self.good_name,
                                                  self.good_amount)
        #print('\n' + output)
        #print(f"Hi {self.good_name}\nThank you for your donation of {self.good_amount} to the mailroom!\n")
        #self.assertEqual(output == f"Hi {self.good_name}\nThank you for your donation of {self.good_amount} to the mailroom!\n"

        self.assertEqual(amount_list, d.amount_list)
Ejemplo n.º 4
0
    def test_validate_and_create_thank_you_good_values(self):
        dc = DonorCollection()
        d = Donor(self.good_name)

        amount_list = dc.donation_dict.get(self.good_name, [])
        amount_list.append(float(self.good_amount))

        output = dc.validate_and_create_thank_you(self.good_name,
                                                  self.good_amount)
        #print('\n' + output)
        #print(f"Hi {self.good_name}\nThank you for your donation of {self.good_amount} to the mailroom!\n")
        #self.assertEqual(output == f"Hi {self.good_name}\nThank you for your donation of {self.good_amount} to the mailroom!\n"

        new_amount_list = dc.donation_dict[self.good_name]
        self.assertEqual(amount_list, new_amount_list)
Ejemplo n.º 5
0
        else:
            return True
    except ValueError as e:
        return False


if __name__ == '__main__':

    example_list = [
        Donor('Fred Smith'),
        Donor('Terrie Ann'),
        Donor('Murray Martin'),
        Donor('Josh Jones'),
        Donor('Jane Doe')
    ]
    dc = DonorCollection(example_list)
    # prompt user for action and then call function
    action = 0
    while not isinstance(action, int) or int(action) != 4:
        prompt_message = 'What would you like to do: '
        prompt_message += '1 - \“Send a Thank You\” or '
        prompt_message += '2 - \“Create a Report\” or '
        prompt_message += '3 - \"Send letters to everyone\" or '
        prompt_message += '4 - \"Donation Challenge\" or 5 - \“quit\”\n'
        action = input(prompt_message)

        action_dict = {
            1: dc.send_thank_you,
            2: dc.create_report,
            3: dc.write_letters,
            4: dc.donation_challenge,
Ejemplo n.º 6
0
 def test_validate_and_create_thank_you_bad_amount(self):
     dc = DonorCollection()
     output = dc.validate_and_create_thank_you(self.good_name,
                                               self.bad_amount)
     self.assertEqual(output, f"invalid donation amount: {self.bad_amount}")
Ejemplo n.º 7
0
def validate_user_selection(action, action_dict):
    """ validate the user selection versus available actions """

    key_list = list(action_dict.keys())
    try:
        if int(action) not in key_list:
            return False
        else:
            return True
    except ValueError as e:
        return False


if __name__ == '__main__':

    dc = DonorCollection()

    # prompt user for action and then call function
    action = 0
    while not isinstance(action, int) or int(action) != 4:
        prompt_message = 'What would you like to do: '
        prompt_message += '1 - \“Send a Thank You\”, '
        prompt_message += '2 - \“Create a Report\” or '
        prompt_message += '3 - \"Send letters to everyone\" or 4 - \“quit\”\n'
        action = input(prompt_message)

        action_dict = {
            1: dc.send_thank_you,
            2: dc.create_report,
            3: dc.write_letters,
            4: exit
        if int(action) not in key_list:
            return False
        else:
            return True
    except ValueError as e:
        return False


if __name__ == '__main__':

    init_message = "Would you like to (1) load existing data or (2) load default data? "
    data_init = input(init_message)
    donor_list = []

    if int(data_init) == 1:
        dc = DonorCollection()
        dc.load_donor_collection()
        print(dc.donor_list)

    if int(data_init) == 2 or (dc is not None and len(dc.donor_list) == 0):
        donor_list = [
            Donor('Fred Smith'),
            Donor('Terrie Ann'),
            Donor('Murray Martin'),
            Donor('Josh Jones'),
            Donor('Jane Doe')
        ]
        dc = DonorCollection(donor_list)

    # prompt user for action and then call function
    action = 0