Skip to content

Commit

Permalink
Merge pull request #813 from nationalarchives/renovate/patch-boto-pac…
Browse files Browse the repository at this point in the history
…kages

fix(deps): update dependency mypy-boto3-s3 to v1.35.81
  • Loading branch information
renovate[bot] authored and jacksonj04 committed Dec 20, 2024
2 parents 6796240 + 1655dee commit bcc4075
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/caselawclient/models/identifiers/unpacker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional
from warnings import warn

from lxml import etree

Expand All @@ -19,12 +20,13 @@ def unpack_all_identifiers_from_etree(identifiers_etree: Optional[etree._Element
return identifiers
for identifier_etree in identifiers_etree.findall("identifier"):
identifier = unpack_an_identifier_from_etree(identifier_etree)
identifiers.add(identifier)
if identifier:
identifiers.add(identifier)
return identifiers


def unpack_an_identifier_from_etree(identifier_xml: etree._Element) -> Identifier:
"""Given an etree representation of a single identifier, unpack it into an appropriate instance of an Identifier."""
def unpack_an_identifier_from_etree(identifier_xml: etree._Element) -> Optional[Identifier]:
"""Given an etree representation of a single identifier, unpack it into an appropriate instance of an Identifier if the type is known (otherwise return `None`)."""

namespace_element = identifier_xml.find("namespace")

Expand All @@ -33,6 +35,11 @@ def unpack_an_identifier_from_etree(identifier_xml: etree._Element) -> Identifie
"Identifer XML representation is not valid: namespace not present or empty"
)

# If the identifier namespace isn't known, fail out
if namespace_element.text not in IDENTIFIER_NAMESPACE_MAP:
warn(f"Identifier type {namespace_element.text} is not known.")
return None

kwargs: dict[str, str] = {}

for attribute in IDENTIFIER_UNPACKABLE_ATTRIBUTES:
Expand Down
18 changes: 17 additions & 1 deletion tests/models/identifiers/test_identifer_unpacking.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import unittest
from unittest.mock import patch

from lxml import etree
Expand All @@ -7,7 +8,7 @@
from caselawclient.models.identifiers.unpacker import unpack_all_identifiers_from_etree, unpack_an_identifier_from_etree


class TestIdentifierUnpacking:
class TestIdentifierUnpacking(unittest.TestCase):
@patch("caselawclient.models.identifiers.unpacker.IDENTIFIER_NAMESPACE_MAP", {"test": TestIdentifier})
def test_unpack_identifier(self):
xml_tree = etree.fromstring("""
Expand All @@ -24,6 +25,21 @@ def test_unpack_identifier(self):
assert unpacked_identifier.uuid == "2d80bf1d-e3ea-452f-965c-041f4399f2dd"
assert unpacked_identifier.value == "TEST-123"

@patch("caselawclient.models.identifiers.unpacker.IDENTIFIER_NAMESPACE_MAP", {"test": TestIdentifier})
def test_unpack_unknown_identifier(self):
xml_tree = etree.fromstring("""
<identifier>
<namespace>unknown</namespace>
<uuid>2d80bf1d-e3ea-452f-965c-041f4399f2dd</uuid>
<value>UK-123</value>
</identifier>
""")

with self.assertWarnsRegex(Warning, "Identifier type unknown is not known."):
unpacked_identifier = unpack_an_identifier_from_etree(xml_tree)

assert unpacked_identifier is None


class TestIdentifierPackUnpackRoundTrip:
@patch("caselawclient.models.identifiers.unpacker.IDENTIFIER_NAMESPACE_MAP", {"test": TestIdentifier})
Expand Down

0 comments on commit bcc4075

Please sign in to comment.