Exemple #1
0
def test_update_customer(customer_repository):
    customer1 = Customer(customer_id=123456,
                         first_name='Rudi',
                         surname='Joyel')
    customer2 = Customer(customer_id=12345,
                         first_name='Nicole',
                         surname='Forsgren')
    customer_repository.store(customer1)
    customer_repository.store(customer2)

    commands.update_customer(customer_id=123456,
                             surname="Jack",
                             customer_repository=customer_repository)

    commands.update_customer(customer_id=12345,
                             surname="Woods",
                             customer_repository=customer_repository)

    updated_customer1 = customer_repository.fetch_by_id(123456)
    updated_customer2 = customer_repository.fetch_by_id(12345)

    assert updated_customer1.first_name == "Rudi"
    assert updated_customer1.surname == "Jack"

    assert updated_customer2.first_name == "Nicole"
    assert updated_customer2.surname == "Woods"
def update_customer():
    body = request.get_json()
    customer_repository = current_app.customer_repository

    commands.update_customer(customer_repository=customer_repository,
                             customer_id=int(body['customer_id']),
                             surname=body['surname'])

    return jsonify(), HTTPStatus.OK
Exemple #3
0
def update_customer_name(customer_id):
    customer_repository = current_app.customer_repository
    body = request.get_json()

    commands.update_customer(first_name=body['firstName'],
                             surname=body['surname'],
                             customer_id=int(customer_id),
                             customer_repository=customer_repository)

    return jsonify(), HTTPStatus.OK
Exemple #4
0
def update_customer():
    customer_repository = current_app.customer_repository

    body = request.get_json()

    UPDATE_PAYLOAD_SCHEMA.validate(body)

    commands.update_customer(customer_id=body['customer_id'],
                             surname=body['surname'],
                             customer_repository=customer_repository)

    return '', HTTPStatus.OK
Exemple #5
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
Exemple #6
0
def update_customer(customer_id):
    customer_repository = current_app.customer_repository

    if not request.is_json:
        raise ContentTypeError()

    body = request.get_json()

    # CREATE_PAYLOAD_SCHEMA.validate(body)

    commands.update_customer(body['surname'], customer_id, customer_repository)

    return jsonify(customerId=str(customer_id), surname=body['surname']), 200
Exemple #7
0
def test_update_customer(customer_repository):
    customer = Customer(customer_id=12345,
                        first_name='Nicole',
                        surname='Forsgren')
    customer_repository.store(customer)

    commands.update_customer(surname='Bloggs',
                             customer_id=12345,
                             customer_repository=customer_repository)

    stored_customer = customer_repository.fetch_by_id(customer.customer_id)

    assert stored_customer.surname == 'Bloggs'
def test_update_customer(customer_repository):
    customer = Customer(first_name='Gene', surname='Kim')
    customer_repository.store(customer)

    commands.update_customer(customer_id=customer.customer_id,
                             customer_repository=customer_repository,
                             first_name='Gene',
                             surname='Wilder')

    stored_customer = customer_repository.fetch_by_id(customer.customer_id)

    assert stored_customer.first_name == 'Gene'
    assert stored_customer.surname == 'Wilder'
Exemple #9
0
def update_customer(customer_id):
    customer_repository = current_app.customer_repository

    body = request.get_json()

    commands.update_customer(first_name=body['firstName'],
                             surname=body['surname'],
                             cid=body['cid'],
                             customer_repository=customer_repository)

    return jsonify(
        dict(firstName=body['firstName'],
             surname=body['surname'],
             cid=body['cid']))
Exemple #10
0
def test_update_customer(customer_repository):
    customer = Customer(first_name='Nicole', surname='Forsgren')

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

    commands.update_customer(customer=customer,
                             customer_repository=customer_repository,
                             surname="Doe")

    stored_customer = customer_repository.fetch_by_id(customer.customer_id)

    assert stored_customer.first_name == 'Nicole'
    assert stored_customer.surname == 'Doe'
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
def test_update_customer(customer_repository):

    customer = Customer(customer_id=12345, first_name='Gene', surname='Kim')

    customer_repository.store(customer)

    commands.update_customer(
        customer_id=12345,
        first_name='Nicole',
        surname='Forsgren',
        customer_repository=customer_repository)

    stored_customer = customer_repository.fetch_by_id(12345)

    assert stored_customer.first_name == 'Nicole'
    assert stored_customer.surname == 'Forsgren'
def update_customer(customer_id):
    customer_repository = current_app.customer_repository

    if not request.is_json:
        raise ContentTypeError()

    body = request.get_json()

    UPDATE_PAYLOAD_SCHEMA.validate(body)

    commands.update_customer(customer_id=int(customer_id),
                             first_name=body['firstName'],
                             surname=body['surname'],
                             customer_repository=customer_repository)

    return jsonify(customerId=str(customer_id),
                   firstName=body['firstName'],
                   surname=body['surname']), HTTPStatus.OK
Exemple #14
0
def update_customer(customer_id):
    customer_repository = current_app.customer_repository

    if not request.is_json:
        raise ContentTypeError()

    body = request.get_json()

    customer = Customer(first_name=body['firstName'], surname=body['surname'])

    commands.update_customer(customer_id=customer_id,
                             customer_repository=customer_repository,
                             first_name=customer.first_name,
                             surname=customer.surname)

    return jsonify(customerId=str(customer.customer_id),
                   firstName=customer.first_name,
                   surname=customer.surname), HTTPStatus.OK
def test_update_customer(customer_repository):
    # Given customer exists
    existing_customer = Customer(first_name='Nicole', surname='Foresgren')

    customer_repository.store(existing_customer)

    # When customer updated
    customer_id = existing_customer.customer_id
    commands.update_customer(first_name='Bob',
                             surname='Todd',
                             customer_id=customer_id,
                             customer_repository=customer_repository)

    # Then
    updated_customer = customer_repository.fetch_by_id(customer_id)
    assert updated_customer.first_name == 'Bob'
    assert updated_customer.surname == 'Todd'
    assert updated_customer.customer_id == customer_id
def update_customer(customer_id):
    customer_repository = current_app.customer_repository

    # if not request.is_json:
    #     raise ContentTypeError()

    body = request.get_json()

    # CREATE_PAYLOAD_SCHEMA.validate(body)

    #customer = Customer(first_name=body['firstName'],
    #                    surname=body['surname'])

    commands.update_customer(int(customer_id),
                             first_name=body['firstName'],
                             surname=body['surname'],
                             customer_repository=customer_repository)

    return "All Done", HTTPStatus.OK
def update_customer(customer_id):
    customer_repository = current_app.customer_repository
    #
    # if not request.is_json:
    #     raise ContentTypeError()
    #
    body = request.get_json()
    #
    # CREATE_PAYLOAD_SCHEMA.validate(body)
    #
    # customer = commands.get_customer(int(customer_id), customer_repository)
    #
    # customer.first_name = body['firstName']
    # customer.surname = body['surname']
    #
    commands.update_customer(
        customer_id=int(customer_id),
        firstname=body['firstName'],
        surname=body['surname'],
        customer_repository=customer_repository)

    return jsonify(), HTTPStatus.OK
def test_update_customer_name(customer_repository):

    mock_fetch_by_id = MagicMock()
    mock_fetch_by_id.return_value = Customer(customer_id=5,
                                             first_name="Susan",
                                             surname="Davies")

    customer_repository.fetch_by_id = mock_fetch_by_id

    mock_store = MagicMock()
    customer_repository.store = mock_store

    commands.update_customer(customer_id=5,
                             first_name="Bob",
                             surname="Jones",
                             customer_repository=customer_repository)

    mock_fetch_by_id.assert_called_once_with(5)

    store_argument = mock_store.call_args_list[0][0][0]
    assert store_argument.first_name == "Bob"
    assert store_argument.surname == "Jones"
def update_customer(customer_id, first_name, surname):

    if (not first_name.isalpha()) or (not surname.isalpha()) or (
            not customer_id.isnumeric()):
        return jsonify(dict(message='Invalid input')), HTTPStatus.BAD_REQUEST

    customer_repository = current_app.customer_repository

    customer = commands.update_customer(customer_id, first_name, surname,
                                        customer_repository)

    return jsonify(customerID=int(customer.customer_id),
                   firstName=customer.first_name,
                   surname=customer.surname), HTTPStatus.OK
def test_update_customer(customer_repository):
    customer = Customer(customer_id=1234, first_name='Gene', surname='Kim')
    customer_repository.store(customer)

    result = commands.update_customer(cid=customer.customer_id,
                                      first_name=customer.first_name,
                                      surname="Sid",
                                      customer_repository=customer_repository)

    assert result.first_name == 'Gene'
    assert result.surname == 'Sid'

    stored_customer = customer_repository.fetch_by_id(1234)

    assert stored_customer.first_name == 'Gene'
    assert stored_customer.surname == 'Sid'