def test_summary(self):
        """Test dictionary set with {Donor: Total, number of donations,
#        and average donation amount}"""
        # Delete test.db collection of people first to start fresh
        log.info('First delete the test_collection so we can start over.')
        self.__class__.db.drop_collection('people')

        # Make a new collection called 'people'.
        log.info('In the test_db use a collection called people')
        log.info('If it doesnt exist mongodb creates it')
        people_collection = self.__class__.db['people']

        # Load the collection 'test_people' from the Load_Tables.py file.
        log.info('Populate the database with people.')
        people_collection.insert_many(people)
        log.info('Completed loading donors')

        # Start the test routine
        group = d.Group(self.__class__.people_collection)
        result = group.summary()
        test_against = {
            'Shane': [21, 3, 7.0],
            'Joe': [15, 5, 3.0],
            'Zach': [10, 1, 10.0],
            'Pete': [15, 2, 7.5],
            'Fitz': [1, 1, 1.0]
        }
        self.assertDictEqual(result, test_against)
    def test_print_donors(self):
        """Prints all the people in the database"""

        # Delete test.db collection of people first to start fresh
        log.info('First delete the test_collection so we can start over.')
        self.__class__.db.drop_collection('people')

        # Make a new collection called 'people'.
        log.info('In the test_db use a collection called people')
        log.info('If it doesnt exist mongodb creates it')
        people_collection = self.__class__.db['people']

        # Load the collection 'test_people' from the Load_Tables.py file.
        log.info(
            'Populate the database with people. MongoDB is non-relational so'
            'the donors and the donations should be kept together.')
        people_collection.insert_many(people)
        log.info('Completed loading donors')

        # Start the test routine
        group = d.Group(self.__class__.people_collection)
        result = collections.Counter(group.print_donors())
        expected = collections.Counter(
            ['Shane', 'Zach', 'Joe', 'Pete', 'Fitz'])
        self.assertEqual(result, expected)
    def test_Group_search2(self):
        """Returns 'name' when name does exist. We start with a new
        collection of people so we know what we start with."""

        group = d.Group(self.__class__.people_collection)
        result = group.search('Shane')  # Bob is not in database
        self.assertEqual(result, 'Shane')
def more_choices():
    client = login_database.login_mongodb_cloud()
    db = client['mailroom']
    people_collection = db['people']
    mail = d.Group(people_collection)
    individual = d.Individual(people_collection)
    r = login_database.login_redis_cloud()

    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 >>\n')
                if yes_no == 'n':
                    return

                if yes_no == 'y':
                    last_name = input(f"What is {name}'s last name?\n")
                    email = input(f"What is {name}'s email?\n")
                    telephone = input(f"What is {name}'s telephone #?\n")
                    d.Individual.redis_add_new(r,
                                               name,
                                               last_name,
                                               telephone,
                                               email)
                else:
                    return
            print(f"First confirm {name}'s information")
            individual.donor_verification(r, name)
            confirm_info = input("Does the donor info look ok? y or n >>\n")
            if confirm_info == 'n':
                update_redis(r, name)
            amount = input('\n''What is the donation amount? or '
                           '\'e\' to exit >')
            if amount == 'e':
                return
            try:
                if int(amount) <= 0:
                    print('\nYou entered an invalid amount!!\n')
                    return
            except ValueError:
                print('\nYou entered an invalid amount!!\n')
                return ValueError
            else:
                individual.add_donation(name, float(amount))
                print(individual.thank_you(name, float(amount)))
def letters_for_all():
    client = login_database.login_mongodb_cloud()
    db = client['mailroom']
    people_collection = db['people']
    mail = d.Group(people_collection)
    path_letters = os.getcwd()
    print(f"You chose to send letters for everyone. "
          f"The letters have been completed and you "
          f"can find them here: {path_letters}")
    mail.letters()
def delete_donor():
    client = login_database.login_mongodb_cloud()
    db = client['mailroom']
    people_collection = db['people']
    mail = d.Group(people_collection)
    individual = d.Individual(people_collection)
    while True:
        name = input('\nWhich donor would you like to delete? \n'
                     'e - to exit\n'
                     'list To see a list of names, or\n'
                     'Type the name of the donor to delete.>>')
        if name == 'e':
            return
        if name == 'list':
            mail.print_donors()
        else:
            print('\n''Ok, you want to delete {}, '
                  'lets see what we can do.'.format(name))

            if mail.search(name) is None:
                print('The name you entered is not in the database.')
                return
            else:
                individual.delete_donor(name)
def print_report():
    client = login_database.login_mongodb_cloud()
    db = client['mailroom']
    people_collection = db['people']
    mail = d.Group(people_collection)
    print(mail.report())
 def test_Group_search1(self):
     """Returns None when name does not exist"""
     group = d.Group(self.__class__.people_collection)
     result = group.search('Bob')  # Bob is not in database
     self.assertEqual(result, None)