Skip to content

Commit

Permalink
Make various methods which announce events consistent
Browse files Browse the repository at this point in the history
Each event now only serves one purpose; instead of a single `publish`
notification which also triggers enrichment we now send a second
`enrich` message. This may allow us to perform filtering in future if
necessary.
  • Loading branch information
jacksonj04 committed Nov 28, 2023
1 parent ed54b68 commit 96102f8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog 1.0.0].

## [Unreleased]

- **Feature:** `Document.enrich()` method will send a message to the announce SNS, requesting that a document be enriched.

## [Release 17.2.0]
- `document.content_as_html` now takes an optional `query=` string parameter, which, when supplied, highlights instances of the query within the document with `<mark>` tags, each of which has a numbered id indicating its sequence in the document.
- `document.number_of_mentions` method which takes a `query=` string parameter, and returns the number of highlighted mentions in the html.
Expand Down
12 changes: 7 additions & 5 deletions src/caselawclient/models/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,12 @@ def status(self) -> str:
return DOCUMENT_STATUS_NEW

def enrich(self) -> None:
"""
Announces to the ANNOUNCE SNS that the document is waiting to be enriched.
"""
announce_document_event(
uri=self.uri,
status="published",
status="enrich",
enrich=True,
)

Expand All @@ -468,18 +471,17 @@ def publish(self) -> None:
self.api_client.set_published(self.uri, True)
announce_document_event(
uri=self.uri,
status="published",
enrich=True,
status="publish",
)
self.enrich()

def unpublish(self) -> None:
self.api_client.break_checkout(self.uri)
unpublish_documents(uri_for_s3(self.uri))
self.api_client.set_published(self.uri, False)
announce_document_event(
uri=self.uri,
status="not published",
enrich=False,
status="unpublish",
)

def hold(self) -> None:
Expand Down
26 changes: 22 additions & 4 deletions tests/models/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def test_judgment_validation_failure_messages_if_failing(self, mock_api_client):
)


class TestDocumentPublication:
class TestDocumentPublish:
def test_publish_fails_if_not_publishable(self, mock_api_client):
with pytest.raises(CannotPublishUnpublishableDocument):
document = Document("test/1234", mock_api_client)
Expand All @@ -364,18 +364,26 @@ def test_publish_fails_if_not_publishable(self, mock_api_client):

@patch("caselawclient.models.documents.announce_document_event")
@patch("caselawclient.models.documents.publish_documents")
@patch("caselawclient.models.documents.Document.enrich")
def test_publish(
self, mock_publish_documents, mock_announce_document_event, mock_api_client
self,
mock_enrich,
mock_publish_documents,
mock_announce_document_event,
mock_api_client,
):
document = Document("test/1234", mock_api_client)
document.is_publishable = True
document.publish()
mock_publish_documents.assert_called_once_with("test/1234")
mock_api_client.set_published.assert_called_once_with("test/1234", True)
mock_announce_document_event.assert_called_once_with(
uri="test/1234", status="published", enrich=True
uri="test/1234", status="publish"
)
mock_enrich.assert_called_once()


class TestDocumentUnpublish:
@patch("caselawclient.models.documents.announce_document_event")
@patch("caselawclient.models.documents.unpublish_documents")
def test_unpublish(
Expand All @@ -387,7 +395,17 @@ def test_unpublish(
mock_api_client.set_published.assert_called_once_with("test/1234", False)
mock_api_client.break_checkout.assert_called_once_with("test/1234")
mock_announce_document_event.assert_called_once_with(
uri="test/1234", status="not published", enrich=False
uri="test/1234", status="unpublish"
)


class TestDocumentEnrich:
@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_announce_document_event.assert_called_once_with(
uri="test/1234", status="enrich", enrich=True
)


Expand Down

0 comments on commit 96102f8

Please sign in to comment.