From 1f8f797db96a90197e0820bfbfe8bd11f69eb27b Mon Sep 17 00:00:00 2001 From: Eli Chadwick Date: Wed, 21 Aug 2024 11:10:30 +0100 Subject: [PATCH 1/6] simplify tests with fixtures --- test/unit/test_publisher.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/test/unit/test_publisher.py b/test/unit/test_publisher.py index a3e45e3..77db2c8 100644 --- a/test/unit/test_publisher.py +++ b/test/unit/test_publisher.py @@ -22,16 +22,26 @@ } -@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() + + +# @pytest.mark.xfail( +# reason="known bug - https://github.com/ResearchObject/ro-crate-inveniordm/issues/1" +# ) +def test_publisher_string(rc, dc): rc, _ = set_field_in_template_rde("publisher", publisher_string, rc) rule_name = "publisher_mapping_1" rule = get_single_mapping("publisher", rule_name) paths = get_mapping_paths(rc, {rule_name: rule}) - dc = setup_dc() dc, _ = apply_mapping(rule, paths, rc, dc) @@ -39,16 +49,13 @@ def test_publisher_string(): assert dc["metadata"]["publisher"] == publisher_string -def test_publisher_entity(): - rc = load_template_rc() +def test_publisher_entity(rc, dc): 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 = get_single_mapping("publisher", rule_name) paths = get_mapping_paths(rc, {rule_name: rule}) dc, _ = apply_mapping(rule, paths, rc, dc) - print(dc) assert dc["metadata"]["publisher"] == publisher_entity["name"] From 0576ee4ce8cc6cdf34a52d00ebe1b68ebaf09610 Mon Sep 17 00:00:00 2001 From: Eli Chadwick Date: Wed, 21 Aug 2024 11:10:42 +0100 Subject: [PATCH 2/6] remove xfail test --- test/unit/test_publisher.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/unit/test_publisher.py b/test/unit/test_publisher.py index 77db2c8..bc65e90 100644 --- a/test/unit/test_publisher.py +++ b/test/unit/test_publisher.py @@ -34,9 +34,6 @@ def dc(): return setup_dc() -# @pytest.mark.xfail( -# reason="known bug - https://github.com/ResearchObject/ro-crate-inveniordm/issues/1" -# ) def test_publisher_string(rc, dc): rc, _ = set_field_in_template_rde("publisher", publisher_string, rc) rule_name = "publisher_mapping_1" From a8dfb348839f14375d0dd2b965d143b6734b1961 Mon Sep 17 00:00:00 2001 From: Eli Chadwick Date: Tue, 11 Jun 2024 10:11:32 +0100 Subject: [PATCH 3/6] add default publisher mapping rule --- src/rocrate_inveniordm/mapping/mapping.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rocrate_inveniordm/mapping/mapping.json b/src/rocrate_inveniordm/mapping/mapping.json index a08a3b4..b69bf24 100644 --- a/src/rocrate_inveniordm/mapping/mapping.json +++ b/src/rocrate_inveniordm/mapping/mapping.json @@ -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" } From 74bab8f76293b347286658debda90b5bd77fa311 Mon Sep 17 00:00:00 2001 From: Eli Chadwick Date: Wed, 21 Aug 2024 11:13:12 +0100 Subject: [PATCH 4/6] update publisher tests --- test/unit/test_publisher.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/unit/test_publisher.py b/test/unit/test_publisher.py index bc65e90..15eb213 100644 --- a/test/unit/test_publisher.py +++ b/test/unit/test_publisher.py @@ -35,24 +35,29 @@ def 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}) + # Act dc, _ = apply_mapping(rule, paths, rc, dc) - print(dc) + # Assert assert dc["metadata"]["publisher"] == publisher_string 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) - 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) + # Assert assert dc["metadata"]["publisher"] == publisher_entity["name"] From 9dc5e98f3a62a9e7516ed65fabed66952a74d68f Mon Sep 17 00:00:00 2001 From: Eli Chadwick Date: Wed, 21 Aug 2024 11:28:08 +0100 Subject: [PATCH 5/6] update docs and integration test data --- docs/all-mappings.md | 3 ++- test/data/datacite-out-utf-8-csv-crate.json | 4 ++-- test/data/utf-8-csv-crate/ro-crate-metadata.json | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/all-mappings.md b/docs/all-mappings.md index 6f0e733..bdb7bfd 100644 --- a/docs/all-mappings.md +++ b/docs/all-mappings.md @@ -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 entity, maps `publisher.name` to `metadata.publisher` - if no publisher exists, the value is `:unkn` ## Mapping of identifier diff --git a/test/data/datacite-out-utf-8-csv-crate.json b/test/data/datacite-out-utf-8-csv-crate.json index 9a39985..e17dc21 100644 --- a/test/data/datacite-out-utf-8-csv-crate.json +++ b/test/data/datacite-out-utf-8-csv-crate.json @@ -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": { diff --git a/test/data/utf-8-csv-crate/ro-crate-metadata.json b/test/data/utf-8-csv-crate/ro-crate-metadata.json index 9fd7bed..3687778 100644 --- a/test/data/utf-8-csv-crate/ro-crate-metadata.json +++ b/test/data/utf-8-csv-crate/ro-crate-metadata.json @@ -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", From 82ff8e482df5dfdbdcc6fcd0cd5e19f0c82248a9 Mon Sep 17 00:00:00 2001 From: Eli Chadwick Date: Fri, 23 Aug 2024 14:29:16 +0100 Subject: [PATCH 6/6] "entity" -> "object" --- docs/all-mappings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/all-mappings.md b/docs/all-mappings.md index bdb7bfd..abdc2df 100644 --- a/docs/all-mappings.md +++ b/docs/all-mappings.md @@ -76,7 +76,7 @@ Note that RO-Crate and DataCite each contain features that the other does not ha ## Mapping of publisher - if `publisher` is a string, maps `publisher` to `metadata.publisher` -- if `publisher` is an entity, maps `publisher.name` 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