Esempio n. 1
0
def analyse_patch_request_errors(request_validator: UserRequest,
                                 data: Data,
                                 filename: str,
                                 method_parameters: dict) \
        -> Union[tuple, None]:
    try:
        request_validator.existent_filename_validator(filename)
    except Exception as nonexistent_train_filename:
        return (
            jsonify(
                {Constants.MESSAGE_RESULT: str(nonexistent_train_filename)}),
            Constants.HTTP_STATUS_CODE_NOT_FOUND,
        )

    module_path, class_name = data.get_module_and_class_from_a_executor_name(
        filename)

    class_method = data.get_class_method_from_a_executor_name(filename)
    try:
        request_validator.valid_method_parameters_validator(
            module_path, class_name, class_method, method_parameters)
    except Exception as invalid_function_parameters:
        return (
            jsonify(
                {Constants.MESSAGE_RESULT: str(invalid_function_parameters)}),
            Constants.HTTP_STATUS_CODE_NOT_ACCEPTABLE,
        )

    return None
def analyse_patch_request_errors(request_validator: UserRequest,
                                 filename: str) \
        -> Union[tuple, None]:
    try:
        request_validator.existent_filename_validator(filename)
    except Exception as nonexistent_filename:
        return (
            jsonify({Constants.MESSAGE_RESULT: str(nonexistent_filename)}),
            Constants.HTTP_STATUS_CODE_NOT_FOUND,
        )

    return None
Esempio n. 3
0
def analyse_post_request_errors(request_validator: UserRequest,
                                data: Data,
                                filename: str,
                                parent_name: str,
                                class_method: str,
                                method_parameters: dict) \
        -> Union[tuple, None]:
    try:
        request_validator.not_duplicated_filename_validator(filename)
    except Exception as duplicated_train_filename:
        return (
            jsonify({Constants.MESSAGE_RESULT:
                     str(duplicated_train_filename)}),
            Constants.HTTP_STATUS_CODE_CONFLICT,
        )

    try:
        request_validator.existent_filename_validator(parent_name)
    except Exception as invalid_model_name:
        return (
            jsonify({Constants.MESSAGE_RESULT: str(invalid_model_name)}),
            Constants.HTTP_STATUS_CODE_NOT_ACCEPTABLE,
        )

    module_path, class_name = data.get_module_and_class_from_a_model(
        parent_name)

    try:
        request_validator.valid_method_class_validator(module_path, class_name,
                                                       class_method)
    except Exception as invalid_method_name:
        return (
            jsonify({Constants.MESSAGE_RESULT: str(invalid_method_name)}),
            Constants.HTTP_STATUS_CODE_NOT_ACCEPTABLE,
        )

    try:
        request_validator.valid_method_parameters_validator(
            module_path, class_name, class_method, method_parameters)
    except Exception as invalid_method_parameters:
        return (
            jsonify({Constants.MESSAGE_RESULT:
                     str(invalid_method_parameters)}),
            Constants.HTTP_STATUS_CODE_NOT_ACCEPTABLE,
        )

    return None