Skip to content

Commit

Permalink
get_content_type
Browse files Browse the repository at this point in the history
  • Loading branch information
jonavellecuerdo committed Jul 23, 2024
1 parent d83c86d commit b1c293a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
12 changes: 12 additions & 0 deletions tests/sources/xml/test_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,18 @@ def test_get_call_numbers_transforms_correctly_if_fields_missing():
assert Marc.get_call_numbers(source_record) is None


def test_get_content_type_success():
source_record = create_marc_source_record_stub()
assert Marc.get_content_type(source_record) == ["Language material"]


def test_get_content_type_transforms_correctly_if_code_blank():
source_record = create_marc_source_record_stub(
leader_field_insert="<leader>03282n m 2200721Ki 4500</leader>"
)
assert Marc.get_content_type(source_record) is None


def test_marc_record_missing_leader_skips_record(caplog):
marc_xml_records = Marc.parse_source_file(
"tests/fixtures/marc/marc_record_missing_leader.xml"
Expand Down
19 changes: 12 additions & 7 deletions transmogrifier/sources/xml/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ def get_optional_fields(self, source_record: Tag) -> dict | None:
# citation not used in MARC

# content_type
if content_type := Marc.json_crosswalk_code_to_name(
self._get_leader_field(source_record)[6:7],
self.marc_content_type_crosswalk,
source_record_id,
"Leader/06",
):
fields["content_type"] = [content_type]
fields["content_type"] = self.get_content_type(source_record)

# contents
for datafield in source_record.find_all("datafield", tag="505"):
Expand Down Expand Up @@ -827,6 +821,17 @@ def get_call_numbers(cls, source_record: Tag) -> list[str] | None:
)
return call_numbers or None

@classmethod
def get_content_type(cls, source_record: Tag) -> list[str] | None:
if content_type := cls.json_crosswalk_code_to_name(
cls._get_leader_field(source_record)[6:7],
cls.marc_content_type_crosswalk,
cls.get_source_record_id(source_record),
"Leader/06",
):
return [content_type]
return None

@staticmethod
def get_main_titles(xml: Tag) -> list[str]:
"""
Expand Down

0 comments on commit b1c293a

Please sign in to comment.