Skip to content

Commit

Permalink
Merge pull request #716 from nationalarchives/lock-judgment-with-fixe…
Browse files Browse the repository at this point in the history
…d-timeout

Lock judgment with fixed timeout
  • Loading branch information
dragon-dxw authored Oct 23, 2024
2 parents ebf5643 + ce5b7ee commit 0029579
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog 1.0.0].
## v27.0.2 (unreleased)

- Allow things on doc.body to be called from doc with a warning
- client.checkout_judgment now accepts a `timeout_seconds` parameter

## v27.0.1 (2024-10-17)

Expand Down
4 changes: 3 additions & 1 deletion src/caselawclient/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,14 @@ def checkout_judgment(
judgment_uri: DocumentURIString,
annotation: str = "",
expires_at_midnight: bool = False,
timeout_seconds: int = -1,
) -> requests.Response:
"""If timeout_seconds is -1, the lock never times out"""
uri = self._format_uri_for_marklogic(judgment_uri)
vars: query_dicts.CheckoutJudgmentDict = {
"uri": uri,
"annotation": annotation,
"timeout": -1,
"timeout": timeout_seconds,
}

if expires_at_midnight:
Expand Down
17 changes: 16 additions & 1 deletion tests/client/test_checkout_checkin_judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_checkout_judgment(self):
accept_header="application/xml",
)

def test_checkout_judgment_with_timeout(self):
def test_checkout_judgment_with_midnight_timeout(self):
with patch.object(self.client, "eval") as mock_eval, patch.object(
self.client,
"calculate_seconds_until_midnight",
Expand All @@ -47,6 +47,21 @@ def test_checkout_judgment_with_timeout(self):
assert mock_eval.call_args.args[0] == (os.path.join(ROOT_DIR, "xquery", "checkout_judgment.xqy"))
assert mock_eval.call_args.kwargs["vars"] == json.dumps(expected_vars)

def test_checkout_judgment_with_timeout_seconds(self):
with patch.object(self.client, "eval") as mock_eval:
uri = "/ewca/civ/2004/632"
annotation = "locked by A KITTEN"
timeout_seconds = 1234
expected_vars = {
"uri": "/ewca/civ/2004/632.xml",
"annotation": "locked by A KITTEN",
"timeout": 1234,
}
self.client.checkout_judgment(uri, annotation, timeout_seconds=timeout_seconds)

assert mock_eval.call_args.args[0] == (os.path.join(ROOT_DIR, "xquery", "checkout_judgment.xqy"))
assert mock_eval.call_args.kwargs["vars"] == json.dumps(expected_vars)

def test_checkin_judgment(self):
with patch.object(self.client, "eval") as mock_eval:
uri = "/ewca/civ/2004/632"
Expand Down

0 comments on commit 0029579

Please sign in to comment.