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 publisher is a string rather than an entity #35

Merged
merged 6 commits 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
3 changes: 2 additions & 1 deletion docs/all-mappings.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ Note that RO-Crate and DataCite each contain features that the other does not ha

## Mapping of publisher

- maps `publisher.name` to `metadata.publisher`
- if `publisher` is a string, maps `publisher` to `metadata.publisher`
- if `publisher` is an object, maps `publisher.name` to `metadata.publisher`
- if no publisher exists, the value is `:unkn`

## Mapping of identifier
Expand Down
7 changes: 6 additions & 1 deletion src/rocrate_inveniordm/mapping/mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,12 @@

"publisher_mapping": {
"mappings": {
"publisher_mapping_1": {
"publisher_mapping_direct": {
"from": "publisher",
"to": "metadata.publisher",
"onlyIf": "?string"
},
"publisher_mapping_name": {
"from": "$publisher.name",
"to": "metadata.publisher"
}
Expand Down
4 changes: 2 additions & 2 deletions test/data/datacite-out-utf-8-csv-crate.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
],
"title": "Demo Crate",
"publication_date": "2024-03-08",
"description": "a demo crate for Galaxy training",
"publisher": ":unkn",
"description": "a demo crate for testing",
"publisher": "Test Organization",
"rights": [
{
"title": {
Expand Down
4 changes: 2 additions & 2 deletions test/data/utf-8-csv-crate/ro-crate-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"LearningResource"
],
"name": "Demo Crate",
"description": "a demo crate for Galaxy training",
"description": "a demo crate for testing",
"datePublished": "2024-03-08",
"publisher": "https://ror.org/0abcdef00",
"publisher": "Test Organization",
"license": {
"@id": "https://spdx.org/licenses/CC-BY-NC-SA-4.0.html",
"@type": "CreativeWork",
Expand Down
35 changes: 22 additions & 13 deletions test/unit/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,42 @@
}


@pytest.mark.xfail(
reason="known bug - https://github.com/ResearchObject/ro-crate-inveniordm/issues/1"
)
def test_publisher_string():
rc = load_template_rc()
@pytest.fixture(scope="module", autouse=True)
def rc():
"""Creates template RO-Crate metadata."""
return load_template_rc()


@pytest.fixture(scope="module", autouse=True)
def dc():
"""Creates template DataCite metadata."""
return setup_dc()


def test_publisher_string(rc, dc):
# Arrange
rc, _ = set_field_in_template_rde("publisher", publisher_string, rc)
rule_name = "publisher_mapping_1"
rule_name = "publisher_mapping_direct"
rule = get_single_mapping("publisher", rule_name)
paths = get_mapping_paths(rc, {rule_name: rule})
dc = setup_dc()

# Act
dc, _ = apply_mapping(rule, paths, rc, dc)

print(dc)
# Assert
assert dc["metadata"]["publisher"] == publisher_string


def test_publisher_entity():
rc = load_template_rc()
def test_publisher_entity(rc, dc):
# Arrange
rc = add_entity_to_template(publisher_entity, rc)
rc, _ = set_field_in_template_rde("publisher", {"@id": publisher_entity["@id"]}, rc)
dc = setup_dc()
rule_name = "publisher_mapping_1"
rule_name = "publisher_mapping_name"
rule = get_single_mapping("publisher", rule_name)
paths = get_mapping_paths(rc, {rule_name: rule})

# Act
dc, _ = apply_mapping(rule, paths, rc, dc)

print(dc)
# Assert
assert dc["metadata"]["publisher"] == publisher_entity["name"]