Exemple #1
0
    def get_input_validation_error(
            self, data_to_validate: typing.Any) -> ProcessValidationError:
        """
        Return an ProcessValidationError containing validation
        detail error for input data
        :param data_to_validate: data to use to generate validation error
        :return:
        """
        # Prevent serpyco error when Rrequest context give us a MultiDictProxy
        if isinstance(data_to_validate, (MultiDictProxy, MultiDict)):
            data_to_validate = dict(data_to_validate)

        try:
            self.serializer.load(data_to_validate)
            raise WorkflowException(
                "Serializer should raise an exception here")
        except ValidationError as exc:
            return ProcessValidationError(
                message='Validation error of input data: "{}"'.format(
                    exc.args[0]),
                details=exc.args[1],
                original_exception=exc,
            )
        except Exception as exc:
            self._logger.exception(
                'Unknown error during serpyco load: "{}": "{}"'.format(
                    type(exc).__name__, str(exc)))
            return ProcessValidationError(
                message="Unknown error during validation "
                'of input data: "{}": "{}"'.format(
                    type(exc).__name__, str(exc)),
                details={},
                original_exception=exc,
            )
Exemple #2
0
 def get_output_validation_error(
         self, data_to_validate: typing.Any) -> ProcessValidationError:
     """
     Return a ProcessValidationError containing validation
     detail error for output data
     """
     try:
         self.serializer.dump(data_to_validate, validate=True)
         raise WorkflowException(
             "Serializer should raise an exception here")
     except ValidationError as exc:
         return ProcessValidationError(
             message='Validation error of output data: "{}"'.format(
                 exc.args[0]),
             details=exc.args[1],
             original_exception=exc,
         )
     except Exception as exc:
         self._logger.exception(
             'Unknown error during serpyco dump: "{}": "{}"'.format(
                 type(exc).__name__, str(exc)))
         return ProcessValidationError(
             message="Unknown error during validation error "
             'of output data: "{}": "{}"'.format(
                 type(exc).__name__, str(exc)),
             details={},
             original_exception=exc,
         )
Exemple #3
0
    def get_input_files_validation_error(
            self, data_to_validate: typing.Any) -> ProcessValidationError:
        errors = {}

        for field in dataclasses.fields(self.schema):
            if not data_to_validate.get(field.name, None):
                errors[field.name] = "data is missing"

        return ProcessValidationError(message="Validation error of input data",
                                      details=errors)
Exemple #4
0
    def get_input_validation_error(
            self, data_to_validate: typing.Any) -> ProcessValidationError:
        """
        Return ProcessValidationError for given input data
        :param data_to_validate: data used to produce ProcessValidationError
        :return: ProcessValidationError instance for given data
        """
        clean_data = self.clean_data(data_to_validate)
        marshmallow_errors = self.schema.load(clean_data).errors

        return ProcessValidationError(message="Validation error of input data",
                                      details=marshmallow_errors)
Exemple #5
0
    def get_output_file_validation_error(
            self, data_to_validate: typing.Any) -> ProcessValidationError:
        """
        Return an ProcessValidationError containing validation
        detail error for output file data
        """
        validation_error_message = self._get_ouput_file_validation_error_message(
            data_to_validate)

        return ProcessValidationError(
            message="Validation error of output file",
            details={"output_file": validation_error_message},
        )
Exemple #6
0
    def get_output_validation_error(
            self, data_to_validate: typing.Any) -> ProcessValidationError:
        """
        Return ProcessValidationError for given output data
        :param data_to_validate: output data to use
        :return: ProcessValidationError instance for given output data
        """
        clean_data = self.clean_data(data_to_validate)
        dump_data = self.schema.dump(clean_data).data
        errors = self.schema.load(dump_data).errors

        return ProcessValidationError(
            message="Validation error of output data", details=errors)
Exemple #7
0
    def get_output_file_validation_error(
            self, data_to_validate: typing.Any) -> ProcessValidationError:
        """
        Return a ProcessValidationError for given output file
        :param data_to_validate: output file
        :return: ProcessValidationError instance for given output file
        """
        validation_error_message = self._get_ouput_file_validation_error_message(
            data_to_validate)

        return ProcessValidationError(
            message="Validation error of output file",
            details={"output_file": validation_error_message},
        )
Exemple #8
0
    def get_input_files_validation_error(
            self, data_to_validate: typing.Any) -> ProcessValidationError:
        """
        Return a ProcessValidationError about files for given data
        :param data_to_validate: data containing files
        :return: ProcessValidationError instance for given data files
        """
        clean_data = self.clean_data(data_to_validate)
        unmarshall = self.schema.load(clean_data)
        errors = unmarshall.errors
        additional_errors = self._get_input_files_errors(unmarshall.data)
        errors.update(additional_errors)

        return ProcessValidationError(message="Validation error of input data",
                                      details=errors)
Exemple #9
0
 def get_output_file_validation_error(
     self, data_to_validate: typing.Any
 ) -> ProcessValidationError:
     return ProcessValidationError(details={}, message="ERROR")