Skip to content

Commit

Permalink
Field method refactor for Ead transform
Browse files Browse the repository at this point in the history
Why these changes are being introduced:
* These updates are required to implement the architecture described
in the following ADR: https://github.com/MITLibraries/transmogrifier/blob/main/docs/adrs/0005-field-methods.md

How this addresses that need:
* Add field methods and corresponding unit tests:
  related_items, rights, subjects

Side effects of this change:
* None

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/TIMX-287
  • Loading branch information
jonavellecuerdo committed Jun 6, 2024
1 parent 79d1b35 commit 0a1dada
Show file tree
Hide file tree
Showing 2 changed files with 334 additions and 79 deletions.
253 changes: 241 additions & 12 deletions tests/sources/xml/test_ead.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,6 @@ def test_ead_transform_with_all_fields_transforms_correctly():
),
relationship="Alternate Format",
),
timdex.RelatedItem(
description=(
"Issues of Twilight Zine were separated for library cataloging."
),
relationship="Separated Material",
),
timdex.RelatedItem(
description="MC-0423 James R. Killian Papers",
),
Expand Down Expand Up @@ -244,6 +238,12 @@ def test_ead_transform_with_all_fields_transforms_correctly():
"(http://www.cjconnick.org/)."
),
),
timdex.RelatedItem(
description=(
"Issues of Twilight Zine were separated for library cataloging."
),
relationship="Separated Material",
),
],
rights=[
timdex.Rights(
Expand Down Expand Up @@ -514,23 +514,23 @@ def test_ead_transform_with_attribute_and_subfield_variations_transforms_correct
),
timdex.RelatedItem(
description="Data with blank head tag",
relationship="Separated Material",
),
timdex.RelatedItem(
description="Data with no head tag",
relationship="Separated Material",
),
timdex.RelatedItem(
description="Data with blank head tag",
description="List data with blank head tag",
),
timdex.RelatedItem(
description="Data with no head tag",
description="List data with no head tag",
),
timdex.RelatedItem(
description="List data with blank head tag",
description="Data with blank head tag",
relationship="Separated Material",
),
timdex.RelatedItem(
description="List data with no head tag",
description="Data with no head tag",
relationship="Separated Material",
),
],
subjects=[
Expand Down Expand Up @@ -1313,6 +1313,235 @@ def test_get_publishers_transforms_correctly_if_fields_missing():
assert Ead.get_publishers(source_record) is None


def test_get_related_items_success():
source_record = create_ead_source_record_stub(
metadata_insert=(
"""
<altformavail>
<head>Location of Copies</head>
<p>
"""
"A use copy of photographic plates in box 4 can be found "
"in the Institute Archives and Special Collections reading room.</p>"
"""
</altformavail>
<separatedmaterial>
<head>Separated Materials</head>
<p>Issues of Twilight Zine were separated for library cataloging.</p>
</separatedmaterial>
"""
),
parent_element="archdesc",
)
assert Ead.get_related_items(source_record) == [
timdex.RelatedItem(
description=(
"A use copy of photographic plates in box 4 can be found "
"in the Institute Archives and Special Collections reading room."
),
relationship="Alternate Format",
),
timdex.RelatedItem(
description="Issues of Twilight Zine were separated for library cataloging.",
relationship="Separated Material",
),
]


def test_get_related_items_transforms_correctly_if_fields_blank():
source_record = create_ead_source_record_stub(
metadata_insert=(
"""
<altformavail></altformavail>
"""
),
parent_element="archdesc",
)
assert Ead.get_related_items(source_record) is None


def test_get_related_items_transforms_correctly_if_fields_missing():
source_record = create_ead_source_record_stub(parent_element="archdesc")
assert Ead.get_related_items(source_record) is None


def test_get_related_items_transforms_correctly_with_related_materials():
source_record = create_ead_source_record_stub(
metadata_insert=(
"""
<relatedmaterial>
<head>Related Materials</head>
<list>
<head>
"""
"Collections at the Institute Archives and Special Collections, "
"Massachusetts Institute of Technology</head>"
"""
<defitem>
<label>MC-0423</label>
<item>James R. Killian Papers</item>
</defitem>
<defitem>
<label>MC-0416</label>
<item>Karl T. Compton Papers</item>
</defitem>
</list>
</relatedmaterial>
<relatedmaterial>
<head>Related Materials</head>
"""
"<p>The Charles J. Connick and Associates Archives are located at "
"the Boston Public Library's Fine Arts Department "
"(http://www.bpl.org/research/finearts.htm).</p>"
"<p>The Charles J. Connick papers, 1901-1949 are located at "
"the Smithsonian Archives of American Art "
"(http://www.aaa.si.edu/collections/charles-j-connick-papers-7235).</p>"
"<p>Information on the Charles J. Connick Stained Glass Foundation "
"may be found at their website (http://www.cjconnick.org/).</p>"
"""
</relatedmaterial>
"""
),
parent_element="archdesc",
)
assert Ead.get_related_items(source_record) == [
timdex.RelatedItem(description="MC-0423 James R. Killian Papers"),
timdex.RelatedItem(description="MC-0416 Karl T. Compton Papers"),
timdex.RelatedItem(
description=(
"The Charles J. Connick and Associates Archives are located at "
"the Boston Public Library's Fine Arts Department "
"(http://www.bpl.org/research/finearts.htm)."
)
),
timdex.RelatedItem(
description=(
"The Charles J. Connick papers, 1901-1949 are located at "
"the Smithsonian Archives of American Art "
"(http://www.aaa.si.edu/collections/charles-j-connick-papers-7235)."
)
),
timdex.RelatedItem(
description=(
"Information on the Charles J. Connick Stained Glass Foundation "
"may be found at their website (http://www.cjconnick.org/)."
)
),
]


def test_get_rights_success():
source_record = create_ead_source_record_stub(
metadata_insert=(
"""
<accessrestrict>
<head>Conditions Governing Access</head>
<p>This collection is open.</p>
</accessrestrict>
<userestrict>
<head>Conditions Governing Use</head>
<p>
"""
"Access to collections in the Department of Distinctive Collections "
"is not authorization to publish. Please see the MIT Libraries "
"Permissions Policy for permission information. Copyright of some items "
"in this collection may be held by respective creators, "
"not by the donor of the collection or MIT."
"""
</p>
</userestrict>
"""
),
parent_element="archdesc",
)
assert Ead.get_rights(source_record) == [
timdex.Rights(
description="This collection is open.", kind="Conditions Governing Access"
),
timdex.Rights(
description=(
"Access to collections in the Department of Distinctive Collections "
"is not authorization to publish. Please see the MIT Libraries "
"Permissions Policy for permission information. Copyright of some items "
"in this collection may be held by respective creators, "
"not by the donor of the collection or MIT."
),
kind="Conditions Governing Use",
),
]


def test_get_rights_transforms_correctly_if_fields_blank():
source_record = create_ead_source_record_stub(
metadata_insert=(
"""
<accessrestrict></accessrestrict>
<userestrict></userestrict>
"""
),
parent_element="archdesc",
)
assert Ead.get_rights(source_record) is None


def test_get_rights_transforms_correctly_if_fields_missing():
source_record = create_ead_source_record_stub(parent_element="archdesc")
assert Ead.get_rights(source_record) is None


def test_get_subjects_success():
source_record = create_ead_source_record_stub(
metadata_insert=(
"""
<controlaccess>
<subject source="aat">Letters (Correspondence)</subject>
</controlaccess>
"""
),
parent_element="archdesc",
)
assert Ead.get_subjects(source_record) == [
timdex.Subject(
value=["Letters (Correspondence)"], kind="Art & Architecture Thesaurus"
)
]


def test_get_subjects_transforms_correctly_if_fields_blank():
source_record = create_ead_source_record_stub(
metadata_insert=(
"""
<controlaccess>
<subject source="aat"></subject>
</controlaccess>
"""
),
parent_element="archdesc",
)
assert Ead.get_subjects(source_record) is None


def test_get_subjects_transforms_correctly_if_fields_missing():
source_record = create_ead_source_record_stub(parent_element="archdesc")
assert Ead.get_subjects(source_record) is None


def test_get_subjects_transforms_correctly_if_source_attribute_missing():
source_record = create_ead_source_record_stub(
metadata_insert=(
"""
<controlaccess>
<subject>Letters (Correspondence)</subject>
</controlaccess>
"""
),
parent_element="archdesc",
)
assert Ead.get_subjects(source_record) == [
timdex.Subject(value=["Letters (Correspondence)"])
]


def test_get_summary_success():
source_record = create_ead_source_record_stub(
metadata_insert=(
Expand Down
Loading

0 comments on commit 0a1dada

Please sign in to comment.