Ejemplo n.º 1
0
    def validate_identifiers(self, value):
        """Validate well-formed identifiers are passed."""
        if any(key not in ['Orcid', 'ror'] for key in value.keys()):
            raise ValidationError(_("Invalid identifier."))

        if 'Orcid' in value:
            if not idutils.is_orcid(value.get('Orcid')):
                raise ValidationError(_("Invalid identifier."))

        if 'ror' in value:
            if not idutils.is_ror(value.get('ror')):
                raise ValidationError(_("Invalid identifier."))
Ejemplo n.º 2
0
def author_id_normalize_and_schema(uid, schema=None):
    """Detect and normalize an author UID schema.

    Args:
        uid (string): a UID string
        schema (string): try to resolve to schema

    Returns:
        Tuple[string, string]: a tuple (uid, schema) where:
        - uid: the UID normalized to comply with the id.json schema
        - schema: a schema of the UID or *None* if not recognised

    Raise:
        UnknownUIDSchema: if UID is too little to definitively guess the schema
        SchemaUIDConflict: if specified schema is not matching the given UID
    """
    def _get_uid_normalized_in_schema(_uid, _schema):
        regex, template = _RE_AUTHORS_UID[_schema]
        match = regex.match(_uid)
        if match:
            return template.format(match.group('uid'))

    if idutils.is_orcid(uid) and schema in (None, 'ORCID'):
        return idutils.normalize_orcid(uid), 'ORCID'

    if schema and schema not in _RE_AUTHORS_UID:
        # Schema explicitly specified, but this function can't handle it
        raise UnknownUIDSchema(uid)

    if schema:
        normalized_uid = _get_uid_normalized_in_schema(uid, schema)
        if normalized_uid:
            return normalized_uid, schema
        else:
            raise SchemaUIDConflict(schema, uid)

    match_schema, normalized_uid = None, None
    for candidate_schema in _RE_AUTHORS_UID:
        candidate_uid = _get_uid_normalized_in_schema(uid, candidate_schema)
        if candidate_uid:
            if match_schema:
                # Valid against more than one candidate schema, ambiguous
                raise UnknownUIDSchema(uid)
            match_schema = candidate_schema
            normalized_uid = candidate_uid

    if match_schema:
        return normalized_uid, match_schema

    # No guessess have been found
    raise UnknownUIDSchema(uid)
Ejemplo n.º 3
0
    def validate_identifiers(self, value):
        """Validate well-formed identifiers are passed."""
        schemes = ['orcid', 'ror']

        if any(scheme not in schemes for scheme in value.keys()):
            raise ValidationError(
                [_(f"Invalid value. Choose one of {schemes}.")])

        if 'orcid' in value:
            if not idutils.is_orcid(value.get('orcid')):
                raise ValidationError({'orcid': [_("Invalid value.")]})

        if 'ror' in value:
            if not idutils.is_ror(value.get('ror')):
                raise ValidationError({'ror': [_("Invalid value.")]})
Ejemplo n.º 4
0
def test_orcid_number_generator(inspire_app):
    orcid = RecordProvider.orcid()
    assert is_isni(orcid)
    assert is_orcid(orcid)