Skip to content

Commit

Permalink
Return an error message when attempting to copy a judgment to an exis…
Browse files Browse the repository at this point in the history
…ting URI

If a newutral citation generates a URI which already exists in Marklogic, return
an error message and do not let the judgment be copied to that URI.
  • Loading branch information
Laura Porter committed Jun 28, 2022
1 parent 84800be commit 1359db7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions judgments/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def test_get_judgment_root_malformed_xml(self):
def test_update_judgment_uri_success(self, fake_client):
ds_caselaw_utils.neutral_url = MagicMock(return_value="new/uri")
attrs = {
"get_judgment_xml.return_value": "",
"copy_judgment.return_value": True,
"delete_judgment.return_value": True,
}
Expand Down Expand Up @@ -210,3 +211,14 @@ def test_update_judgment_uri_unparseable_citation(self):

with self.assertRaises(judgments.utils.NeutralCitationToUriError):
update_judgment_uri("old/uri", "Wrong neutral citation")

@patch("judgments.utils.api_client")
def test_update_judgment_uri_duplicate_uri(self, fake_client):
ds_caselaw_utils.neutral_url = MagicMock(return_value="new/uri")
attrs = {
"get_judgment_xml.return_value": "<akomaNtoso><judgment></judgment></akomaNtoso>",
}
fake_client.configure_mock(**attrs)

with self.assertRaises(judgments.utils.MoveJudgmentError):
update_judgment_uri("old/uri", "[2002] EAT 1")
7 changes: 7 additions & 0 deletions judgments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def update_judgment_uri(old_uri, new_citation):
f"Unable to form new URI for {old_uri} from neutral citation: {new_citation}"
)

existing_judgment = api_client.get_judgment_xml(new_uri, show_unpublished=True)
if existing_judgment != "":
raise MoveJudgmentError(
f"The URI {new_uri} generated from {new_citation} already exists, you cannot move this judgment to a"
f" pre-existing Neutral Citation Number."
)

try:
api_client.copy_judgment(old_uri, new_uri)
set_metadata(old_uri, new_uri)
Expand Down

0 comments on commit 1359db7

Please sign in to comment.