Skip to content

Commit

Permalink
A test
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Dec 4, 2024
1 parent 8c5199f commit a3ba163
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ds-caselaw-ingester/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ def insert_document_xml(self) -> bool:
return True

def set_document_identifiers(self) -> None:
logging.critical("start set_document_identifiers")
doc = api_client.get_document_by_uri(DocumentURIString(self.uri))
if doc.identifiers:
msg = f"Ingesting, but identifiers already present for {self.uri}!"
Expand All @@ -453,12 +452,14 @@ def set_document_identifiers(self) -> None:
try:
ncn = doc.neutral_citation
except AttributeError:
return
ncn = None

if ncn:
doc.identifiers.add(NeutralCitationNumber(ncn))
doc.identifiers.save(doc)
logging.info(f"Ingested document had NCN {ncn}")
logger.info(f"Ingested document had NCN {ncn}")
else:
logger.info(f"Ingested document had NCN (NOT FOUND)")

def send_updated_judgment_notification(self) -> None:
personalisation = personalise_email(self.uri, self.metadata)
Expand Down
9 changes: 9 additions & 0 deletions ds-caselaw-ingester/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def test_handler_messages_v2(
capsys,
):
boto_session.return_value.client.return_value.download_file = create_fake_tdr_file
doc = apiclient.get_document_by_uri.return_value
doc.neutral_citation = None

message = v2_message_raw
event = {"Records": [{"Sns": {"Message": message}}, {"Sns": {"Message": message}}]}
Expand All @@ -161,6 +163,8 @@ def test_handler_messages_v2(
payload=ANY,
)
assert annotation.call_count == 2
doc.identifiers.add.assert_not_called()
doc.identifiers.save.assert_not_called()

@patch("lambda_function.api_client", autospec=True)
@patch("lambda_function.boto3.session.Session")
Expand All @@ -180,6 +184,8 @@ def test_handler_messages_s3(
):
"""Test that, with appropriate stubs, an S3 message passes through the parsing process"""
boto_session.return_value.client.return_value.download_file = create_fake_bulk_file
doc = apiclient.get_document_by_uri.return_value
doc.neutral_citation = "[2012] UKUT 82 (IAC)"

message = s3_message_raw
event = {"Records": [{"Sns": {"Message": message}}, {"Sns": {"Message": message}}]}
Expand All @@ -200,13 +206,16 @@ def test_handler_messages_s3(
notify_new.assert_not_called()
notify_updated.assert_not_called()
modify_filename.assert_not_called()

annotation.assert_called_with(
ANY,
automated=True,
message="Updated document uploaded by Find Case Law",
payload=ANY,
)
assert annotation.call_count == 2
assert doc.identifiers.add.call_args_list[0].args[0].value == "[2012] UKUT 82 (IAC)"
doc.identifiers.save.assert_called()


class TestLambda:
Expand Down

0 comments on commit a3ba163

Please sign in to comment.