Skip to content

Commit

Permalink
Refactor log checking out
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Jun 4, 2024
1 parent 50fb60e commit b88320c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
9 changes: 5 additions & 4 deletions ds-caselaw-ingester/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class InvalidMessageException(ReportableException):
class DocumentInsertionError(ReportableException):
pass


class ErrorLogWouldOverwritePublishedDocument(ReportableException):
pass

Expand Down Expand Up @@ -499,11 +500,11 @@ def process_message(message):
except DocumentNotFoundError: # the target does not exist
target_published = False

allow_publish = (
is_akoma # should we forbid publication because it's a parser error log?
)
# forbid publication if it's a parser error log
# allow publication if it's looks like an akoma ntosa document
allow_publish = is_akoma

if target_published and not is_akoma:
if target_published and not allow_publish:
"""Do not publish: there is an existing published document, and we do not have a real document"""
raise ErrorLogWouldOverwritePublishedDocument(
f"XML for {uri} is a {xml.tag}; a published document already exists there."
Expand Down
28 changes: 12 additions & 16 deletions ds-caselaw-ingester/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ def create_fake_bulk_file(*args, **kwargs):
shutil.copyfile(BULK_TARBALL_PATH, "/tmp/BULK-0.tar.gz")


def assert_log_sensible(log):
assert "Ingester Start: Consignment reference" in log
assert "tar.gz saved locally as" in log
assert "Ingesting document" in log
assert "Updated judgment xml" in log
assert "Upload Successful" in log
assert "Ingestion complete" in log
assert "Invalid XML file" not in log
assert "No XML file found" not in log


class TestHandler:
@patch("lambda_function.api_client", autospec=True)
@patch("lambda_function.boto3.session.Session")
Expand Down Expand Up @@ -107,15 +118,8 @@ def test_handler_messages_v2(
lambda_function.handler(event=event, context=None)

log = capsys.readouterr().out
assert "Ingester Start: Consignment reference TDR-2022-DNWR" in log
assert "tar.gz saved locally as /tmp/TDR-2022-DNWR.tar.gz" in log
assert "Ingesting document" in log
assert "Updated judgment xml" in log
assert "Upload Successful" in log
assert "Ingestion complete" in log
assert_log_sensible(log)
assert "auto_publish" not in log
assert "Invalid XML file" not in log
assert "No XML file found" not in log
assert "image1.png" in log
notify_update.assert_called()
assert notify_update.call_count == 2
Expand Down Expand Up @@ -161,15 +165,7 @@ def test_handler_messages_s3(
lambda_function.handler(event=event, context=None)

log = capsys.readouterr().out
assert "Ingester Start: Consignment reference BULK-0" in log
assert "tar.gz saved locally as /tmp/BULK-0.tar.gz" in log
assert "Ingesting document" in log
assert "Updated judgment xml" in log
assert "Upload Successful" in log
assert "Ingestion complete" in log
assert "auto_publish" in log
assert "Invalid XML file" not in log
assert "No XML file found" not in log
apiclient.set_published.assert_called_with("ukut/iac/2012/82", True)
assert apiclient.set_published.call_count == 2
notify_new.assert_not_called()
Expand Down

0 comments on commit b88320c

Please sign in to comment.