Example #1
0
 def test_get_files_published(self):
     published = True
     get_files(self.mock_dataset, published)
     self.mock_dataset.get_files.assert_called_once_with('latest-published')
Example #2
0
 def test_get_files(self):
     published = False
     get_files(self.mock_dataset, published)
     self.mock_dataset.get_files.assert_called_once_with('latest')
 def test_get_files_published(self):
     published = True
     get_files(self.mock_dataset, published)
     self.mock_dataset.get_files.assert_called_once_with('latest-published')
 def test_get_files(self):
     published = False
     get_files(self.mock_dataset, published)
     self.mock_dataset.get_files.assert_called_once_with('latest')
Example #5
0
def _dataverse_root_folder(node_addon, auth, **kwargs):
    node = node_addon.owner

    default_version = 'latest-published'
    version = 'latest-published' if not node.can_edit(
        auth) else default_version

    # Quit if no dataset linked
    if not node_addon.complete:
        return []

    can_edit = node.can_edit(auth)

    permissions = {
        'edit': can_edit and not node.is_registration,
        'view': node.can_view(auth)
    }

    try:
        connection = client.connect_from_settings(node_addon)
        dataverse = client.get_dataverse(connection,
                                         node_addon.dataverse_alias)
        dataset = client.get_dataset(dataverse, node_addon.dataset_doi)
    except SSLError:
        return [
            rubeus.build_addon_root(
                node_addon,
                node_addon.dataset,
                permissions=permissions,
                private_key=kwargs.get('view_only', None),
            )
        ]

    # Quit if doi does not produce a dataset
    if dataset is None:
        return []

    published_files = client.get_files(dataset, published=True)

    # Produce draft version or quit if no published version is available
    if not published_files:
        if can_edit:
            version = 'latest'
        else:
            return []

    urls = {
        'publish': node.api_url_for('dataverse_publish_dataset'),
    }

    # determine if there are any changes between the published and draft
    # versions of the dataset
    try:
        dataset.get_metadata('latest-published')
        dataset_is_published = True
        dataset_draft_modified = dataset.get_state() == 'DRAFT'
    except VersionJsonNotFoundError:
        dataset_is_published = False
        dataset_draft_modified = True

    # Get the dataverse host
    # (stored in oauth_key because dataverse doesn't use that)
    dataverse_host = node_addon.external_account.oauth_key

    try:
        host_custom_publish_text = client.get_custom_publish_text(connection)
    except OperationFailedError:
        host_custom_publish_text = ''

    return [
        rubeus.build_addon_root(
            node_addon,
            node_addon.dataset,
            urls=urls,
            permissions=permissions,
            dataset=node_addon.dataset,
            doi=dataset.doi,
            dataverse=dataverse.title,
            hasPublishedFiles=bool(published_files),
            dataverseIsPublished=dataverse.is_published,
            datasetIsPublished=dataset_is_published,
            datasetDraftModified=dataset_draft_modified,
            version=version,
            host=dataverse_host,
            hostCustomPublishText=host_custom_publish_text,
            private_key=kwargs.get('view_only', None),
        )
    ]
Example #6
0
def _dataverse_root_folder(node_addon, auth, **kwargs):
    node = node_addon.owner

    default_version = 'latest-published'
    version = 'latest-published' if not node.can_edit(auth) else default_version

    # Quit if no dataset linked
    if not node_addon.complete:
        return []

    can_edit = node.can_edit(auth)

    permissions = {
        'edit': can_edit and not node.is_registration,
        'view': node.can_view(auth)
    }

    try:
        connection = client.connect_from_settings(node_addon)
        dataverse = client.get_dataverse(connection, node_addon.dataverse_alias)
        dataset = client.get_dataset(dataverse, node_addon.dataset_doi)
    except SSLError:
        return [rubeus.build_addon_root(
            node_addon,
            node_addon.dataset,
            permissions=permissions,
            private_key=kwargs.get('view_only', None),
        )]

    # Quit if doi does not produce a dataset
    if dataset is None:
        return []

    published_files = client.get_files(dataset, published=True)

    # Produce draft version or quit if no published version is available
    if not published_files:
        if can_edit:
            version = 'latest'
        else:
            return []

    urls = {
        'publish': node.api_url_for('dataverse_publish_dataset'),
    }

    # determine if there are any changes between the published and draft
    # versions of the dataset
    try:
        dataset.get_metadata('latest-published')
        dataset_is_published = True
        dataset_draft_modified = dataset.get_state() == 'DRAFT'
    except VersionJsonNotFoundError:
        dataset_is_published = False
        dataset_draft_modified = True

    # Get the dataverse host
    # (stored in oauth_key because dataverse doesn't use that)
    dataverse_host = node_addon.external_account.oauth_key

    try:
        host_custom_publish_text = client.get_custom_publish_text(connection)
    except OperationFailedError:
        host_custom_publish_text = ''

    return [rubeus.build_addon_root(
        node_addon,
        node_addon.dataset,
        urls=urls,
        permissions=permissions,
        dataset=node_addon.dataset,
        doi=dataset.doi,
        dataverse=dataverse.title,
        hasPublishedFiles=bool(published_files),
        dataverseIsPublished=dataverse.is_published,
        datasetIsPublished=dataset_is_published,
        datasetDraftModified=dataset_draft_modified,
        version=version,
        host=dataverse_host,
        hostCustomPublishText=host_custom_publish_text,
        private_key=kwargs.get('view_only', None),
    )]