Ejemplo n.º 1
0
    def test_valid_identifiers(self):
        # UUID1.
        self.assertTrue(identifier.validate('70e7cfc6-def7-11e8-bb65-10e7c6792ac1'))

        # UUID3.
        self.assertTrue(identifier.validate('a402d082-1bb6-38ce-b44e-953fd8610fac'))

        # UUID4.
        self.assertTrue(identifier.validate('9c189dd1-a4d3-4b3f-ba08-37fc962dc9c9'))

        # UUID5.
        self.assertTrue(identifier.validate('76c439e1-dfc9-50ab-a06a-d70afa21bb2f'))

        # UUID are case insensitive.
        self.assertTrue(identifier.validate('9C189DD1-A4D3-4B3F-BA08-37FC962DC9C9'))
Ejemplo n.º 2
0
def validate_concept_value(concept, value):

    # If null check if nillable is ok and return
    if value is None and concept.nillable:
        return True
    elif value is None and not concept.nillable:
        return False

    # Check data type
    #
    # TODO: This is neither a complete list nor does it take into consideration string values that
    # contain legal representations.  Its very basic at this point of time and needs to be hashed
    # out.
    #
    if concept.type_name == "xbrli:booleanItemType":
        if type(value) is not bool:
            return False
    elif concept.type_name == "xbrli:stringItemType":
        if type(value) is not str:
            return False
    elif concept.type_name == "xbrli:integerItemType":
        if type(value) is not int:
            return False

    # Check identifiers.  This is based upon the name of the field containing the word Identifier
    # in it.
    if concept.id.find("Identifier") != -1:
        return identifier.validate(value)

    # If all conditions clear then the value passes.
    return True
Ejemplo n.º 3
0
def validate_concept_value(concept, value):

    errors = []
    # If null check if nillable is ok and return
    if value is None and not concept.nillable:
        errors += [
            "'{}' is not allowed to be nillable (null).".format(concept.id)
        ]

    # Check data type and validator calling
    if type(concept.type_name).__name__ in ["str", "unicode"]:
        method_name = get_validator_method_name(concept.type_name)
        validator_module = sys.modules[__name__]
        found_method = getattr(validator_module, method_name, None)
        if found_method is not None:
            errors += found_method(value, concept)

    # Check identifiers.  This is based upon the name of the field containing the word Identifier
    # in it.
    if concept.id.find("Identifier") != -1:
        if identifier.validate(value) is False:
            errors += ["'{}' is not valid identifier.".format(concept.id)]

    # If all conditions clear then the value passes.
    return errors
Ejemplo n.º 4
0
    def validate_concept_value(self, concept_details, value):
        """
            Validate a concept value.

            Args:
                concept_details (ConceptDetails): concept details
                value (*): value to be validated

            Returns:
                A Tuple (*, list of str) containing original or converted value and list of errors (if any)
        """
        errors = []
        result = value, []
        # If null check if nillable is ok and return
        if value is None and not concept_details.nillable:
            errors += [
                "'{}' is not allowed to be nillable (null).".format(
                    concept_details.id)
            ]
        enum = self._taxonomy.types.get_type_enum(concept_details.type_name)
        is_enum = enum is not None
        # Check data type and validator calling
        if type(concept_details.type_name).__name__ in ["str", "unicode"]:
            method_name = self._get_validator_method_name(
                concept_details.type_name)
            # validator_module = sys.modules[__name__]
            found_method = getattr(self, method_name, None)
            if found_method is not None:
                if is_enum:
                    result = found_method(value, enum)
                else:
                    result = found_method(value)
            elif is_enum:
                result = self._generic_enum_validator(value, concept_details,
                                                      enum)
            else:
                raise Exception(
                    "Concept '{}' could not be processed. Missing method '{}'."
                    .format(concept_details.type_name, method_name))

        # Check identifiers.  This is based upon the name of the field containing
        # the word Identifier in it.
        if concept_details.id.find("Identifier") != -1:
            if identifier.validate(value) is False:
                errors += [
                    "'{}' is not valid identifier.".format(concept_details.id)
                ]

        # If all conditions clear then the value passes.
        errors += result[1]
        return result[0], errors
Ejemplo n.º 5
0
def validate_concept_value(concept, value):
    """Validate a concept."""
    errors = []
    result = value, []
    # If null check if nillable is ok and return
    if value is None and not concept.nillable:
        errors += [
            "'{}' is not allowed to be nillable (null).".format(concept.id)
        ]
    enum = taxonomy.getTaxonomy().types.get_type_enum(concept.type_name)
    is_enum = enum is not None
    # Check data type and validator calling
    if type(concept.type_name).__name__ in ["str", "unicode"]:
        method_name = _get_validator_method_name(concept.type_name)
        validator_module = sys.modules[__name__]
        found_method = getattr(validator_module, method_name, None)
        if found_method is not None:
            if is_enum:
                result = found_method(value, enum)
            else:
                result = found_method(value)
        elif is_enum:
            result = _generic_enum_validator(value, concept, enum)
        else:
            raise Exception(
                "Concept '{}' could not be processed. Missing method '{}'.".
                format(concept.type_name, method_name))

    # Check identifiers.  This is based upon the name of the field containing
    # the word Identifier in it.
    if concept.id.find("Identifier") != -1:
        if identifier.validate(value) is False:
            errors += ["'{}' is not valid identifier.".format(concept.id)]

    # If all conditions clear then the value passes.
    errors += result[1]
    return result[0], errors
Ejemplo n.º 6
0
def validate_identifier(args):
    print("Valid:", identifier.validate(args.identifier))
Ejemplo n.º 7
0
 def test_invalid_identifier_format(self):
     # Bad UUID format
     self.assertFalse(identifier.validate("dfasfdfsadfds"))
Ejemplo n.º 8
0
 def test_invalid_identifier_bad_version(self):
     # Not a valid UUID identifier (the third group should start with 1, 2, 3, 4 or 5).
     self.assertFalse(identifier.validate('9c189dd1-a4d3-Xb3f-ba08-37fc962dc9c9'))