Skip to content

Commit

Permalink
Merge pull request #395 from nationalarchives/FCL-82-consistent-status
Browse files Browse the repository at this point in the history
Provide publication information when getting metadata for search results
  • Loading branch information
dragon-dxw authored Sep 18, 2023
2 parents 7d0b36e + 08fec9e commit 3a6b6c0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/caselawclient/models/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ class UnparsableDate(Warning):
""" This document has been published and should be considered publicly visible. """

DOCUMENT_STATUS_IN_PROGRESS = "In progress"
""" This document has not been published or put on hold, and should be progressing through the document pipeline. """
""" This document has not been published or put on hold, and has been picked up by an editor and
should be progressing through the document pipeline. """

DOCUMENT_STATUS_NEW = "New"
""" This document isn't published, on hold, or assigned, and can be picked up by an editor in the future. """


DOCUMENT_COLLECTION_URI_JUDGMENT = "judgment"
DOCUMENT_COLLECTION_URI_PRESS_SUMMARY = "press-summary"
Expand Down Expand Up @@ -386,7 +391,10 @@ def status(self) -> str:
if self.is_held:
return DOCUMENT_STATUS_HOLD

return DOCUMENT_STATUS_IN_PROGRESS
if self.assigned_to:
return DOCUMENT_STATUS_IN_PROGRESS

return DOCUMENT_STATUS_NEW

def enrich(self) -> None:
notify_changed(
Expand Down
10 changes: 10 additions & 0 deletions src/caselawclient/responses/search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class EditorStatus(Enum):
NEW = "new"
IN_PROGRESS = "in progress"
HOLD = "hold"
PUBLISHED = "published"


class EditorPriority(Enum):
Expand Down Expand Up @@ -97,6 +98,13 @@ def editor_hold(self) -> str:

return self._get_xpath_match_string("//editor-hold/text()")

@property
def is_published(self) -> bool:
"""
:return:
"""
return self._get_xpath_match_string("//published/text()") == "true"

@property
def editor_priority(self) -> str:
"""
Expand Down Expand Up @@ -130,6 +138,8 @@ def editor_status(
:return: The editor status based on the metadata
"""

if self.is_published:
return EditorStatus.PUBLISHED.value
if self.editor_hold == "true":
return EditorStatus.HOLD.value
if self.assigned_to:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let $properties := (
fn:QName("", 'source-name'),
fn:QName("", 'source-email'),
fn:QName("", 'transfer-consignment-reference'),
fn:QName("", 'transfer-received-at')
fn:QName("", 'transfer-received-at'),
fn:QName("", 'published')
)

return <property-results>{
Expand Down
10 changes: 10 additions & 0 deletions tests/models/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from caselawclient.models.documents import (
DOCUMENT_STATUS_HOLD,
DOCUMENT_STATUS_IN_PROGRESS,
DOCUMENT_STATUS_NEW,
DOCUMENT_STATUS_PUBLISHED,
CannotPublishUnpublishableDocument,
Document,
Expand Down Expand Up @@ -155,19 +156,28 @@ def test_judgment_content_as_xml_tree(self, mock_api_client):
assert etree.tostring(document.content_as_xml_tree) == b"<xml/>"

def test_document_status(self, mock_api_client):
new_document = Document("test/1234", mock_api_client)
new_document.is_held = False
new_document.is_published = False
new_document.assigned_to = ""
assert new_document.status == DOCUMENT_STATUS_NEW

in_progress_document = Document("test/1234", mock_api_client)
in_progress_document.is_held = False
in_progress_document.is_published = False
in_progress_document.assigned_to = "duck"
assert in_progress_document.status == DOCUMENT_STATUS_IN_PROGRESS

on_hold_document = Document("test/1234", mock_api_client)
on_hold_document.is_held = True
on_hold_document.is_published = False
on_hold_document.assigned_to = "duck"
assert on_hold_document.status == DOCUMENT_STATUS_HOLD

published_document = Document("test/1234", mock_api_client)
published_document.is_held = False
published_document.is_published = True
published_document.assigned_to = "duck"
assert published_document.status == DOCUMENT_STATUS_PUBLISHED

def test_document_best_identifier(self, mock_api_client):
Expand Down
22 changes: 16 additions & 6 deletions tests/responses/test_search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def test_init(self):
"<transfer-consignment-reference>test_consignment_reference</transfer-consignment-reference>"
"<editor-hold>false</editor-hold>"
"<editor-priority>30</editor-priority>"
"<published>true</published>"
"<transfer-received-at>2023-01-26T14:17:02Z</transfer-received-at>"
"</property-result>"
"</property-results>"
Expand All @@ -127,6 +128,7 @@ def test_init(self):
assert meta.editor_priority == "30"
assert meta.submission_datetime == datetime.datetime(2023, 1, 26, 14, 17, 2)
assert meta.last_modified == "test_last_modified"
assert meta.is_published is True

def test_empty_properties_init(self):
"""
Expand All @@ -150,17 +152,24 @@ def test_empty_properties_init(self):
assert meta.editor_priority == EditorPriority.MEDIUM.value
assert meta.submission_datetime == datetime.datetime.min
assert meta.last_modified == "test_last_modified"
assert meta.is_published is False

@pytest.mark.parametrize(
"editor_hold, assigned_to, expected_editor_status",
"published_string, editor_hold, assigned_to, expected_editor_status",
[
("false", "", EditorStatus.NEW),
("false", "TestEditor", EditorStatus.IN_PROGRESS),
("true", "", EditorStatus.HOLD),
("true", "TestEditor", EditorStatus.HOLD),
("", "false", "", EditorStatus.NEW),
("", "false", "TestEditor", EditorStatus.IN_PROGRESS),
("", "true", "", EditorStatus.HOLD),
("", "true", "TestEditor", EditorStatus.HOLD),
("true", "false", "", EditorStatus.PUBLISHED),
("true", "false", "TestEditor", EditorStatus.PUBLISHED),
("true", "true", "", EditorStatus.PUBLISHED),
("true", "true", "TestEditor", EditorStatus.PUBLISHED),
],
)
def test_editor_status(self, assigned_to, editor_hold, expected_editor_status):
def test_editor_status(
self, published_string, assigned_to, editor_hold, expected_editor_status
):
"""
GIVEN editor_hold and assigned_to values
WHEN creating a SearchResultMetadata instance
Expand All @@ -171,6 +180,7 @@ def test_editor_status(self, assigned_to, editor_hold, expected_editor_status):
"<property-result>"
f"<assigned-to>{assigned_to}</assigned-to>"
f"<editor-hold>{editor_hold}</editor-hold>"
f"<published>{published_string}</published>"
"</property-result>"
"</property-results>"
)
Expand Down

0 comments on commit 3a6b6c0

Please sign in to comment.