Commit 17f516a8 authored by Vuillaume's avatar Vuillaume
Browse files

Merge branch 'list_att_classes' into 'master'

Adds `get_associated_versions`

See merge request !183
parents e96fc798 4bc4e517
Pipeline #175214 passed with stages
in 9 minutes and 23 seconds
......@@ -225,6 +225,19 @@ def test_search_communities():
assert communities[0]['title'] == 'ESCAPE 2020'
def test_get_associated_versions():
record = Record.from_id(4786641) # ZenodoCI deprecated lib. A single version
versions = record.get_associated_versions()
assert len(versions) == 1
assert list(versions)[0] == record.id # itself
eossr_record = Record.from_id(6352039)
eossr_record_versions = eossr_record.get_associated_versions()
assert len(eossr_record_versions) >= 7 # Seven versions, to date 21/03/2022
for recid, version in eossr_record_versions.items():
assert eossr_record.data['conceptrecid'] == Record.from_id(recid).data['conceptrecid']
assert eossr_record_versions[5524913] == 'v0.2' # ID of eOSSR version v0.2
@pytest.mark.xfail(raises=FileNotFoundError)
def test_get_codemeta_fail():
record = Record.from_id(3734091)
......
......@@ -608,6 +608,10 @@ class Record:
def title(self):
return self.data['metadata']['title']
@property
def metadata(self):
return self.data['metadata']
@property
def filelist(self):
"""
......@@ -643,6 +647,41 @@ class Record:
url = Path(self.data['links']['self']).parent.joinpath(str(record_id)).as_posix()
return Record(requests.get(url).json())
@property
def from_sandbox(self):
"""
Is the record from sandbox?
:return: bool
"""
if 'sandbox' in self.data['links']['self']:
return True
else:
return False
def get_associated_versions(self, size=_default_size_query, **kwargs):
"""
Returns a dictionnary of all the versions of the current record
:param size: int
Number of results to return. Default = 50 (`_default_size_query`)
:param kwargs: Zenodo query arguments.
For an exhaustive list, see the query arguments at https://developers.zenodo.org/#list36
:return: dict
dictionnary of `{record_id: record_version}`
"""
conceptrecid = self.data['conceptrecid']
params = {'all_versions': True, **kwargs}
params.setdefault('size', size)
versions = {}
for record in get_zenodo_records(f'conceptrecid:{conceptrecid}', sandbox=self.from_sandbox, **params):
if 'version' in record.metadata:
versions[record.id] = record.metadata['version']
else:
version[record.id] = None
return versions
def print_info(self, linebreak='\n', file=sys.stdout):
"""
Print general information about the record to a stream, or to sys.stdout by default.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment