Пример #1
0
def dataverse_publish_dataset(node_addon, auth, **kwargs):
    node = node_addon.owner
    publish_both = request.json.get('publish_both', False)

    now = timezone.now()

    connection = client.connect_from_settings_or_401(node_addon)

    dataverse = client.get_dataverse(connection, node_addon.dataverse_alias)
    dataset = client.get_dataset(dataverse, node_addon.dataset_doi)

    if publish_both:
        client.publish_dataverse(dataverse)
    client.publish_dataset(dataset)

    # Add a log
    node.add_log(
        action='dataverse_dataset_published',
        params={
            'project': node.parent_id,
            'node': node._id,
            'dataset': dataset.title,
        },
        auth=auth,
        log_date=now,
    )

    return {'dataset': dataset.title}, http.OK
Пример #2
0
    def test_publish_dataset_unpublished_dataverse(self):
        type(self.mock_dataverse).is_published = mock.PropertyMock(return_value=False)
        with assert_raises(HTTPError) as e:
            publish_dataset(self.mock_dataset)

        assert_false(self.mock_dataset.publish.called)
        assert_equal(e.exception.code, 405)
Пример #3
0
def dataverse_publish(node_addon, auth, publish_both=False):
    node = node_addon.owner
    user_settings = node_addon.user_settings

    now = datetime.datetime.utcnow()

    try:
        connection = connect_from_settings_or_401(user_settings)
    except HTTPError as error:
        if error.code == httplib.UNAUTHORIZED:
            connection = None
        else:
            raise

    dataverse = get_dataverse(connection, node_addon.dataverse_alias)
    dataset = get_dataset(dataverse, node_addon.dataset_doi)

    if publish_both:
        publish_dataverse(dataverse)
    publish_dataset(dataset)

    # Add a log
    node.add_log(
        action='dataverse_dataset_published',
        params={
            'project': node.parent_id,
            'node': node._primary_key,
            'dataset': dataset.title,
        },
        auth=auth,
        log_date=now,
    )

    return {'dataset': dataset.title}, httplib.OK
Пример #4
0
def dataverse_publish_dataset(node_addon, auth, **kwargs):
    node = node_addon.owner
    publish_both = request.json.get('publish_both', False)

    now = datetime.datetime.utcnow()

    connection = client.connect_from_settings_or_401(node_addon)

    dataverse = client.get_dataverse(connection, node_addon.dataverse_alias)
    dataset = client.get_dataset(dataverse, node_addon.dataset_doi)

    if publish_both:
        client.publish_dataverse(dataverse)
    client.publish_dataset(dataset)

    # Add a log
    node.add_log(
        action='dataverse_dataset_published',
        params={
            'project': node.parent_id,
            'node': node._id,
            'dataset': dataset.title,
        },
        auth=auth,
        log_date=now,
    )

    return {'dataset': dataset.title}, http.OK
Пример #5
0
def dataverse_publish(node_addon, auth, publish_both=False):
    node = node_addon.owner
    user_settings = node_addon.user_settings

    now = datetime.datetime.utcnow()

    try:
        connection = connect_from_settings_or_401(user_settings)
    except HTTPError as error:
        if error.code == httplib.UNAUTHORIZED:
            connection = None
        else:
            raise

    dataverse = get_dataverse(connection, node_addon.dataverse_alias)
    dataset = get_dataset(dataverse, node_addon.dataset_doi)

    if publish_both:
        publish_dataverse(dataverse)
    publish_dataset(dataset)

    # Add a log
    node.add_log(
        action="dataverse_dataset_published",
        params={"project": node.parent_id, "node": node._primary_key, "dataset": dataset.title},
        auth=auth,
        log_date=now,
    )

    return {"dataset": dataset.title}, httplib.OK
Пример #6
0
def dataverse_publish_dataset(node_addon, auth, **kwargs):
    node = node_addon.owner
    publish_both = request.json.get('publish_both', False)

    now = datetime.datetime.utcnow()

    try:
        connection = connect_from_settings_or_401(node_addon)
    except HTTPError as error:
        if error.code == httplib.UNAUTHORIZED:
            connection = None
        else:
            raise

    dataverse = get_dataverse(connection, node_addon.dataverse_alias)
    dataset = get_dataset(dataverse, node_addon.dataset_doi)

    if publish_both:
        publish_dataverse(dataverse)
    publish_dataset(dataset)

    # Add a log
    node.add_log(
        action='dataverse_dataset_published',
        params={
            'project': node.parent_id,
            'node': node._primary_key,
            'dataset': dataset.title,
        },
        auth=auth,
        log_date=now,
    )

    return {'dataset': dataset.title}, httplib.OK
Пример #7
0
    def test_publish_dataset_unpublished_dataverse(self):
        type(self.mock_dataverse).is_published = mock.PropertyMock(return_value=False)
        with assert_raises(HTTPError) as e:
            publish_dataset(self.mock_dataset)

        assert_false(self.mock_dataset.publish.called)
        assert_equal(e.exception.code, 405)
Пример #8
0
 def test_publish_dataset(self):
     publish_dataset(self.mock_dataset)
     self.mock_dataset.publish.assert_called_once_with()
Пример #9
0
 def test_publish_dataset(self):
     publish_dataset(self.mock_dataset)
     self.mock_dataset.publish.assert_called_once_with()