Skip to content

Commit

Permalink
SciDataLib-76 Scidata 'rights' limited to 1 entry
Browse files Browse the repository at this point in the history
Updated code to handle multiple entries (equivalent to sources).  Add tests for both the append and replace functionalities.
  • Loading branch information
stuchalk committed Dec 14, 2023
1 parent 810a38d commit ce9b3ad
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
33 changes: 20 additions & 13 deletions scidatalib/scidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,25 +917,32 @@ def sources(self, sources: list, replace=False) -> dict:
}
ld.update(x)
srcs.append(ld)
self.meta['@graph']['sources'] = srcs
return self.meta['@graph']['sources']

def rights(self, holder: str, lic: str) -> dict:
def rights(self, rights: list, replace=False) -> dict:
"""
Add the rights section to the file (max: 1 entry)
Add the rights section to the file (min: 1 entry)
:param holder: the entity that holds the license to this data
:param lic: the assigned license
:param rights: the rights of the data consisting of:
holder: the rights holder
license: the license given by the holder
:param replace: the assigned license
"""
rights = []
if isinstance(holder, str) and isinstance(lic, str):
rights = [{
'@id': 'rights/1/',
'@type': 'dc:rights',
'holder': holder,
'license': lic,
}]
self.meta['@graph']['rights'] = rights
rites = []
if not replace:
rites = self.meta['@graph']['rights']
for x in rights:
ld = {
'@id': 'rights/' + str(len(rites) + 1) + '/',
'@type': 'dc:rights'
}
ld.update(x)
rites.append(ld)
else:
rites = rights
self.meta['@graph']['rights'] = rites
return self.meta['@graph']['rights']

# private class functions
Expand Down
19 changes: 17 additions & 2 deletions tests/test_scidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,25 @@ def test_source(sd):
assert sd.sources(src) == out


def test_rights(sd):
def test_rights_append(sd):
holder = 'Megadodo Productions'
licurl = 'https://creativecommons.org/licenses/by/4.0/'
lic = 'Creative Commons, Attribution 4.0 Galactic (CC BY 4.0) ' + licurl
out = [{"@id": "rights/1/", "@type": "dc:rights",
"holder": holder, "license": lic},
{"@id": "rights/2/", "@type": "dc:rights",
"holder": holder, "license": lic}]
assert sd.rights(holder, lic) == out
inn = {'holder': holder, 'license': lic}
sd.rights([inn])
assert sd.rights([inn]) == out


def test_rights_replace(sd):
holder = 'Megadodo Productions'
licurl = 'https://creativecommons.org/licenses/by/4.0/'
lic = 'Creative Commons, Attribution 4.0 Galactic (CC BY 4.0) ' + licurl
out = [{"@id": "rights/1/", "@type": "dc:rights",
"holder": holder, "license": lic}]
inn = {'holder': holder, 'license': lic}
sd.rights([inn, inn])
assert sd.rights([inn, True]) == out

0 comments on commit ce9b3ad

Please sign in to comment.