コード例 #1
0
 def test_Sum_Donations(self):
     """Test Individual.Sum_Donations"""
     individual = d.Individual(self.__class__.people_collection)
     result = self.__class__.people_collection.find_one({"donor": "Joe"})
     sum_ind = sum(result['donations'])
     log.info(f"The sum of Joe's donations is {sum_ind}")
     self.assertEqual(sum_ind, individual.sum_donations('Joe'))
コード例 #2
0
 def test_Number_Donations(self):
     """Test Individual.Number_of_Donations"""
     individual = d.Individual(self.__class__.people_collection)
     number = individual.number_donations('Shane')
     result = self.__class__.people_collection.find_one({"donor": "Shane"})
     donations = result['donations']
     self.assertEqual(number, len(donations))
コード例 #3
0
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)))
コード例 #4
0
 def test_Individual_Add_Donation1(self):
     """Test Add_Donation when donor does not exist"""
     # pass db instance to Individulal Class Instance
     individual = d.Individual(self.__class__.people_collection)
     individual.add_donation('Luke', 5)
     result = self.__class__.people_collection.find_one({"donor": "Luke"})
     aperson = result['donor']
     adonation = result['donations']
     self.assertEqual(aperson, 'Luke')  # Test donor was added
     self.assertEqual(adonation[0], 5)  # Test donation was added for Luke
コード例 #5
0
 def test_Individual_Add_Donation2(self):
     """Test Add_Donation when it is an existing donor."""
     # pass db instance to Individulal Class Instance
     individual = d.Individual(self.__class__.people_collection)
     individual.add_donation('Shane', 500)
     result = self.__class__.people_collection.find_one({"donor": "Shane"})
     aperson = result['donor']
     adonation = result['donations']
     self.assertEqual(aperson, 'Shane')  # Test donor was added
     self.assertEqual(adonation,
                      [6, 5, 10, 500])  # Test donation was added for Luke
コード例 #6
0
 def test_delete_donor(self):
     """Test delete_donor"""
     individual = d.Individual(self.__class__.people_collection)
     log.info(f"Show that we can find donor.")
     result = self.__class__.people_collection.find_one({"donor": "Pete"})
     self.assertEqual(result['donor'], 'Pete')
     # Delete the document
     individual.delete_donor('Pete')
     # Show that we can no longer find entry
     result = self.__class__.people_collection.find_one({"donor": "Pete"})
     self.assertEqual(result, None)
コード例 #7
0
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)
コード例 #8
0
 def test_Last_Donation(self):
     """Test Individual.last_donation"""
     individual = d.Individual(self.__class__.people_collection)
     result = self.__class__.people_collection.find_one({"donor": "Joe"})
     last_donation = result['donations'][-1]
     self.assertEqual(last_donation, individual.last_donation('Joe'))