Skip to content

Commit

Permalink
handle case where RDE has no author
Browse files Browse the repository at this point in the history
  • Loading branch information
elichad committed Aug 22, 2024
1 parent 53ade9c commit 2cef956
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rocrate_zenodo/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def build_zenodo_metadata_from_crate(crate: ROCrate) -> Metadata:
"""Given an RO-Crate, collect the metadata to use in Zenodo upload"""
# retrieve author(s)
authors = crate.root_dataset.get("author")
creators = build_zenodo_creator_list(authors)
creators = build_zenodo_creator_list(authors) if authors else []

# retrieve title
title = crate.root_dataset.get("name")
Expand Down
38 changes: 38 additions & 0 deletions test/test_data/no_author_crate/ro-crate-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"@context": "https://w3id.org/ro/crate/1.1/context",
"@graph": [
{
"@id": "ro-crate-metadata.json",
"@type": "CreativeWork",
"conformsTo": {
"@id": "https://w3id.org/ro/crate/1.1"
},
"about": {
"@id": "./"
}
},
{
"@id": "./",
"@type": [
"Dataset",
"LearningResource"
],
"name": "Demo Crate",
"description": "a demo crate for Galaxy training",
"datePublished": "2024-03-08",
"publisher": "https://ror.org/0abcdef00",
"license": {
"@id": "https://spdx.org/licenses/CC-BY-NC-SA-4.0.html",
"@type": "CreativeWork",
"name": "CC BY-NC-SA 4.0 International",
"description": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International"
}
},
{
"@id": "https://ror.org/0abcdef00",
"@type": "Organization",
"name": "Example University",
"url": "https://www.example.org"
}
]
}
21 changes: 21 additions & 0 deletions test/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ def test_build_zenodo_metadata(self):
# Assert
self.assertDictEqual(expected, result_select)

def test_build_zenodo_metadata__no_author(self):
# Arrange
crate_path = "test/test_data/no_author_crate"
crate = ROCrate(crate_path)

expected = {
"title": "Demo Crate",
"upload_type": "dataset",
"description": "a demo crate for Galaxy training",
"creators": [],
"license": "cc-by-nc-sa-4.0",
}

# Act
result = build_zenodo_metadata_from_crate(crate)
result = result.model_dump()
result_select = {key: result[key] for key in result if key in expected}

# Assert
self.assertDictEqual(expected, result_select)

def test_build_zenodo_metadata_fails_with_invalid_data(self):
# Arrange
crate_path = "test/test_data/invalid_data_crate"
Expand Down

0 comments on commit 2cef956

Please sign in to comment.