Skip to content

Commit

Permalink
feat(FCL-532): assign FCLIDs on document publication
Browse files Browse the repository at this point in the history
When documents are published they will now be assigned a new FCLID if one isn't already present.
  • Loading branch information
jacksonj04 committed Dec 16, 2024
1 parent 73c2914 commit 6fcaab0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/caselawclient/models/documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
NotSupportedOnVersion,
OnlySupportedOnVersion,
)
from caselawclient.models.identifiers.fclid import FindCaseLawIdentifier, FindCaseLawIdentifierSchema
from caselawclient.models.identifiers.unpacker import unpack_all_identifiers_from_etree
from caselawclient.models.utilities import VersionsDict, extract_version, render_versions
from caselawclient.models.utilities.aws import (
Expand Down Expand Up @@ -432,6 +433,12 @@ def publish(self) -> None:
if not self.is_publishable:
raise CannotPublishUnpublishableDocument

## If it doesn't already have one, get a new FCLID for this document and assign
if len(self.identifiers.of_type(FindCaseLawIdentifier)) < 1:
document_fclid = FindCaseLawIdentifierSchema.mint(self.api_client)
self.identifiers.add(document_fclid)
self.save_identifiers()

publish_documents(uri_for_s3(self.uri))
self.api_client.set_published(self.uri, True)
announce_document_event(
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@ def mock_api_client():
mock_client = Mock(spec=MarklogicApiClient)
mock_client.get_judgment_xml_bytestring.return_value = b"<xml>content</xml>"
mock_client.get_property_as_node.return_value = None
mock_client.get_next_document_sequence_number.return_value = 1

return mock_client
38 changes: 38 additions & 0 deletions tests/models/documents/test_document_verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DocumentURIString,
)
from caselawclient.models.identifiers import Identifiers
from caselawclient.models.identifiers.fclid import FindCaseLawIdentifier
from caselawclient.models.judgments import Judgment
from caselawclient.models.neutral_citation_mixin import NeutralCitationString

Expand Down Expand Up @@ -64,6 +65,43 @@ def test_publish(
)
mock_enrich.assert_called_once()

@patch("caselawclient.models.documents.announce_document_event")
@patch("caselawclient.models.documents.publish_documents")
@patch("caselawclient.models.documents.Document.enrich")
def test_publish_assigns_new_fclid(
self,
mock_enrich,
mock_publish_documents,
mock_announce_document_event,
mock_api_client,
):
document = Document(DocumentURIString("test/1234"), mock_api_client)
document.is_publishable = True
mock_api_client.get_next_document_sequence_number.return_value = 123
document.publish()

assert len(document.identifiers.of_type(FindCaseLawIdentifier)) == 1
assert [identifier.value for identifier in document.identifiers.of_type(FindCaseLawIdentifier)][0] == "z27xcnhr"

@patch("caselawclient.models.documents.announce_document_event")
@patch("caselawclient.models.documents.publish_documents")
@patch("caselawclient.models.documents.Document.enrich")
def test_publish_only_assigns_new_fclid_if_none_present(
self,
mock_enrich,
mock_publish_documents,
mock_announce_document_event,
mock_api_client,
):
document = Document(DocumentURIString("test/1234"), mock_api_client)
document.is_publishable = True
document.identifiers.add(FindCaseLawIdentifier(value="abcd1234"))
mock_api_client.get_next_document_sequence_number.return_value = 123
document.publish()

assert len(document.identifiers.of_type(FindCaseLawIdentifier)) == 1
assert [identifier.value for identifier in document.identifiers.of_type(FindCaseLawIdentifier)][0] == "abcd1234"


class TestDocumentUnpublish:
@patch("caselawclient.models.documents.announce_document_event")
Expand Down

0 comments on commit 6fcaab0

Please sign in to comment.