def test_can_update_connection_type(db, testapp, connection_payload):
    connection = ConnectionFactory.create(
        connection_type=ConnectionType.father.value)
    db.session.commit()

    res = testapp.patch('/connections/' + str(connection.id),
                        json=connection_payload)

    assert res.status_code == HTTPStatus.OK
    assert res.json['connection_type'] == connection_payload['connection_type']
def test_update_connection_type_validations(db, testapp, connection_payload,
                                            field, value, error_message):
    connection = ConnectionFactory.create(
        connection_type=ConnectionType.father)
    db.session.commit()

    connection_payload[field] = value

    res = testapp.patch('/connections/' + str(connection.id),
                        json=connection_payload)

    assert res.status_code == HTTPStatus.BAD_REQUEST
    assert res.json['description'] == 'Input failed validation.'
    errors = res.json['errors']
    assert error_message in errors[field]