Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use save_identifiers on document not identifiers.save() #801

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/caselawclient/models/documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ def can_reparse(self) -> bool:
"""
return self.docx_exists()

def save_identifiers(self) -> None:
"""Save the current state of this Document's identifiers to MarkLogic."""
self.identifiers.validate()
self.api_client.set_property_as_node(self.uri, "identifiers", self.identifiers.as_etree)

def __getattr__(self, name: str) -> Any:
warnings.warn(f"{name} no longer exists on Document, using Document.body instead", DeprecationWarning)
try:
Expand Down
5 changes: 0 additions & 5 deletions src/caselawclient/models/identifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,3 @@ def as_etree(self) -> etree._Element:
identifiers_root.append(identifier.as_xml_tree)

return identifiers_root

def save(self, document) -> None: # type: ignore[no-untyped-def, unused-ignore]
"""Save the current state of this Document's identifiers to MarkLogic."""
self.validate()
document.api_client.set_property_as_node(document.uri, "identifiers", self.as_etree)
20 changes: 19 additions & 1 deletion tests/models/documents/test_document_verbs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import json
import os
from unittest.mock import PropertyMock, patch
from unittest.mock import Mock, PropertyMock, patch

import pytest
import time_machine
Expand All @@ -13,10 +13,28 @@
DocumentNotSafeForDeletion,
DocumentURIString,
)
from caselawclient.models.identifiers import Identifiers
from caselawclient.models.judgments import Judgment
from caselawclient.models.neutral_citation_mixin import NeutralCitationString


class TestDocumentSaveIdentifiers:
def test_document_save_identifiers(self, mock_api_client):
"""
given a particular Document with a known value of Identifiers (probably mock this out tbh)
when I call document.save_identifiers() it
calls identifiers.validate and
calls set_property_as_node with expected values (edited)
"""
document = Document(DocumentURIString("test/1234"), mock_api_client)
document.identifiers = Mock(autospec=Identifiers)
document.identifiers.as_etree = "fake_node"

document.save_identifiers()
document.identifiers.validate.assert_called_once()
mock_api_client.set_property_as_node.assert_called_with("test/1234", "identifiers", "fake_node")


class TestDocumentPublish:
def test_publish_fails_if_not_publishable(self, mock_api_client):
with pytest.raises(CannotPublishUnpublishableDocument):
Expand Down
Loading