def search_customer(customer_id): """ Search for customer name in database :return: Customer info if Ture, empty dict if None :param customer_id: customer_id to search for """ find_customer_dict = {} LOGGER.info("Search for customer name in database...") try: find_customer = Customer.get(Customer.customer_id == customer_id) if find_customer: find_customer_dict = { "first_name": find_customer.first_name, "last_name": find_customer.last_name, "email_address": find_customer.email_address, "phone_number": find_customer.phone_number } LOGGER.info('%s %s is in the database. There phone # is %s', find_customer.first_name, find_customer.last_name, find_customer.phone_number) except pw.DoesNotExist: LOGGER.info('No customer with customer id of %s', Customer.customer_id) return find_customer_dict
def delete_customer(customer_id): """ :param customer_id: :param stage: :return: """ customer = Customer.get(Customer.customer_id == customer_id) customer.delete_instance()
def delete_customer(id=None): delete_customer = Customer.get(Customer.id == id) logging.info( " Make sure that this customer will be deleted from our database") if delete_customer: delete_customer.delete_instance() delete_customer.save() else: logging.error(f"We could not delete {first_name} from the database") raise ValueError("Customer not found")
def update_customer_credit(id, credit_limit): update_custumer = Customer.get(Customer.id == id) if update_customer: update_customer.credit_limit = credit_limit update_customer.save() else: raise ValueError logging.info(error) logging.info(f"We could not update {first_name} from the database") database.close()
def search_customer(id=None): try: find_customer_model = Customer.get(Customer.id == id) except pw.DoesNotExist as err: logging.error(err) find_customer_dict = {} else: find_customer_dict = model_dictionary(find_customer_model) return find_customer_dict
def test_add_ok_customer(): customer_id = 'W3434' name = 'Tim' last_name = 'Pauley' home_address = '1234 Queen Anne Ave N Seattle, Wa 98019' phone_number = '206-123-4567' email_address = '*****@*****.**' status = True credit_limit = '40,0000' add_customer( customer_id ,name ,last_name ,home_address ,email_address ,status ,credit_limit ) Customer.get(Customer.customer_id=customer_id) assert(test_customer.email_address = email_address)
def update_customer_credit(customer_id, credit_limit): """ :param customer_id: :param credit_limit: :param stage: :return: """ customer = Customer.get(Customer.customer_id == customer_id) update = customer.update(credit_limit=credit_limit) update.execute()
def delete_customer(customer_id): try: acustomer = Customer.get(Customer.customer_id == customer_id) logging.info( " Make sure that this customer will be deleted from our database") acustomer.delete_instance() acustomer.save() except Exception as e: logging.info(e) return output_dict database.close()
def search_customer(customer_id): """ :param customer_id: :param stage: :return: """ try: results = Customer.get(Customer.customer_id == customer_id) except Exception: return False return results
def update_customer_credit(customer_id, credit_limit): """ Updates the customer credit limit :param cusomer_id: credit_limit to update new limit """ LOGGER.info("Updating customer credit limit") try: customer = Customer.get(Customer.customer_id == customer_id) customer.credit_limit = credit_limit customer.save() except pw.DoesNotExist: LOGGER.error("Customer_id of %s does not exist", customer_id)
def delete_customer(customer_id, stage='prod'): """ :param customer_id: :param stage: :return: """ if stage == 'prod': customer = Customer.get(cm.customer_id == customer_id) customer.delete_instance() if stage == 'dev': customer = TestCustomer.get(TestCustomer.customer_id == customer_id) customer.delete_instance()
def delete_customer(customer_id): """ Deletes customer from database :return: empty dict if custome doesnt exist :param customer_id: customer_id to search and delete for """ LOGGER.info("Creating new customer named Tom and then deleting him") try: customer_remove = Customer.get(Customer.customer_id == customer_id) customer_remove.delete_instance() except pw.DoesNotExist: return None LOGGER.info("Customer successfully deleted in database")
def search_customer(customer_id): output_dict = {} try: acustomer = Customer.get(Customer.customer_id == customer_id) logging.info(" A customer search from the database") output_dict['first_name'] = acustomer.first_name output_dict['last_name'] = acustomer.last_name output_dict['email_address'] = acustomer.email_address output_dict['phone_number'] = acustomer.phone_number acustomer.save() except Exception as e: logging.info(e) return output_dict database.close()
def update_customer_credit(customer_id, credit_limit, stage='prod'): """ :param customer_id: :param credit_limit: :param stage: :return: """ if stage == 'prod': customer = Customer.get(cm.customer_id == customer_id) update = customer.update(credit_limit=credit_limit) update.execute() if stage == 'dev': customer = TestCustomer.get(TestCustomer.customer_id == customer_id) update = customer.update(credit_limit=credit_limit) update.execute()
def search_customer(customer_id, stage='prod'): """ :param customer_id: :param stage: :return: """ try: if stage == 'prod': results = Customer.get(cm.customer_id == customer_id) if stage == 'dev': results = TestCustomer.get(TestCustomer.customer_id == customer_id) except Exception: return False return results
def test_add_ok_customer(): add_customer(**ok_customer) test_customer = Customer.get(Customer.customer_id==ok_customer['customer_id']) assert test_customer.email_address == ok_customer['email_address']
def update_customer_credit(customer_id, credit_limit): acustumer = Customer.get(Customer.customer_id == customer_id) acustumer.credit_limit = credit_limit acustomer.save()
first_name = name, last_name = last_name, home_address = home_address, phone_number = phone_number, email_address = email_address, status = status, credit_limit = credit_limit) new_customer.save() logger.info('Database add successful') 'This is to serach customer' logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) logger.info('Working with Customer class to search, find') logger.info('Find and display by selecting with one Customer name...') acustomer = Customer.get(Customer.customer_name == 'John') logger.info(f'{acustomer.first_name} and {acustomer.last_name}, the customer address id is {acustomer.customer_id}, the customer ' + \ f' and home address is {acustomer.home_address} and phone number is {acustomer.phone_number}, email is {acustomer.email_address}) + \ f' status is {acustomer.status} with credit limit is {acustomer.credit_limit}, email is {acustomer) logger.info('Our customer class inherits select(). Specify search with .where()') database.close() 'This is to delete customer ' def delete_customer(first_name): if first_name == 'John': delete_customer.delete() logger.info('Reading and print all Customer records (but not John; he has been deleted)...') for customer in Customer:
'''This is to test the basic operations '''