示例#1
0
def test_get_customer(customer_repository):
    customer = Customer(customer_id=1234, first_name='Gene', surname='Kim')
    customer_repository.store(customer)

    result = commands.get_customer(customer_id=1234,
                                   customer_repository=customer_repository)

    assert result is customer
def get_customer(customer_id):
    customer_repository = current_app.customer_repository

    customer = commands.get_customer(customer_id=customer_id,
                                     customer_repository=customer_repository)

    return jsonify(customerId=customer.customer_id,
                   firstName=customer.first_name,
                   surname=customer.surname)
示例#3
0
def update_customer():
    customer_repository = current_app.customer_repository

    if not request.is_json:
        raise ContentTypeError()

    body = request.get_json()
    UPDATE_SURNAME_SCHEMA.validate(body)
    customer = commands.get_customer(body['customer_id'], customer_repository)
    commands.update_customer(customer, customer_repository, body['surname'])
    return jsonify(customerId=str(customer.customer_id),
                   surname=customer.surname), HTTPStatus.CREATED
def update_customer(customer_id, surname):

    customer_repository = current_app.customer_repository

    customer = commands.get_customer(customer_id=int(customer_id),
                                     customer_repository=customer_repository)

    customer.surname = surname

    commands.update_customer(customer=customer,
                             customer_repository=customer_repository)

    return jsonify(customerId=str(customer.customer_id),
                   firstName=customer.first_name,
                   surname=customer.surname), HTTPStatus.CREATED
示例#5
0
def update_surname(customer_id):
    customer_repository = current_app.customer_repository

    if not request.is_json:
        raise ContentTypeError()

    body = request.get_json()

    commands.update_surname(customer_id=int(customer_id),
                            new_surname=body['newSurname'],
                            customer_repository=customer_repository)

    customer = commands.get_customer(customer_id=int(customer_id),
                                     customer_repository=customer_repository)

    return jsonify(customerId=str(customer_id),
                   firstName=customer.first_name,
                   surname=customer.surname), HTTPStatus.ACCEPTED
示例#6
0
def test_get_customer_when_customer_does_not_exist(customer_repository):
    with pytest.raises(CustomerNotFound):
        commands.get_customer(customer_id=99999,
                              customer_repository=customer_repository)