diff --git a/tests/sources/xml/test_oai_dc.py b/tests/sources/xml/test_oai_dc.py index 6822fd2..bb21257 100644 --- a/tests/sources/xml/test_oai_dc.py +++ b/tests/sources/xml/test_oai_dc.py @@ -1,12 +1,11 @@ import pytest - from bs4 import BeautifulSoup import transmogrifier.models as timdex from transmogrifier.sources.xml.oaidc import OaiDc -def create_oai_dc_source_record_stub(xml_insert: str = "") -> BeautifulSoup: +def create_oaidc_source_record_stub(xml_insert: str = "") -> BeautifulSoup: xml_str = f""" @@ -29,7 +28,7 @@ def create_oai_dc_source_record_stub(xml_insert: str = "") -> BeautifulSoup: return BeautifulSoup(xml_str, "xml") -def test_oai_dc_transform_with_all_fields_transforms_correctly(): +def test_oaidc_transform_with_all_fields_transforms_correctly(): source_records = OaiDc.parse_source_file( "tests/fixtures/oai_dc/oaidc_record_all_fields.xml" ) @@ -83,7 +82,7 @@ def test_oaidc_transform_with_optional_fields_blank_transforms_correctly(): ) -def test_oai_dc_transform_with_optional_fields_missing_transforms_correctly(): +def test_oaidc_transform_with_optional_fields_missing_transforms_correctly(): source_records = OaiDc.parse_source_file( "tests/fixtures/oai_dc/oaidc_record_optional_fields_missing.xml" ) @@ -121,7 +120,7 @@ def test_get_content_type_raises_key_error_if_source_missing(oai_dc_record_all_f def test_get_contributors_success(): - source_record = create_oai_dc_source_record_stub( + source_record = create_oaidc_source_record_stub( """ Ye Li """ @@ -147,12 +146,12 @@ def test_get_contributors_transforms_correctly_if_fields_missing( def test_get_dates_success(): - source_record = create_oai_dc_source_record_stub( + source_record = create_oaidc_source_record_stub( """ 2008-06-19T17:55:27 """ ) - assert OaiDc.get_dates(source_record_id="abc", source_record=source_record) == [ + assert OaiDc.get_dates(source_record=source_record, source_record_id="abc") == [ timdex.Date(kind="Unknown", value="2008-06-19T17:55:27") ] @@ -162,7 +161,7 @@ def test_get_dates_transforms_correctly_if_fields_blank( ): assert ( OaiDc.get_dates( - source_record_id="abc", source_record=oai_dc_record_optional_fields_blank + source_record=oai_dc_record_optional_fields_blank, source_record_id="abc" ) == [] ) @@ -173,19 +172,19 @@ def test_get_dates_transforms_correctly_if_fields_missing( ): assert ( OaiDc.get_dates( - source_record_id="abc", source_record=oai_dc_record_optional_fields_missing + source_record=oai_dc_record_optional_fields_missing, source_record_id="abc" ) == [] ) def test_get_dates_transforms_correctly_if_date_invalid(): - source_record = create_oai_dc_source_record_stub( + source_record = create_oaidc_source_record_stub( """ INVALID """ ) - assert OaiDc.get_dates(source_record_id="abc", source_record=source_record) == [] + assert OaiDc.get_dates(source_record=source_record, source_record_id="abc") == [] def test_get_identifiers_success(oai_dc_record_all_fields): @@ -209,7 +208,7 @@ def test_get_identifiers_transforms_correctly_if_fields_missing( def test_get_publishers_success(): - source_record = create_oai_dc_source_record_stub( + source_record = create_oaidc_source_record_stub( """ MIT Libraries """ @@ -230,7 +229,7 @@ def test_get_publishers_transforms_correctly_if_fields_missing( def test_get_subjects_success(): - source_record = create_oai_dc_source_record_stub( + source_record = create_oaidc_source_record_stub( """ Engineering Science @@ -256,10 +255,10 @@ def test_get_subjects_transforms_correctly_if_fields_missing( def test_get_summary_success(): - source_record = create_oai_dc_source_record_stub( + source_record = create_oaidc_source_record_stub( """ Useful databases and other research tips for materials science. - """ + """ # noqa: E501 ) assert OaiDc.get_summary(source_record) == [ "Useful databases and other research tips for materials science." @@ -279,7 +278,7 @@ def test_get_summary_transforms_properly_if_fields_missing( def test_get_main_titles_success(): - source_record = create_oai_dc_source_record_stub( + source_record = create_oaidc_source_record_stub( """ Materials Science & Engineering """ @@ -288,7 +287,7 @@ def test_get_main_titles_success(): def test_get_main_titles_transforms_properly_if_fields_blank(): - source_record = create_oai_dc_source_record_stub( + source_record = create_oaidc_source_record_stub( """ """ @@ -297,7 +296,7 @@ def test_get_main_titles_transforms_properly_if_fields_blank(): def test_get_main_titles_transforms_properly_if_fields_missing(): - source_record = create_oai_dc_source_record_stub() + source_record = create_oaidc_source_record_stub() assert OaiDc.get_main_titles(source_record) == [] diff --git a/transmogrifier/sources/xml/oaidc.py b/transmogrifier/sources/xml/oaidc.py index 0f0c637..f2531b1 100644 --- a/transmogrifier/sources/xml/oaidc.py +++ b/transmogrifier/sources/xml/oaidc.py @@ -44,7 +44,7 @@ def get_optional_fields(self, source_record: Tag) -> dict | None: fields["contributors"] = self.get_contributors(source_record) or None # dates - fields["dates"] = self.get_dates(source_record_id, source_record) or None + fields["dates"] = self.get_dates(source_record, source_record_id) or None # edition: not set in this transformation @@ -63,7 +63,7 @@ def get_optional_fields(self, source_record: Tag) -> dict | None: # languages: not set in this transformation # links - fields["links"] = self.get_links(source_record_id, source_record) or None + fields["links"] = self.get_links(source_record, source_record_id) or None # literary_form: not set in this transformation @@ -102,7 +102,7 @@ def get_contributors(cls, source_record: Tag) -> list[timdex.Contributor]: ] @classmethod - def get_dates(cls, source_record_id: str, source_record: Tag) -> list[timdex.Date]: + def get_dates(cls, source_record: Tag, source_record_id: str) -> list[timdex.Date]: """ Method to get TIMDEX "dates" field. This method broken out to allow subclasses to override. @@ -110,8 +110,9 @@ def get_dates(cls, source_record_id: str, source_record: Tag) -> list[timdex.Dat Return list of timdex.Date's if valid and present. Args: - source_record_id: Source record ID. source_record: A BeautifulSoup Tag representing a single OAI DC record in XML. + source_record_id: Source record ID. + """ dates = [] for date in source_record.find_all("dc:date", string=True): @@ -136,15 +137,14 @@ def get_identifiers(cls, source_record: Tag) -> list[timdex.Identifier]: ) return identifiers - @classmethod - def get_links(cls, source_record_id: str, source_record: Tag) -> list[timdex.Link]: + def get_links(self, _source_record: Tag, _source_record_id: str) -> list[timdex.Link]: """ Method to get TIMDEX "links" field. This method broken out to allow subclasses to override. Args: - source_record_id: Source record ID. source_record: A BeautifulSoup Tag representing a single OAI DC record in XML. + source_record_id: Source record ID. """ return []