How to use the renku.core.models.datasets.Dataset.from_jsonld function in renku

To help you get started, we’ve selected a few renku examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SwissDataScienceCenter / renku-python / tests / core / commands / test_dataset.py View on Github external
def test_dataset_serialization(dataset):
    """Test dataset (de)serialization."""
    dataset_metadata = dataset.asjsonld()
    dataset = Dataset.from_jsonld(dataset_metadata)

    # assert that all attributes found in metadata are set in the instance
    assert dataset.created
    assert dataset.creator
    assert dataset.identifier
    assert dataset.name
    assert dataset.path
    assert dataset._project

    # check values
    assert str(dataset.created.isoformat()) == dataset_metadata.get('created')
    assert dataset.creator[0].email == dataset_metadata.get('creator'
                                                            )[0].get('email')
    assert dataset.identifier == dataset_metadata.get('identifier')
    assert dataset.name == dataset_metadata.get('name')
    assert dataset.path == dataset_metadata.get('path')
github SwissDataScienceCenter / renku-python / tests / cli / test_migrate.py View on Github external
def test_migration_broken_urls(dataset_metadata):
    """Check that migration of broken dataset file URLs is string."""
    dataset = Dataset.from_jsonld(
        dataset_metadata,
        client=LocalClient('.'),
    )

    for file_ in dataset.files:
        assert isinstance(url_to_string(file_.url), str)
github SwissDataScienceCenter / renku-python / tests / core / commands / test_serialization.py View on Github external
def test_dataset_creator_email(dataset_metadata):
    """Check that creators without an email are assigned a blank node."""
    # modify the dataset metadata to change the creator
    dataset = Dataset.from_jsonld(
        dataset_metadata,
        client=LocalClient('.'),
    )

    dataset.creator[0]._id = 'mailto:None'
    dataset_broken = Dataset.from_jsonld(
        dataset.asjsonld(), client=LocalClient('.')
    )
    assert 'mailto:None' not in dataset_broken.creator[0]._id
github SwissDataScienceCenter / renku-python / tests / core / commands / test_serialization.py View on Github external
def test_dataset_doi_metadata(dataset_metadata):
    """Check dataset metadata for correct DOI."""
    from renku.core.utils.doi import is_doi
    dataset = Dataset.from_jsonld(
        dataset_metadata,
        client=LocalClient('.'),
    )

    if is_doi(dataset.identifier):
        assert urljoin(
            'https://doi.org', dataset.identifier
        ) == dataset.same_as

    assert dataset._id.endswith(
        'datasets/{}'.format(quote(dataset.identifier, safe=''))
    )
github SwissDataScienceCenter / renku-python / tests / core / commands / test_serialization.py View on Github external
def test_dataset_creator_email(dataset_metadata):
    """Check that creators without an email are assigned a blank node."""
    # modify the dataset metadata to change the creator
    dataset = Dataset.from_jsonld(
        dataset_metadata,
        client=LocalClient('.'),
    )

    dataset.creator[0]._id = 'mailto:None'
    dataset_broken = Dataset.from_jsonld(
        dataset.asjsonld(), client=LocalClient('.')
    )
    assert 'mailto:None' not in dataset_broken.creator[0]._id
github SwissDataScienceCenter / renku-python / renku / core / commands / providers / zenodo.py View on Github external
def as_dataset(self, client):
        """Deserialize `ZenodoRecordSerializer` to `Dataset`."""
        files = self.get_files()
        metadata = self.get_jsonld()
        dataset = Dataset.from_jsonld(metadata, client=client)

        serialized_files = []
        for file_ in files:
            remote_ = file_.remote_url
            dataset_file = DatasetFile(
                url=remote_,
                id=file_.id,
                checksum=file_.checksum,
                filename=file_.filename,
                filesize=file_.filesize,
                filetype=file_.type,
                path='',
            )
            serialized_files.append(dataset_file)

        dataset.files = serialized_files
github SwissDataScienceCenter / renku-python / renku / core / commands / providers / dataverse.py View on Github external
def as_dataset(self, client):
        """Deserialize `DataverseRecordSerializer` to `Dataset`."""
        files = self.get_files()
        dataset = Dataset.from_jsonld(self._json, client=client)

        serialized_files = []
        for file_ in files:
            remote_ = file_.remote_url
            dataset_file = DatasetFile(
                url=remote_,
                id=file_._id if file_._id else file_.name,
                filename=file_.name,
                filesize=file_.content_size,
                filetype=file_.file_format,
                path='',
            )
            serialized_files.append(dataset_file)

        dataset.files = serialized_files