Exemplo n.º 1
0
def put_info():
    data, code = verify_admin_token()
    if code != 202:
        return make_response(jsonify(data), code)

    args, code = validate_request_query()
    if code != 202:
        return make_response(jsonify(args), code)
    data, code = validate_request_body()
    if code != 202:
        return make_response(jsonify(data), code)

    try:
        schema.validate('info', data)
    except error.ValidationError as e:
        return make_response(jsonify(make_error_data(e)), 400)

    try:
        data = schema.convert_instance_formatted_properties_from_json(
            'info', data)
        data = sql.update_by_id('info', 1, data)
        data = schema.convert_instance_formatted_properties_to_json(
            'info', data)
        code = 200
    except error.NotFoundError as e:
        data = make_error_data(e)
        code = 404
    except error.DBError as e:
        data = make_error_data(e)
        code = 500

    return make_response(jsonify(data), code)
Exemplo n.º 2
0
def post_test():
    args, code = validate_request_query()
    if code != 202:
        return make_response(jsonify(args), code)
    data, code = validate_request_body()
    if code != 202:
        return make_response(jsonify(data), code)

    try:
        schema.validate('subscriber', data)
    except error.ValidationError as e:
        return make_response(jsonify(make_error_data(e)), 400)

    try:
        data = schema.convert_instance_formatted_properties_from_json(
            'subscriber', data)
        data = sql.insert('subscriber', data)
        data = schema.convert_instance_formatted_properties_to_json(
            'subscriber', data)
        code = 201
    except error.NotFoundError as e:
        data = make_error_data(e)
        code = 404
    except error.DBError as e:
        data = make_error_data(e)
        code = 500

    return make_response(jsonify(data), code)