Skip to content

Commit

Permalink
Merge pull request #538 from nationalarchives/feature/record-reparse-…
Browse files Browse the repository at this point in the history
…attempt-datetime

Reparsing a document will now record the attempt timestamp
  • Loading branch information
jacksonj04 authored Jan 29, 2024
2 parents a093081 + 2fc9492 commit 9831ef5
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 4 deletions.
72 changes: 70 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ coverage = "^7.2.3"
pytest = "^7.3.2"
responses = "^0.24.0"
python-dotenv = "^1.0.0"
time-machine = "^2.13.0"

[tool.poetry.group.docs]
optional = true
Expand Down
4 changes: 4 additions & 0 deletions src/caselawclient/models/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ def move(self, new_citation: str) -> None:
def reparse(self) -> None:
"Send an SNS notification that triggers reparsing, also sending all editor-modifiable metadata and URI"

self.api_client.set_property(
self.uri, "last_sent_to_parser", datetime.datetime.now().isoformat()
)

parser_type_noun = {"judgment": "judgment", "press summary": "pressSummary"}[
self.document_noun
]
Expand Down
25 changes: 23 additions & 2 deletions tests/models/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import patch

import pytest
import time_machine

from caselawclient.errors import (
DocumentNotFoundError,
Expand Down Expand Up @@ -413,10 +414,16 @@ def test_unpublish(


class TestDocumentEnrich:
@time_machine.travel(datetime.datetime(1955, 11, 5, 6))
@patch("caselawclient.models.documents.announce_document_event")
def test_enrich(self, mock_announce_document_event, mock_api_client):
document = Document("test/1234", mock_api_client)
document.enrich()

mock_api_client.set_property.assert_called_once_with(
"test/1234", "last_sent_to_enrichment", "1955-11-05T06:00:00"
)

mock_announce_document_event.assert_called_once_with(
uri="test/1234", status="enrich", enrich=True
)
Expand Down Expand Up @@ -672,10 +679,11 @@ def test_no_dates(self, mock_api_client):
assert document.get_latest_manifestation_datetime() is None
assert document.get_manifestation_datetimes("any") == []

@time_machine.travel(datetime.datetime(1955, 11, 5, 6))
@patch("caselawclient.models.utilities.aws.create_sns_client")
@patch.dict(os.environ, {"PRIVATE_ASSET_BUCKET": "MY_BUCKET"})
@patch.dict(os.environ, {"REPARSE_SNS_TOPIC": "MY_TOPIC"})
def test_reparse_empty(self, sns):
def test_reparse_empty(self, sns, mock_api_client):
document = JudgmentFactory().build(
is_published=False,
name="",
Expand All @@ -685,7 +693,13 @@ def test_reparse_empty(self, sns):
document_noun="judgment",
)

document.api_client = mock_api_client
Judgment.reparse(document)

mock_api_client.set_property.assert_called_once_with(
"test/2023/123", "last_sent_to_parser", "1955-11-05T06:00:00"
)

# first call, second argument (the kwargs), so [0][1]
returned_message = json.loads(
sns.return_value.publish.call_args_list[0][1]["Message"]
Expand Down Expand Up @@ -719,13 +733,20 @@ def test_reparse_empty(self, sns):
},
}

@time_machine.travel(datetime.datetime(1955, 11, 5, 6))
@patch("caselawclient.models.utilities.aws.create_sns_client")
@patch.dict(os.environ, {"PRIVATE_ASSET_BUCKET": "MY_BUCKET"})
@patch.dict(os.environ, {"REPARSE_SNS_TOPIC": "MY_TOPIC"})
def test_reparse_full(self, sns):
def test_reparse_full(self, sns, mock_api_client):
document = JudgmentFactory().build(is_published=True)
document.api_client = mock_api_client

Judgment.reparse(document)

mock_api_client.set_property.assert_called_once_with(
"test/2023/123", "last_sent_to_parser", "1955-11-05T06:00:00"
)

# first call, second argument (the kwargs), so [0][1]
returned_message = json.loads(
sns.return_value.publish.call_args_list[0][1]["Message"]
Expand Down

0 comments on commit 9831ef5

Please sign in to comment.