Skip to content

Commit

Permalink
Add 15 minute default timeout to checkout/lock
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Nov 6, 2024
1 parent a6405d6 commit 9d6588e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires-python = ">=3.12, <4"

[tool.poetry]
name = "ds-caselaw-privileged-api"
version = "0.3.0"
version = "0.4.0"
description = ""
authors = ["David McKee <david.mckee@dxw.com>"]
license = "MIT"
Expand Down
8 changes: 3 additions & 5 deletions src/openapi_server/apis/writing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,18 @@ async def judgment_uri_lock_put(
response: Response,
judgmentUri: DocumentURIString,
token_basic: TokenModel = SECURITY_TOKEN_MODEL,
expires="0",
expires: str = "900",
):
"""Locks edit access for a document for the current client. Returns the latest
version of the locked document, along with the new lock state."""
client = client_for_basic_auth(token_basic)
annotation = f"Judgment locked for editing by {token_basic.username}"
expires = bool(
int(expires),
) # If expires is True then the lock will expire at midnight, otherwise the lock is permanent
timeout_seconds = int(expires)
with error_handling():
_ml_response = client.checkout_judgment(
judgmentUri,
annotation,
expires,
timeout_seconds=timeout_seconds,
)
judgment = client.get_judgment_xml(judgmentUri, show_unpublished=True)
return Response(status_code=201, content=judgment, media_type="application/xml")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_writing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_put_lock_success(mocked_client):
mocked_client.return_value.checkout_judgment.assert_called_with(
"judgment/uri",
"Judgment locked for editing by user",
False,
timeout_seconds=900,
)
assert response.status_code == 201
assert "<judgment>" in response.text
Expand All @@ -97,12 +97,12 @@ def test_put_lock_success_temporary(mocked_client):
"PUT",
"/lock/judgment/uri",
auth=("user", "pass"),
params={"expires": "1"},
params={"expires": "123"},
)
mocked_client.return_value.checkout_judgment.assert_called_with(
"judgment/uri",
"Judgment locked for editing by user",
True,
timeout_seconds=123,
)
assert response.status_code == 201
assert "<judgment>" in response.text
Expand All @@ -123,7 +123,7 @@ def test_put_lock_failure(mocked_client):
mocked_client.return_value.checkout_judgment.assert_called_with(
"judgment/uri",
"Judgment locked for editing by user",
False,
timeout_seconds=900,
)
assert response.status_code == 409
assert "resource is locked by another user" in response.text
Expand Down

0 comments on commit 9d6588e

Please # to comment.