Exemplo n.º 1
0
    def _validate(self, value):
        if not isinstance(value, (str, text_type)):
            raise scim_exceptions.ScimAttributeInvalidTypeException(
                expected=self._d,
                locator=self._locator_path,
                value="({}){}".format(type(value).__name__, value),
                multi_value=self.multiValued,
                attribute_type="type string",
                reference=self._link_reference,
            )

        if self.canonicalValues:
            adjusted_value = value if self.caseExact else value.lower()
            adjusted_canonical_value = (
                self.canonicalValues
                if self.caseExact
                else [cv.lower() for cv in self.canonicalValues]
            )
            if adjusted_value not in adjusted_canonical_value:
                raise scim_exceptions.ScimAttributeInvalidTypeException(
                    expected=self._d,
                    locator=self._locator_path,
                    value=value,
                    multi_value=self.multiValued,
                    attribute_type="one of {}".format(
                        " ,".join([v for v in adjusted_canonical_value])
                    ),
                    reference=self._link_reference,
                )
Exemplo n.º 2
0
 def _validate(self, value):
     if not isinstance(value, (str, text_type)):
         raise scim_exceptions.ScimAttributeInvalidTypeException(
             expected=self._d,
             locator=self._locator_path,
             value=value,
             multi_value=self.multiValued,
             attribute_type="type reference",
             reference=self._link_reference,
         )
Exemplo n.º 3
0
 def _validate(self, value):
     if not (value and not isinstance(value, bool) and isinstance(value, int)):
         raise scim_exceptions.ScimAttributeInvalidTypeException(
             expected=self._d,
             locator=self._locator_path,
             value=value,
             multi_value=self.multiValued,
             attribute_type="integer",
             reference=self._link_reference,
         )
Exemplo n.º 4
0
 def _validate(self, value):
     if not (value and datetime.strptime(value, "%Y %m %dT%H:%M:%S %Z")):
         raise scim_exceptions.ScimAttributeInvalidTypeException(
             expected=self._d,
             locator=self._locator_path,
             value=value,
             multi_value=self.multiValued,
             attribute_type="datetime with format 2008-01-23T04:56:22Z",
             reference=self._link_reference,
         )
Exemplo n.º 5
0
 def _validate(self, value):
     # todo - there is no proper way to know the different between a
     # string and a binary
     if not isinstance(value, (str, text_type)):
         raise scim_exceptions.ScimAttributeInvalidTypeException(
             expected=self._d,
             locator=self._locator_path,
             value=value,
             multi_value=self.multiValued,
             attribute_type="binary",
             reference=self._link_reference,
         )
Exemplo n.º 6
0
 def _validate(self, value):
     pos_period = str(value).index(".")
     if not (
         value
         and isinstance(value, float)
         and pos_period < 1
         and len(value) - pos_period >= 1
     ):
         type_description = (
             "must be a real number with at least one "
             "digit to the left and right of the period"
         )
         raise scim_exceptions.ScimAttributeInvalidTypeException(
             expected=self._d,
             locator=self._locator_path,
             value=value,
             multi_value=self.multiValued,
             attribute_type=type_description,
             reference=self._link_reference,
         )
Exemplo n.º 7
0
    def _validate(self, value):
        if not isinstance(value, list):
            raise scim_exceptions.ScimAttributeInvalidTypeException(
                self._d,
                self._locator_path,
                value,
                self.multiValued,
                "list",
                reference=self._link_reference,
            )

        adjusted_values = [
            self.element_attribute._get_significant_value(v)
            for v in value
            if (not v == {} and v is not None)
        ]
        if not adjusted_values:
            raise scim_exceptions.ScimAttributeValueNotFoundException(
                value, self._locator_path, self.name, self.multiValued
            )

        exceptions = []
        try:
            self._validate_uniqueness(list_values=adjusted_values)
        except AssertionError as dpp:
            exceptions.append(dpp)

        for v in value:
            if not v == {} and v is not None:
                try:
                    self.element_attribute._validate(v)
                except AssertionError as iat:
                    exceptions.append(iat)

        if exceptions:
            raise scim_exceptions.AggregatedScimMultValueAttributeValidationExceptions(
                location="{} at path ('{}')".format(self.name, self._locator_path),
                exceptions=exceptions,
            )