Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans-Chrstian committed Jul 8, 2024
1 parent 0381892 commit 2ad86b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
18 changes: 14 additions & 4 deletions ckanext/fairdatapoint/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,25 @@ def _parse_creator(self, dataset_dict: Dict, dataset_ref: URIRef) -> Dict:
creators = []
for creator_ref in graph.objects(dataset_ref, DCTERMS.creator):
creator = {}

# Handle non-anonymous creator (URIRef) & # handle anonymous creator (BNode)
creator_identifier = graph.value(creator_ref, DCTERMS.identifier)
creator_name = graph.value(creator_ref, FOAF.name)

if creator_identifier:
creator['creator_identifier'] = str(graph.value(creator_ref, DCTERMS.identifier))
creator['creator_identifier'] = str(creator_identifier)
if creator_name:
creator['creator_name'] = str(graph.value(creator_ref, FOAF.name))
creator['creator_name'] = str(creator_name)
else:
# If the creator is a URI, use it as the identifier
if isinstance(creator_ref, URIRef):
creator['creator_identifier'] = str(creator_ref)
# Attempt to get the name from the graph if available
name_from_graph = graph.value(creator_ref, FOAF.name)
if name_from_graph:
creator['creator_name'] = str(name_from_graph)
else:
creator['creator_name'] = str(creator_ref)
else:
creator['creator_name'] = str(creator_ref)

creators.append(creator)

Expand Down
26 changes: 10 additions & 16 deletions ckanext/fairdatapoint/tests/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,21 @@ def test_fdp_record_converter_dataset_dict(self):
"http://purl.org/zonmw/generic/10006;"
"dataset=https://covid19initiatives.health-ri.nl/p/Project/27866022694497978",
record=data)
expected_dataset = {"extras":
[
{"key": "uri", "value": "https://covid19initiatives.health-ri.nl/p/Project/27866022694497978"}
],
"resources": [],
"title": "COVID-NL cohort MUMC+",
"notes": "Clinical data of MUMC COVID-NL cohort",
"tags": [],
"license_id": "",
"identifier": "27866022694497978",
"has_version": ["https://repo.metadatacenter.org/template-instances/2836bf1c-76e9-44e7-a65e-80e9ca63025a"],
"contact_point": [
expected_dataset = dict(extras=[
{"key": "uri", "value": "https://covid19initiatives.health-ri.nl/p/Project/27866022694497978"}
], resources=[], title="COVID-NL cohort MUMC+", notes="Clinical data of MUMC COVID-NL cohort", tags=[],
license_id="", identifier="27866022694497978",
has_version=["https://repo.metadatacenter.org/template-instances/2836bf1c-76e9-44e7-a65e-80e9ca63025a"],
contact_point=[
{
"contact_name": "N.K. De Vries",
"contact_uri": "https://orcid.org/0000-0002-4348-707X",
"contact_email": "",
}
],
"publisher_uri": "https://opal.health-ri.nl/pub/",
"temporal_start": datetime(2020, 1, 1, 0, 0),
"temporal_end": datetime(2025, 12, 31, 0, 0)}
], creator=[{"creator_identifier": "https://orcid.org/0000-0002-0180-3636",
"creator_name": "https://orcid.org/0000-0002-0180-3636"}],
publisher_uri="https://opal.health-ri.nl/pub/", temporal_start=datetime(2020, 1, 1, 0, 0),
temporal_end=datetime(2025, 12, 31, 0, 0))
assert actual_dataset == expected_dataset

def test_fdp_record_converter_catalog_dict(self):
Expand Down

0 comments on commit 2ad86b1

Please sign in to comment.