def _migrate_doi_identifier(data, client): """If the dataset _id is doi, make it a UUID.""" from renku.core.utils.doi import is_doi from renku.core.utils.uuid import is_uuid _id = data.get('_id', '') identifier = data.get('identifier', '') if not is_uuid(_id): if not is_uuid(identifier): data['identifier'] = str(uuid.uuid4()) if is_doi(data.get('_id', '')): data['same_as'] = {'@type': ['schema:URL'], 'url': data['_id']} if data.get('@context'): data['@context'].setdefault( 'same_as', { '@id': 'schema:sameAs', '@type': 'schema:URL', '@context': { '@version': '1.1', 'url': 'schema:url', 'schema': 'http://schema.org/' } }) data['_id'] = data['identifier'] return data
def _migrate_doi_identifier(data, client): """If the dataset _id is doi, make it a UUID.""" from renku.core.utils.doi import is_doi from renku.core.utils.uuid import is_uuid _id = data.get("_id", "") identifier = data.get("identifier", "") if not is_uuid(_id): if not is_uuid(identifier): data["identifier"] = str(uuid.uuid4()) if is_doi(data.get("_id", "")): data["same_as"] = {"@type": ["schema:URL"], "url": data["_id"]} if data.get("@context"): data["@context"].setdefault( "same_as", { "@id": "schema:sameAs", "@type": "schema:URL", "@context": { "@version": "1.1", "url": "schema:url", "schema": "http://schema.org/" }, }, ) data["_id"] = data["identifier"] return data
def test_uuid_migration(dataset_metadata, client): """Test migration of id with UUID.""" dataset = Dataset.from_jsonld(dataset_metadata, client=client) assert is_uuid(dataset.identifier) assert urljoin('https://localhost/datasets/', dataset.identifier) == dataset._id