From fbb80fb6e1bb58292a607bee5599af795e717f95 Mon Sep 17 00:00:00 2001 From: jonavellecuerdo Date: Fri, 31 May 2024 14:28:56 -0400 Subject: [PATCH] Update tests * Add tests for field methods: languages, locations, notes physical description, publishers, summary --- tests/sources/xml/test_ead.py | 342 ++++++++++++++++++++++++++++++++++ 1 file changed, 342 insertions(+) diff --git a/tests/sources/xml/test_ead.py b/tests/sources/xml/test_ead.py index ee4599a..5875399 100644 --- a/tests/sources/xml/test_ead.py +++ b/tests/sources/xml/test_ead.py @@ -1008,6 +1008,311 @@ def test_get_identifiers_transforms_correctly_if_type_attribute_invalid(): assert Ead.get_identifiers(source_record) is None +def test_get_languages_success(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + English + , + French + . + + """ + ), + parent_element="did", + ) + assert Ead.get_languages(source_record) == ["English", "French"] + + +def test_get_languages_transforms_correctly_if_fields_blank(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + """ + ), + parent_element="did", + ) + assert Ead.get_languages(source_record) is None + + +def test_get_languages_transforms_correctly_if_fields_missing(): + source_record = create_ead_source_record_stub(parent_element="did") + assert Ead.get_languages(source_record) is None + + +def test_get_locations_success(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + Boston, MA + + + + Bibliography + + + <part>Affiches americaines</part> + + San Domingo: + Imprimerie + royale du Cap, 1782. Nos. 30, 35. + + + """ + ), + parent_element="archdesc", + ) + assert Ead.get_notes(source_record) == [ + timdex.Note( + value=[ + ( + "Affiches americaines San Domingo: " + "Imprimerie royale du Cap, 1782. Nos. 30, 35." + ) + ], + kind="Bibliography", + ) + ] + + +def test_get_notes_transforms_correctly_if_fields_blank(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + + + """ + ), + parent_element="archdesc", + ) + assert Ead.get_notes(source_record) is None + + +def test_get_notes_transforms_correctly_if_fields_missing(): + source_record = create_ead_source_record_stub(parent_element="archdesc") + assert Ead.get_notes(source_record) is None + + +def test_get_notes_transforms_correctly_with_multiple_kinds(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + Bibliography + + + <part>Affiches americaines</part> + + San Domingo: + Imprimerie + royale du Cap, 1782. Nos. 30, 35. + + + + Biographical Note +

+ """ + "Charles J. Connick (1875-1945) was an American " + "stained glass artist whose work may be found " + "in cities all across the United States." + """ +

+

Connick founded his own studio in 1912 in Boston.

+
+ """ + ), + parent_element="archdesc", + ) + assert Ead.get_notes(source_record) == [ + timdex.Note( + value=[ + ( + "Affiches americaines San Domingo: " + "Imprimerie royale du Cap, 1782. Nos. 30, 35." + ) + ], + kind="Bibliography", + ), + timdex.Note( + value=[ + ( + "Charles J. Connick (1875-1945) was an American " + "stained glass artist whose work may be found " + "in cities all across the United States." + ), + "Connick founded his own studio in 1912 in Boston.", + ], + kind="Biographical Note", + ), + ] + + +def test_get_notes_transforms_correctly_if_head_missing(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + + + <part>Affiches americaines</part> + + San Domingo: + Imprimerie + royale du Cap, 1782. Nos. 30, 35. + + + """ + ), + parent_element="archdesc", + ) + assert Ead.get_notes(source_record) == [ + timdex.Note( + value=[ + ( + "Affiches americaines San Domingo: " + "Imprimerie royale du Cap, 1782. Nos. 30, 35." + ) + ], + kind="Bibliography", + ) + ] + + +def test_get_physical_description_success(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + 4.5 Cubic Feet + + (10 manuscript boxes, 1 legal manuscript box, 1 cassette box) + + + """ + ), + parent_element="did", + ) + assert Ead.get_physical_description(source_record) == ( + "4.5 Cubic Feet (10 manuscript boxes, 1 legal manuscript box, 1 cassette box)" + ) + + +def test_get_physical_description_transforms_correctly_if_fields_blank(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + """ + ), + parent_element="did", + ) + assert Ead.get_physical_description(source_record) is None + + +def test_get_physical_description_transforms_correctly_if_fields_missing(): + source_record = create_ead_source_record_stub(parent_element="did") + assert Ead.get_physical_description(source_record) is None + + +def test_get_physical_description_transforms_correctly_if_multiple_physdesc(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + 4.5 Cubic Feet + + (10 manuscript boxes, 1 legal manuscript box, 1 cassette box) + + + + 1.5 Cubic Feet + (2 manuscript boxes) + + """ + ), + parent_element="did", + ) + assert Ead.get_physical_description(source_record) == ( + "4.5 Cubic Feet (10 manuscript boxes, 1 legal manuscript box, 1 cassette box); " + "1.5 Cubic Feet (2 manuscript boxes)" + ) + + +def test_get_publishers_success(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + + Massachusetts + Institute + of Technology. Libraries. Department of Distinctive Collections + + + """ + ), + parent_element="did", + ) + assert Ead.get_publishers(source_record) == [ + timdex.Publisher( + name=( + "Massachusetts Institute of Technology. Libraries. " + "Department of Distinctive Collections" + ) + ) + ] + + +def test_get_publishers_transforms_correctly_if_fields_blank(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + """ + ), + parent_element="did", + ) + assert Ead.get_publishers(source_record) is None + + +def test_get_publishers_transforms_correctly_if_fields_missing(): + source_record = create_ead_source_record_stub(parent_element="did") + assert Ead.get_publishers(source_record) is None + + def test_get_main_titles_success(): source_record = create_ead_source_record_stub( metadata_insert=( @@ -1051,3 +1356,40 @@ def test_get_main_titles_transforms_correctly_if_fields_blank(): def test_get_main_titles_transforms_correctly_if_fields_missing(): source_record = create_ead_source_record_stub(parent_element="did") assert Ead.get_main_titles(source_record) == [] + + +def test_get_summary_success(): + source_record = create_ead_source_record_stub( + metadata_insert=( + "" + "A record of the MIT faculty begins with " + "the minutes of the September 25, 1865, " + "meeting and continues to the present day." + "" + ), + parent_element="did", + ) + assert Ead.get_summary(source_record) == [ + ( + "A record of the MIT faculty begins with " + "the minutes of the September 25, 1865, " + "meeting and continues to the present day." + ) + ] + + +def test_get_summary_transforms_correctly_if_fields_blank(): + source_record = create_ead_source_record_stub( + metadata_insert=( + """ + + """ + ), + parent_element="did", + ) + assert Ead.get_summary(source_record) is None + + +def test_get_summary_transforms_correctly_if_fields_missing(): + source_record = create_ead_source_record_stub(parent_element="did") + assert Ead.get_summary(source_record) is None