diff --git a/ds-caselaw-ingester/lambda_function.py b/ds-caselaw-ingester/lambda_function.py index 9ea88d0..950b44c 100644 --- a/ds-caselaw-ingester/lambda_function.py +++ b/ds-caselaw-ingester/lambda_function.py @@ -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}!" @@ -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) diff --git a/ds-caselaw-ingester/tests.py b/ds-caselaw-ingester/tests.py index 6c74b92..6c54d9a 100644 --- a/ds-caselaw-ingester/tests.py +++ b/ds-caselaw-ingester/tests.py @@ -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}}]} @@ -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") @@ -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}}]} @@ -200,6 +206,7 @@ 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, @@ -207,6 +214,8 @@ def test_handler_messages_s3( 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: