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'))
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 (can be empty). """ 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) # 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: if enum: result = found_method(value, enum) else: result = found_method(value) elif enum: result = self._generic_enum_validator(value, concept_details, enum) else: raise ob.OBValidationError( "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. Avoid UtilityIdentifier which is a LEI. if concept_details.id != "solar:UtilityIdentifier" and concept_details.id.find( "Identifier") != -1: if not identifier.validate(value): errors += [ "'{}' is not valid identifier.".format(concept_details.id) ] # If all conditions clear then the value passes. errors += result[1] return result[0], errors
def validate_identifier(args): print("Valid:", identifier.validate(args.identifier))
def test_invalid_identifier_format(self): # Bad UUID format self.assertFalse(identifier.validate("dfasfdfsadfds"))
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'))