Skip to content

Commit

Permalink
get_dates
Browse files Browse the repository at this point in the history
  • Loading branch information
jonavellecuerdo committed Jul 24, 2024
1 parent 26f35ce commit 3f9ca54
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 16 additions & 0 deletions tests/sources/xml/test_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,22 @@ def test_get_contributors_transforms_correctly_if_kind_not_specified():
]


def test_get_dates_success():
source_record = create_marc_source_record_stub()
assert Marc.get_dates(source_record) == [
timdex.Date(kind="Publication date", value="2016")
]


def test_get_dates_transforms_correctly_if_char_positions_blank():
source_record = create_marc_source_record_stub(
control_field_insert=(
'<controlfield tag="008">170906s fr mun| o e zxx d</controlfield>'
)
)
assert Marc.get_dates(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
13 changes: 8 additions & 5 deletions transmogrifier/sources/xml/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ def get_optional_fields(self, source_record: Tag) -> dict | None:
fields["contributors"] = self.get_contributors(source_record)

# dates
publication_year = self._get_control_field(source_record)[7:11].strip()
if validate_date(publication_year, source_record_id):
fields["dates"] = [
timdex.Date(kind="Publication date", value=publication_year)
]
fields["dates"] = self.get_dates(source_record)

# edition
edition_values = []
Expand Down Expand Up @@ -857,6 +853,13 @@ def get_contributors(cls, source_record: Tag) -> list[timdex.Contributor] | None
)
return contributors or None

@classmethod
def get_dates(cls, source_record: Tag) -> list[timdex.Date] | None:
publication_year = cls._get_control_field(source_record)[7:11].strip()
if validate_date(publication_year, cls.get_source_record_id(source_record)):
return [timdex.Date(kind="Publication date", value=publication_year)]
return None

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

0 comments on commit 3f9ca54

Please sign in to comment.