Skip to content

Commit

Permalink
Fix auto-publishing
Browse files Browse the repository at this point in the history
* actually set it to be published on Marklogic
* don't send emails
  • Loading branch information
dragon-dxw committed Nov 20, 2023
1 parent 66e2ecb commit dc1e008
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
18 changes: 14 additions & 4 deletions ds-caselaw-ingester/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
29 changes: 27 additions & 2 deletions ds-caselaw-ingester/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit dc1e008

Please sign in to comment.