Example #1
0
 def _validate(self, value):
     super(AbstractCollection, self)._validate(value)
     errors = _validate_sequence(self.value_type, value)
     if errors:
         raise WrongContainedType(errors, self.__name__)
     if self.unique:
         _validate_uniqueness(value)
Example #2
0
    def _validate(self, value):
        super(JSONField, self)._validate(value)

        try:
            self.schema_validator.validate(value)
        except jsonschema.ValidationError as e:
            raise WrongContainedType([e], self.getName(), value=value)
Example #3
0
    def _validate(self, value):
        super(JSONField, self)._validate(value)

        try:
            jsonschema.validate(value, self.json_schema)
        except jsonschema.ValidationError as e:
            raise WrongContainedType(e.message, self.__name__)
Example #4
0
 def _validate(self, value):
     if isinstance(value, RichTextFieldValue):
         # check the value against schema
         errors = _validate_fields(IRichTextFieldSchema, value)
     else:
         raise Exception('Not valid field')
     if errors:
         raise WrongContainedType(errors, self.__name__)
Example #5
0
    def _validate(self, value):
        super(JSONField, self)._validate(value)

        try:
            self.schema_validator.validate(value)
        except jsonschema.ValidationError as e:
            raise WrongContainedType(
                f"Failed to validate {'.'.join(e.absolute_schema_path)} with {e.validator_value}"
            )
Example #6
0
 def validate(self, value):
     errors = []
     for field in self.fields:
         try:
             field.validate(value)
             return field
         except ValidationError as error:
             errors.append(error)
     else:
         raise WrongContainedType(errors, self.__name__, value=value)
Example #7
0
    def _validate(self, value):
        super(Dict, self)._validate(value)
        errors = []
        if not self.naive:
            if self.value_type:
                errors = _validate_sequence(self.value_type, value.values(),
                                            errors)
            errors = _validate_sequence(self.key_type, value, errors)

        if errors:
            raise WrongContainedType(errors, self.__name__, value=value)
Example #8
0
    def _validate(self, value):
        super(Object, self)._validate(value)

        # schema has to be provided by value
        if not self.schema.providedBy(value):
            raise SchemaNotProvided

        # check the value against schema
        errors = _validate_fields(self.schema, value)
        if errors:
            raise WrongContainedType(errors, self.__name__)
Example #9
0
    def _validate(self, value):
        super(Dict, self)._validate(value)
        errors = []
        try:
            if self.value_type:
                errors = _validate_sequence(self.value_type, value.values(),
                                            errors)
            errors = _validate_sequence(self.key_type, value, errors)

            if errors:
                raise WrongContainedType(errors, self.__name__)

        finally:
            errors = None
Example #10
0
    def _validate(self, value):
        """ """
        super(FhirField, self)._validate(value)

        if self.resource_interface:
            try:
                verifyObject(
                    self._resource_interface_class, value.foreground_origin(), False
                )

            except (
                BrokenImplementation,
                BrokenMethodImplementation,
                DoesNotImplement,
            ) as exc:

                return reraise(Invalid, str(exc))

        if self.resource_type and value.resource_type != self.resource_type:
            msg = (
                "Resource type must be `{0}` but we got {1} " "which is not allowed!"
            ).format(self.resource_type, value.resource_type)
            raise ConstraintNotSatisfied(msg, field_name=self.getName())

        if self.resource_class:
            klass = self._resource_class

            if value.foreground_origin() is not None and not isinstance(
                value.foreground_origin(), klass
            ):
                msg = (
                    "Wrong fhir resource value is provided! "
                    "Value should be object of {0!r} but got {1!r}".format(
                        klass, value.foreground_origin().__class__
                    )
                )

                raise WrongContainedType(msg, field_name=self.getName())

        if value.foreground_origin() is not None:
            try:
                value.foreground_origin().as_json()
            except (FHIRValidationError, TypeError) as exc:
                msg = (
                    "There is invalid element inside " "fhir model object.\n{0!s}"
                ).format(exc)

                return reraise(Invalid, msg)
Example #11
0
    def _validate(self, value):
        super(Object, self)._validate(value)

        if isinstance(value, dict):
            # Dicts are validated differently
            valid_type = namedtuple(
                'temp_validate_type',
                set(self.schema.names(all=True)) & set(value.keys()))
            # check the value against schema
            errors = _validate_fields(self.schema, valid_type(**value))
        else:
            if not self.schema.providedBy(value):
                raise SchemaNotProvided
            errors = _validate_fields(self.schema, value)
        if errors:
            raise WrongContainedType(errors, self.__name__)
Example #12
0
    def _validate(self, value):
        """ """
        super(FhirField, self)._validate(value)

        if self.resource_interface:
            try:
                verifyObject(self._resource_interface_class,
                             value.foreground_origin(), False)

            except (BrokenImplementation, BrokenMethodImplementation,
                    DoesNotImplement):

                t, v, tb = sys.exc_info()
                try:
                    reraise(Invalid(str(v)), None, tb)
                finally:
                    del t, v, tb

        if self.resource_type and value.resource_type != self.resource_type:
            msg = "Resource type must be `{0}` but we got {1} which is not allowed!".format(
                self.resource_type, value.resource_type)
            raise ConstraintNotSatisfied(msg)

        if self.resource_class:
            klass = self._resource_class

            if value.foreground_origin() is not None and not isinstance(
                    value.foreground_origin(), klass):
                msg = "Wrong fhir resource value is provided! "\
                      "Value should be object of {0!r} but got {1!r}".\
                    format(klass, value.foreground_origin().__class__)

                raise WrongContainedType(msg)

        if value.foreground_origin() is not None:
            try:
                value.foreground_origin().as_json()
            except (FHIRValidationError, TypeError) as exc:
                msg = "There is invalid element inside fhir model object.\n{0!s}".format(
                    exc)
                t, v, tb = sys.exc_info()
                try:
                    reraise(Invalid(msg), None, tb)
                finally:
                    del t, v, tb