Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case where RDE has no author #21

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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