def update_customer_credit(customer_id, credit_limit): '''updated customer credit limit based on customer id''' try: update_limit = Customer.get(Customer.customer_id == customer_id) update_limit.credit_limit = credit_limit LOGGER.info("%s's credit has succesfully been updated to %s", update_limit.customer_id, update_limit.credit_limit) update_limit.save() except DoesNotExist: LOGGER.info('Customer does not exist in the system') raise ValueError
def delete_customer(customer_id): '''deletes a customer based on customer id''' try: deletion = Customer.get(Customer.customer_id == customer_id) LOGGER.info('Deleting Customer ID %s from the customer database', deletion.customer_id) deletion.delete_instance() LOGGER.info('delete_customer: Customer successfully deleted') except DoesNotExist: LOGGER.info('Customer does not exist in the system') raise ValueError
def add_customer(customer_id, name, last_name, home_address, phone_number, email_address, status, credit_limit): '''function to add a new customer to the database''' new_customer = Customer.create(customer_id=customer_id, name=name, last_name=last_name, home_address=home_address, phone_number=phone_number, email_address=email_address, status=status, credit_limit=credit_limit) LOGGER.info('Added %s to the customer database', new_customer.name) new_customer.save()
def test_update_customer_credit(self): '''tests updating a customers credit''' db_setup() add_customer(1234, 'Zach', 'Thomson', '1000 John St', '2068675309', '*****@*****.**', True, 1000.00) #test credit update success update_customer_credit(1234, 2000.00) new_credit = Customer.get(Customer.customer_id == 1234) self.assertEqual(new_credit.credit_limit, 2000.00) #test credit update failure self.assertRaises(ValueError, update_customer_credit, 9000, 10.00)
def search_customer(customer_id): '''return a dictionary with customer information based on customer id''' search_dict = {} try: search = Customer.get(Customer.customer_id == customer_id) search_dict['name'] = search.name search_dict['last_name'] = search.last_name search_dict['email_address'] = search.email_address search_dict['phone_number'] = search.phone_number LOGGER.info('search_customer: Search completed') return search_dict except DoesNotExist: LOGGER.info('search_customer: Customer is not in the system') return search_dict
def search_customer(customer_id): '''return a dictionary with customer information based on customer id''' try: search = Customer.get(Customer.customer_id == customer_id) keys = ['name', 'last_name', 'email_address', 'phone_number'] values = [ search.name, search.last_name, search.email_address, search.phone_number ] search_dict = dict(zip(keys, values)) LOGGER.info('search_customer: Search completed') return search_dict except DoesNotExist: LOGGER.info('search_customer: Customer is not in the system') return dict()
def test_add_customer(self): '''test add customer function''' db_setup() add_customer(1234, 'Zach', 'Thomson', '1000 John St', '2068675309', '*****@*****.**', True, 1000.00) generic = Customer.get(Customer.customer_id == 1234) self.assertEqual(generic.customer_id, 1234) self.assertEqual(generic.name, 'Zach') self.assertEqual(generic.last_name, 'Thomson') self.assertEqual(generic.home_address, '1000 John St') self.assertEqual(generic.phone_number, '2068675309') self.assertEqual(generic.email_address, '*****@*****.**') self.assertEqual(generic.status, True) self.assertEqual(generic.credit_limit, 1000.00)