Skip to content

Commit

Permalink
Further updates based on discussion in PR #199
Browse files Browse the repository at this point in the history
* Refactor get_source_link method
* Update dependencies to address new safety vulnerability
* Updates to address linting errors
* Add XMLTransformer.record_is_deleted unit test
  • Loading branch information
ehanson8 committed Jul 19, 2024
1 parent 5b086ee commit 3f67bcb
Show file tree
Hide file tree
Showing 7 changed files with 504 additions and 535 deletions.
1,007 changes: 484 additions & 523 deletions Pipfile.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions tests/sources/test_xmltransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def test_xmltransformer_record_is_deleted_returns_true_if_deleted(caplog):
assert XMLTransformer.record_is_deleted(next(source_records)) is True


def test_xmltransformer_record_is_deleted_returns_false_if_not_deleted(caplog):
source_records = XMLTransformer.parse_source_file(
"tests/fixtures/record_title_field_blank.xml"
)
assert XMLTransformer.record_is_deleted(next(source_records)) is False


def test_xmltransformer_get_required_fields_returns_expected_values(oai_pmh_records):
transformer = XMLTransformer("cool-repo", oai_pmh_records)
assert transformer.get_required_fields(next(oai_pmh_records)) == {
Expand Down
4 changes: 3 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ def test_load_external_config_json():


def test_load_external_config_xml():
assert type(load_external_config("config/loc-countries.xml", "xml")) == BeautifulSoup
assert isinstance(
load_external_config("config/loc-countries.xml", "xml"), BeautifulSoup
)
2 changes: 1 addition & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_parse_date_from_string_success():
"1930-12-31T12:34:56.000001",
"1930-12-31T12:34:56.000001Z",
]:
assert type(parse_date_from_string(date)) == datetime
assert isinstance(parse_date_from_string(date), datetime)


def test_parse_date_from_string_invalid_date_returns_none():
Expand Down
9 changes: 5 additions & 4 deletions transmogrifier/sources/json/aardvark.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ def get_source_link(
- not used by default implementation, but could be useful for subclass
overrides
"""
if links := cls.get_links(source_record):
url_links = [link for link in links if link.kind == "Website"]
if len(url_links) == 1:
return url_links[0].url
if (links := cls.get_links(source_record)) and (
url_links := [link for link in links if link.kind == "Website"]
):
return url_links[0].url

message = "Could not locate a kind=Website link to pull the source link from."
raise ValueError(message)

Expand Down
6 changes: 3 additions & 3 deletions transmogrifier/sources/xml/whoas.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ def valid_content_types(cls, content_type_list: list[str]) -> bool:
Args:
content_type_list: A list of content_type values.
"""
if all(item.lower() in INVALID_CONTENT_TYPES for item in content_type_list):
return False
return True
return not all(
item.lower() in INVALID_CONTENT_TYPES for item in content_type_list
)
4 changes: 1 addition & 3 deletions transmogrifier/sources/xmltransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ def record_is_deleted(cls, source_record: Tag) -> bool:
Args:
source_record: A BeautifulSoup Tag representing a single XML record
"""
if source_record.find("header", status="deleted"):
return True
return False
return source_record.find("header", status="deleted") is not None

def get_optional_fields(self, _source_record: Tag) -> dict | None:
"""
Expand Down

0 comments on commit 3f67bcb

Please sign in to comment.