Exemplo n.º 1
0
def delete_customer(customer_id):
    '''
    Deletes a customer if it exists, otherwise throws DoesNotExist error

    :param customer_id: customer_id to search and delete
    '''
    customer = Customer.get(Customer.customer_id == customer_id)
    customer.delete_instance()
def test_list_active_customers():
    ''' test list_active_customers count '''
    result = bo.list_active_customers()
    assert result == len(customer_id_list)
    customer = Customer.get(Customer.customer_id == "active_customers")
    customer.status = False
    customer.save()

    result = bo.list_active_customers()
    assert result == len(customer_id_list) - 1
def test_add_customer_ok():
    ''' Add a new valid customer '''
    customer_id = "add_ok"
    ok_customer = dict(customer_data)
    ok_customer['customer_id'] = customer_id
    bo.add_customer(**ok_customer)

    result = Customer.get(Customer.customer_id == customer_id)
    assert result.first_name == ok_customer["name"]
    assert result.last_name == ok_customer["lastname"]
    assert result.home_address == ok_customer["home_address"]
    assert result.phone_number == ok_customer["phone_number"]
    assert result.email_address == ok_customer["email_address"]
    assert result.status == ok_customer["status"]
    assert result.credit_limit == float(ok_customer["credit_limit"])
Exemplo n.º 4
0
def search_customer(customer_id):
    '''
    Search for a customer

    :param customer_id: customer id to search for
    '''

    try:
        customer = Customer.get(Customer.customer_id == customer_id)
        return {
            "name": customer.first_name,
            "lastname": customer.last_name,
            "email_address": customer.email_address,
            "phone_number": customer.phone_number
        }
    except DoesNotExist:
        return {}
Exemplo n.º 5
0
def search_customer(customer_id=None):
    '''
    Search for a customer

    :param customer_id: customer id to search for
    '''

    try:
        customer = Customer.get(Customer.customer_id == customer_id)
        keys = ("name", "lastname", "email_address", "phone_number")
        values = ("first_name", "last_name", "email_address", "phone_number")
        return {
            key: getattr(customer, value)
            for key, value in zip(keys, values)
        }
    except pw.DoesNotExist:
        logging.info(f"Customer not found: {customer_id}")
        return {}
Exemplo n.º 6
0
def update_customer_credit(customer_id, credit_limit):
    '''
    Updates the customer credit amount

    :param customer_id: customer id to search and update
    :param credit_limit: credit limit value to change to
    '''
    try:
        credit_limit = float(credit_limit)
    except ValueError as err:
        logging.error(err)
        raise

    try:
        customer = Customer.get(Customer.customer_id == customer_id)
    except DoesNotExist:
        logging.info(f"Customer does not exist: {customer_id}")
        raise ValueError(f"Customer_id does not exist: {customer_id}")

    customer.credit_limit = credit_limit
    customer.save()