Skip to content

Commit c6b0309

Browse files
rokroskarjsam
authored andcommitted
fix: use latest_html for version check (#647)
Also changes the integration test, which was previously passing for the wrong reasons - it was always using the "concept" doi so it should have never shown the "newer version exists" message. closes #641
1 parent aed54bf commit c6b0309

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

renku/cli/_providers/zenodo.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from renku.cli._providers.api import ExporterApi, ProviderApi
3232
from renku.cli._providers.doi import DOIProvider
3333
from renku.models.datasets import Dataset, DatasetFile
34-
from renku.utils.doi import is_doi
3534

3635
ZENODO_BASE_URL = 'https://zenodo.org'
3736
ZENODO_SANDBOX_URL = 'https://sandbox.zenodo.org/'
@@ -190,7 +189,7 @@ class ZenodoRecordSerializer:
190189

191190
owner = attr.ib(default=None, kw_only=True)
192191

193-
record_id = attr.ib(default=None, kw_only=True)
192+
record_id = attr.ib(default=None, kw_only=True, converter=str)
194193

195194
state = attr.ib(default=None, kw_only=True)
196195

@@ -212,12 +211,10 @@ def version(self):
212211
return self.metadata.version
213212

214213
def is_last_version(self, uri):
215-
"""Check if record is at last possible version."""
216-
if is_doi(uri):
217-
return uri == self.metadata.prereserve_doi['doi']
218-
219-
record_id = self.metadata.prereserve_doi['recid']
220-
return ZenodoProvider.record_id(uri) == record_id
214+
"""Check if this record is the latest version."""
215+
return ZenodoProvider.record_id(
216+
self.links.get('latest_html')
217+
) == self.record_id
221218

222219
def get_jsonld(self):
223220
"""Get record metadata as jsonld."""

renku/cli/dataset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,9 @@ def import_(ctx, client, uri, name, extract):
559559

560560
text_prompt = 'Do you wish to download this version?'
561561
if record.is_last_version(uri) is False:
562-
text_prompt = WARNING + 'Newer version found.\n' + text_prompt
562+
text_prompt = WARNING + 'Newer version found at {}\n'.format(
563+
record.links.get('latest_html')
564+
) + text_prompt
563565

564566
except KeyError as e:
565567
raise BadParameter((

tests/cli/test_integration_datasets.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,26 @@ def test_dataset_import_real_param(doi, runner, project):
8787
def test_dataset_import_real_doi_warnings(runner, project):
8888
"""Test dataset import for existing DOI and dataset"""
8989
result = runner.invoke(
90-
cli.cli, ['dataset', 'import', '10.5281/zenodo.597964'], input='y'
90+
cli.cli, ['dataset', 'import', '10.5281/zenodo.1438326'], input='y'
9191
)
9292
assert 0 == result.exit_code
93-
assert 'Warning: Newer version found.' in result.output
93+
assert 'Warning: Newer version found' in result.output
9494
assert 'OK'
9595

9696
result = runner.invoke(
97-
cli.cli, ['dataset', 'import', '10.5281/zenodo.597964'], input='y\ny'
97+
cli.cli, ['dataset', 'import', '10.5281/zenodo.1438326'], input='y\ny'
9898
)
9999
assert 0 == result.exit_code
100-
assert 'Warning: Newer version found.' in result.output
100+
assert 'Warning: Newer version found' in result.output
101101
assert 'Warning: This dataset already exists.' in result.output
102102
assert 'OK' in result.output
103103

104104
result = runner.invoke(
105105
cli.cli, ['dataset', 'import', '10.5281/zenodo.597964'], input='y\nn'
106106
)
107107
assert 0 == result.exit_code
108-
assert 'Warning: Newer version found.' in result.output
109-
assert 'Warning: This dataset already exists.' in result.output
108+
assert 'Warning: Newer version found' not in result.output
109+
assert 'Warning: This dataset already exists.' not in result.output
110110
assert 'OK' not in result.output
111111

112112
result = runner.invoke(cli.cli, ['dataset'])

0 commit comments

Comments
 (0)