From 0faf51434072dfcc43b024d449ded848805a1518 Mon Sep 17 00:00:00 2001 From: Eric Hanson Date: Mon, 9 May 2022 15:30:35 -0400 Subject: [PATCH] Add tests to account for lack of name type attribute * Modify identifier url methods to account for lack of type attribute * Add unit tests and fixtures where type attribute is missing --- tests/conftest.py | 14 +++ .../jpal_record_no_name_identifier_scheme.xml | 75 ++++++++++++ ...record_related_item_no_identifier_type.xml | 111 ++++++++++++++++++ tests/test_datacite.py | 19 +++ transmogrifier/sources/datacite.py | 4 +- 5 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/datacite/jpal_record_no_name_identifier_scheme.xml create mode 100644 tests/fixtures/datacite/jpal_record_related_item_no_identifier_type.xml diff --git a/tests/conftest.py b/tests/conftest.py index 1118c17..479b295 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -74,6 +74,13 @@ def datacite_jpal_record_unknown_name_identifier(): ) +@pytest.fixture() +def datacite_jpal_record_no_name_identifier_scheme(): + return parse_xml_records( + "tests/fixtures/datacite/jpal_record_no_name_identifier_scheme.xml" + ) + + @pytest.fixture() def datacite_jpal_record_related_item_identifier_doi_type(): return parse_xml_records( @@ -88,6 +95,13 @@ def datacite_jpal_record_related_item_identifier_unknown_type(): ) +@pytest.fixture() +def datacite_jpal_record_related_item_no_identifier_type(): + return parse_xml_records( + "tests/fixtures/datacite/jpal_record_related_item_no_identifier_type.xml" + ) + + @pytest.fixture() def datacite_record_partial(): return partial( diff --git a/tests/fixtures/datacite/jpal_record_no_name_identifier_scheme.xml b/tests/fixtures/datacite/jpal_record_no_name_identifier_scheme.xml new file mode 100644 index 0000000..b68a0ea --- /dev/null +++ b/tests/fixtures/datacite/jpal_record_no_name_identifier_scheme.xml @@ -0,0 +1,75 @@ + + +
+ doi:10.7910/DVN/19PPE7 + 2022-03-26T06:04:55Z + Jameel_Poverty_Action_Lab + IQSS +
+ + + 10.7910/DVN/19PPE7 + + The Impact of Maternal Literacy and Participation Programs: Evidence from a Randomized Evaluation in India + + Harvard Dataverse + 2017 + + Social Sciences + Adult education, education inputs, field experiments + + + + Banerji, Rukmini + Rukmini + Banerji + 0000-0000-0000-0000 + Pratham and ASER Centre + + + + 2017-02-27 + 2019-06-24 + + Survey Data + + 10.1257/app.20150390 + + + 124903 + 48958 + 199070 + 186674 + 139605 + 97304 + 9907 + 178534602 + 4032103 + 43589 + 15697 + + + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + application/pdf + application/pdf + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + application/pdf + application/x-stata-syntax + application/x-stata + application/x-stata + application/zip + application/pdf + application/pdf + + 1.2 + + + CC0 1.0 + + + Using a randomized field experiment in India, we evaluate the effectiveness of adult literacy and parental involvement interventions in improving children's learning. Households were assigned to receive either adult literacy (language and math) classes for mothers, training for mothers on how to enhance their children's learning at home, or a combination of the two programs. All three interventions had significant but modest impacts on childrens math scores. The interventions also increased mothers' test scores in both language and math, as well as a range of other outcomes reflecting greater involvement of mothers in their children's education. + + + + +
\ No newline at end of file diff --git a/tests/fixtures/datacite/jpal_record_related_item_no_identifier_type.xml b/tests/fixtures/datacite/jpal_record_related_item_no_identifier_type.xml new file mode 100644 index 0000000..d84cb05 --- /dev/null +++ b/tests/fixtures/datacite/jpal_record_related_item_no_identifier_type.xml @@ -0,0 +1,111 @@ + + +
+ doi:10.7910/DVN/19PPE7 + 2022-03-26T06:04:55Z + Jameel_Poverty_Action_Lab + IQSS +
+ + + 10.7910/DVN/19PPE7 + + + Banerji, Rukmini + Rukmini + Banerji + Pratham and ASER Centre + 0000-0000-0000-0000 + + + Berry, James + James + Berry + University of Delaware + + + Shotland, Marc + Marc + Shotland + Abdul Latif Jameel Poverty Action Lab + + + + The Impact of Maternal Literacy and Participation Programs + An Alternative Title + Baseline Data + + Harvard Dataverse + 2017 + + Social Sciences + Adult education, education inputs, field experiments + + + + Banerji, Rukmini + Rukmini + Banerji + 0000-0000-0000-0000 + Pratham and ASER Centre + + + + 2017-02-27 + 2019-06-24 + + Survey Data + + 0000.0000 + + en_US + + 124903 + 48958 + 199070 + 186674 + 139605 + 97304 + 9907 + 178534602 + 4032103 + 43589 + 15697 + + + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + application/pdf + application/pdf + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + application/pdf + application/x-stata-syntax + application/x-stata + application/x-stata + application/zip + application/pdf + application/pdf + + 1.2 + + + CC0 1.0 + + + Using a randomized field experiment in India, we evaluate the effectiveness of adult literacy and parental involvement interventions in improving children's learning. Households were assigned to receive either adult literacy (language and math) classes for mothers, training for mothers on how to enhance their children's learning at home, or a combination of the two programs. All three interventions had significant but modest impacts on childrens math scores. The interventions also increased mothers' test scores in both language and math, as well as a range of other outcomes reflecting greater involvement of mothers in their children's education. + Stata, 13 + + + + A point on the globe + + + + + 3ie, Nike Foundation + 0987 + OW1/1012 (3ie) + + + + +
\ No newline at end of file diff --git a/tests/test_datacite.py b/tests/test_datacite.py index 85ed5e3..09e6fb1 100644 --- a/tests/test_datacite.py +++ b/tests/test_datacite.py @@ -262,6 +262,15 @@ def test_generate_name_identifier_url_unknown_scheme( assert next(output_records).contributors[0].identifier == ["0000-0000-0000-0000"] +def test_generate_name_identifier_url_no_identifier_scheme( + datacite_record_partial, datacite_jpal_record_no_name_identifier_scheme +): + output_records = datacite_record_partial( + input_records=datacite_jpal_record_no_name_identifier_scheme + ) + assert next(output_records).contributors[0].identifier == ["0000-0000-0000-0000"] + + def test_generate_related_item_identifier_url_doi_type( datacite_record_partial, datacite_jpal_record_related_item_identifier_doi_type ): @@ -278,3 +287,13 @@ def test_generate_related_item_identifier_url_unknown_type( input_records=datacite_jpal_record_related_item_identifier_unknown_type ) assert next(output_records).related_items[0].uri == "0000.0000" + + +def test_generate_related_item_identifier_no_identifier_type( + datacite_record_partial, + datacite_jpal_record_related_item_no_identifier_type, +): + output_records = datacite_record_partial( + input_records=datacite_jpal_record_related_item_no_identifier_type + ) + assert next(output_records).related_items[0].uri == "0000.0000" diff --git a/transmogrifier/sources/datacite.py b/transmogrifier/sources/datacite.py index 2131eda..4aa1d21 100644 --- a/transmogrifier/sources/datacite.py +++ b/transmogrifier/sources/datacite.py @@ -294,7 +294,7 @@ def generate_name_identifier_url(cls, name_identifier): name_identifier: An BeautifulSoup Tag Tag representing a Datacite nameIdentifier XML field. """ - if name_identifier["nameIdentifierScheme"] == "ORCID": + if name_identifier.get("nameIdentifierScheme") == "ORCID": base_url = "https://orcid.org/" else: base_url = "" @@ -308,7 +308,7 @@ def generate_related_item_identifier_url(cls, related_item_identifier): related_item_identifier: An BeautifulSoup Tag Tag representing a Datacite relatedIdentifier XML field. """ - if related_item_identifier["relatedIdentifierType"] == "DOI": + if related_item_identifier.get("relatedIdentifierType") == "DOI": base_url = "https://doi.org/" else: base_url = ""