-
Notifications
You must be signed in to change notification settings - Fork 0
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
Timx 287 ead field method refactor 2 #187
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -586,15 +586,6 @@ def test_ead_transform_with_invalid_date_and_date_range_omits_dates(caplog): | |
assert ("has a later start date than end date: '2001', '1999'") in caplog.text | ||
|
||
|
||
def test_ead_transform_with_multiple_unitid_gets_valid_ids(): | ||
ead_xml_records = Ead.parse_source_file( | ||
"tests/fixtures/ead/ead_record_attribute_and_subfield_variations.xml" | ||
) | ||
output_record = next(Ead("aspace", ead_xml_records)) | ||
for identifier in output_record.identifiers: | ||
assert identifier.value != "unitid-that-should-not-be-identifier" | ||
|
||
|
||
def test_get_alternate_titles_success(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
|
@@ -739,6 +730,284 @@ def test_get_content_type_transforms_correctly_if_fields_missing(): | |
assert Ead.get_content_type(source_record) == ["Archival materials"] | ||
|
||
|
||
def test_get_contents_success(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
""" | ||
<arrangement> | ||
<head>Arrangement</head> | ||
<p>This collection is organized into ten series: </p> | ||
<p>Series 1. Charles J. Connick and Connick Studio documents</p> | ||
<p>Series 2. Charles J. Connick Studio and Associates job information</p> | ||
<p>Series 3. Charles J. Connick Stained Glass Foundation documents</p> | ||
</arrangement> | ||
""" | ||
), | ||
parent_element="archdesc", | ||
) | ||
assert Ead.get_contents(source_record) == [ | ||
"This collection is organized into ten series:", | ||
"Series 1. Charles J. Connick and Connick Studio documents", | ||
"Series 2. Charles J. Connick Studio and Associates job information", | ||
"Series 3. Charles J. Connick Stained Glass Foundation documents", | ||
] | ||
|
||
|
||
def test_get_contents_transforms_correctly_if_fields_blank(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
""" | ||
<arrangement></arrangement> | ||
""" | ||
), | ||
parent_element="archdesc", | ||
) | ||
assert Ead.get_contents(source_record) is None | ||
|
||
|
||
def test_get_contents_transforms_correctly_if_fields_missing(): | ||
source_record = create_ead_source_record_stub(parent_element="archdesc") | ||
assert Ead.get_contents(source_record) is None | ||
|
||
|
||
def test_get_contributors_success(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
""" | ||
<origination label="Creator"> | ||
<persname> | ||
Author, Best E. | ||
<part>( <emph> Best <emph>Ever</emph> </emph> )</part> | ||
</persname> | ||
</origination> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_contributors(source_record) == [ | ||
timdex.Contributor(value="Author, Best E. ( Best Ever )", kind="Creator") | ||
] | ||
Comment on lines
+773
to
+789
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a random example, but really digging these tests. |
||
|
||
|
||
def test_get_contributors_transforms_correctly_if_fields_blank(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
""" | ||
<origination></origination> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_contributors(source_record) is None | ||
|
||
|
||
def test_get_contributors_transforms_correctly_if_fields_missing(): | ||
source_record = create_ead_source_record_stub(parent_element="did") | ||
assert Ead.get_contributors(source_record) is None | ||
|
||
|
||
def test_get_contributors_transforms_correctly_if_multiple_contributors(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
""" | ||
<origination label="Creator"> | ||
<persname> | ||
Author, Best E. | ||
<part>( <emph> Best <emph>Ever</emph> </emph> )</part> | ||
</persname> | ||
<persname> | ||
Author, Better | ||
</persname> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_contributors(source_record) == [ | ||
timdex.Contributor( | ||
value="Author, Best E. ( Best Ever )", | ||
kind="Creator", | ||
), | ||
timdex.Contributor( | ||
value="Author, Better", | ||
kind="Creator", | ||
), | ||
] | ||
|
||
|
||
def test_get_contributors_transforms_correctly_with_source_based_identifiers(): | ||
jonavellecuerdo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
""" | ||
<origination label="Creator"> | ||
<persname authfilenumber="a001" source="naf"> | ||
Author, Best E. | ||
<part>( <emph> Best <emph>Ever</emph> </emph> )</part> | ||
</persname> | ||
<persname authfilenumber="b001" source="viaf"> | ||
Author, Better | ||
</persname> | ||
</origination> | ||
<origination> | ||
<famname authfilenumber="c001" source="snac">Fambam</famname> | ||
</famname> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_contributors(source_record) == [ | ||
timdex.Contributor( | ||
value="Author, Best E. ( Best Ever )", | ||
identifier=["https://lccn.loc.gov/a001"], | ||
kind="Creator", | ||
), | ||
timdex.Contributor( | ||
value="Author, Better", | ||
identifier=["http://viaf.org/viaf/b001"], | ||
kind="Creator", | ||
), | ||
timdex.Contributor( | ||
value="Fambam", identifier=["https://snaccooperative.org/view/c001"] | ||
), | ||
] | ||
|
||
|
||
def test_get_dates_success(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a non-range date value as well so we're testing everything There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change has been made in commit 95b6b47) |
||
source_record = create_ead_source_record_stub( | ||
header_insert=( | ||
""" | ||
<identifier>oai:mit//repositories/2/resources/1</identifier> | ||
""" | ||
), | ||
metadata_insert=( | ||
""" | ||
<unitdate certainty="approximate" datechar="creation" normal="1905/2012"> | ||
1905-2012 | ||
</unitdate> | ||
<unitdate normal="2023-01-01">2023-01-01</unitdate> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_dates(source_record) == [ | ||
timdex.Date( | ||
kind="creation", | ||
note="approximate", | ||
range=timdex.DateRange(gte="1905", lte="2012"), | ||
), | ||
timdex.Date(value="2023-01-01"), | ||
] | ||
|
||
|
||
def test_get_dates_transforms_correctly_if_fields_blank(): | ||
source_record = create_ead_source_record_stub( | ||
header_insert=( | ||
""" | ||
<identifier>oai:mit//repositories/2/resources/1</identifier> | ||
""" | ||
), | ||
metadata_insert=( | ||
""" | ||
<unitdate certainty="approximate" datechar="creation" normal=""></unitdate> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_dates(source_record) is None | ||
|
||
|
||
def test_get_dates_transforms_correctly_if_fields_missing(): | ||
source_record = create_ead_source_record_stub( | ||
header_insert=( | ||
""" | ||
<identifier>oai:mit//repositories/2/resources/1</identifier> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_dates(source_record) is None | ||
|
||
|
||
def test_get_dates_transforms_correctly_if_date_invalid(): | ||
source_record = create_ead_source_record_stub( | ||
header_insert=( | ||
""" | ||
<identifier>oai:mit//repositories/2/resources/1</identifier> | ||
""" | ||
), | ||
metadata_insert=( | ||
""" | ||
<unitdate certainty="approximate" datechar="creation" normal=""> | ||
INVALID | ||
</unitdate> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_dates(source_record) is None | ||
|
||
|
||
def test_get_dates_transforms_correctly_if_normal_attribute_missing(): | ||
source_record = create_ead_source_record_stub( | ||
header_insert=( | ||
""" | ||
<identifier>oai:mit//repositories/2/resources/1</identifier> | ||
""" | ||
), | ||
metadata_insert=( | ||
""" | ||
<unitdate certainty="approximate" datechar="creation">2024</unitdate> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_dates(source_record) is None | ||
|
||
|
||
def test_get_identifiers_success(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
""" | ||
<unitid>a001</unitid> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_identifiers(source_record) == [ | ||
timdex.Identifier(value="a001", kind="Collection Identifier") | ||
] | ||
|
||
|
||
def test_get_identifiers_transforms_correctly_if_fields_blank(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
""" | ||
<unitid></unitid> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_identifiers(source_record) is None | ||
|
||
|
||
def test_get_identifiers_transforms_correctly_if_fields_missing(): | ||
source_record = create_ead_source_record_stub( | ||
parent_element="did", | ||
) | ||
assert Ead.get_identifiers(source_record) is None | ||
|
||
|
||
def test_get_identifiers_transforms_correctly_if_type_attribute_invalid(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
""" | ||
<unitid type="aspace_uri">ignore-me</unitid> | ||
""" | ||
), | ||
parent_element="did", | ||
) | ||
assert Ead.get_identifiers(source_record) is None | ||
|
||
|
||
def test_get_main_titles_success(): | ||
source_record = create_ead_source_record_stub( | ||
metadata_insert=( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ehanson8 Related to #185 (comment). I removed the test and in its place are the tests for the new
get_identifiers
field method. 🤓