-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Springshare testing and convention following
Why these changes are being introduced: * Updates stemming from code review for PR #99 How this addresses that need: * updated test naming * additional tests for OaiDc get_dates() and get_links() hooks * fallback on default citation generator * ensure usage of str(<BS4_element.string) for memory concerns Side effects of this change: * None Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/TIMX-227
- Loading branch information
Showing
10 changed files
with
198 additions
and
76 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
tests/fixtures/oai_dc/springshare/springshare_invalid_dates.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<records> | ||
<record xmlns:dc="http://purl.org/dc/elements/1.1/"> | ||
<dc:date>200000000-01-01</dc:date> | ||
</record> | ||
<record xmlns:dc="http://purl.org/dc/elements/1.1/"> | ||
<dc:date>Not found</dc:date> | ||
</record> | ||
<record xmlns:dc="http://purl.org/dc/elements/1.1/"> | ||
<dc:date></dc:date> | ||
</record> | ||
<record xmlns:dc="http://purl.org/dc/elements/1.1/"></record> | ||
</records> |
24 changes: 24 additions & 0 deletions
24
tests/fixtures/oai_dc/springshare/springshare_record_missing_required_fields.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<records> | ||
<record xmlns="http://www.openarchives.org/OAI/2.0/" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<header> | ||
<identifier>oai:libguides.com:guides/175846</identifier> | ||
<datestamp>2023-05-31T19:49:21Z</datestamp> | ||
<setSpec>guides</setSpec> | ||
</header> | ||
<metadata> | ||
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" | ||
xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> | ||
<dc:creator>Ye Li</dc:creator> | ||
<dc:subject>Engineering</dc:subject> | ||
<dc:subject>Science</dc:subject> | ||
<dc:description>Useful databases and other research tips for materials science.</dc:description> | ||
<dc:publisher>MIT Libraries</dc:publisher> | ||
<dc:date>2008-06-19T17:55:27</dc:date> | ||
</oai_dc:dc> | ||
</metadata> | ||
</record> | ||
</records> |
8 changes: 8 additions & 0 deletions
8
tests/fixtures/oai_dc/springshare/springshare_valid_dates.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<records> | ||
<record xmlns:dc="http://purl.org/dc/elements/1.1/"> | ||
<dc:date>2000-01-01</dc:date> | ||
</record> | ||
<record xmlns:dc="http://purl.org/dc/elements/1.1/"> | ||
<dc:date>January 1st, 2000</dc:date> | ||
</record> | ||
</records> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import transmogrifier.models as timdex | ||
from transmogrifier.helpers import parse_xml_records | ||
from transmogrifier.sources.springshare import SpringshareOaiDc | ||
|
||
FIXTURES_PREFIX = "tests/fixtures/oai_dc/springshare" | ||
|
||
|
||
def test_springshare_get_dates_valid(): | ||
""" | ||
Test for valid date parsing | ||
""" | ||
|
||
input_records = parse_xml_records(f"{FIXTURES_PREFIX}/springshare_valid_dates.xml") | ||
transformer_instance = SpringshareOaiDc("libguides", input_records) | ||
|
||
# asser valid dates | ||
for xml in transformer_instance.input_records: | ||
date_field_val = transformer_instance.get_dates("test_get_dates", xml) | ||
assert date_field_val == [ | ||
timdex.Date(kind=None, note=None, range=None, value="2000-01-01T00:00:00") | ||
] | ||
|
||
|
||
def test_springshare_get_dates_invalid(caplog): | ||
""" | ||
Tests that bad, missing, or blank data will log and continue to process | ||
""" | ||
|
||
input_records = parse_xml_records( | ||
f"{FIXTURES_PREFIX}/springshare_invalid_dates.xml" | ||
) | ||
transformer_instance = SpringshareOaiDc("libguides", input_records) | ||
|
||
# assert error handling for invalid dates | ||
for xml in transformer_instance.input_records: | ||
date_field_val = transformer_instance.get_dates("test_get_dates", xml) | ||
assert date_field_val is None | ||
assert "could not parse date for Springshare record" in caplog.text | ||
|
||
|
||
def test_springshare_get_links_missing_identifier(caplog): | ||
""" | ||
Tests that links does logs error and continues to process when dc:identifier is absent | ||
""" | ||
|
||
input_records = parse_xml_records( | ||
f"{FIXTURES_PREFIX}/springshare_record_missing_required_fields.xml" | ||
) | ||
transformer_instance = SpringshareOaiDc("libguides", input_records) | ||
|
||
# assert error handling for invalid dates | ||
for xml in transformer_instance.input_records: | ||
links_field_val = transformer_instance.get_links("test_get_links", xml) | ||
assert links_field_val is None | ||
assert "cannot generate links for Springshare record" in caplog.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.