diff --git a/ds-caselaw-ingester/lambda_function.py b/ds-caselaw-ingester/lambda_function.py index 47faedb..4fea907 100644 --- a/ds-caselaw-ingester/lambda_function.py +++ b/ds-caselaw-ingester/lambda_function.py @@ -525,14 +525,22 @@ def handler(event, context): updated = update_document_xml(uri, xml, metadata) inserted = False if updated else insert_document_xml(uri, xml, metadata) + force_publish = ( + metadata.get("parameters", {}) + .get("INGESTER_OPTIONS", {}) + .get("auto_publish", False) + ) + if updated: # Notify editors that a document has been updated - send_updated_judgment_notification(uri, metadata) - unpublish_updated_judgment(uri) + if not force_publish: + send_updated_judgment_notification(uri, metadata) + unpublish_updated_judgment(uri) print(f"Updated judgment xml for {uri}") elif inserted: # Notify editors that a new document is ready - send_new_judgment_notification(uri, metadata) + if not force_publish: + send_new_judgment_notification(uri, metadata) print(f"Inserted judgment xml for {uri}") else: raise DocumentInsertionError( @@ -584,7 +592,9 @@ def handler(event, context): .get("auto_publish", False) ) if force_publish is True: - print(f"auto_publishing {consignment_reference}") + print(f"auto_publishing {consignment_reference} at {uri}") + api_client.set_published(uri) + if api_client.get_published(uri) or force_publish: update_published_documents(uri, s3_client) diff --git a/ds-caselaw-ingester/tests.py b/ds-caselaw-ingester/tests.py index 345358f..62c5b65 100644 --- a/ds-caselaw-ingester/tests.py +++ b/ds-caselaw-ingester/tests.py @@ -105,8 +105,18 @@ def test_handler_messages_v1( @patch("lambda_function.tarfile") @patch("lambda_function.boto3.session.Session") @patch("lambda_function.urllib3.PoolManager") + @patch("lambda_function.send_updated_judgment_notification") + @patch("lambda_function.send_new_judgment_notification") def test_handler_messages_v2( - self, urllib_pool, boto_session, tarfile, metadata, apiclient, capsys + self, + notify_new, + notify_update, + urllib_pool, + boto_session, + tarfile, + metadata, + apiclient, + capsys, ): """Mostly intended as a very sketchy test of the primary function""" urllib_pool.return_value.request.return_value.status = 200 @@ -151,14 +161,26 @@ def test_handler_messages_v2( assert "Upload Successful" in log assert "Ingestion complete" in log assert "auto_publish" not in log + notify_update.assert_called() + notify_new.assert_not_called() @patch("lambda_function.api_client", autospec=True) @patch("lambda_function.extract_metadata", autospec=True) @patch("lambda_function.tarfile") @patch("lambda_function.boto3.session.Session") @patch("lambda_function.urllib3.PoolManager") + @patch("lambda_function.send_new_judgment_notification") + @patch("lambda_function.send_updated_judgment_notification") def test_handler_messages_s3( - self, urllib_pool, boto_session, tarfile, metadata, apiclient, capsys + self, + notify_new, + notify_updated, + urllib_pool, + boto_session, + tarfile, + metadata, + apiclient, + capsys, ): """Test that, with appropriate stubs, an S3 message passes through the parsing process""" urllib_pool.return_value.request.return_value.status = 200 @@ -204,6 +226,9 @@ def test_handler_messages_s3( assert "Upload Successful" in log assert "Ingestion complete" in log assert "auto_publish" in log + apiclient.set_published.assert_called_with("failures/TDR-2020-FAR") + notify_new.assert_not_called() + notify_updated.assert_not_called() class TestLambda: