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 4578afd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
6 changes: 6 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ paths:
schema:
type: string
style: simple
- name: timeout
schema:
type: int
required: false
in: query
description: After this many seconds, the judgment will be unlocked. Defaults to 900 (15 minutes).
responses:
"201":
description: "A single judgment document, in Akoma Ntoso XML"
Expand Down
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 <[email protected]>"]
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",
timeout: str = "900", # noqa: ASYNC109
):
"""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(timeout)
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
10 changes: 5 additions & 5 deletions tests/test_writing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,27 @@ 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


@patch("openapi_server.apis.writing_api.client_for_basic_auth")
def test_put_lock_success_temporary(mocked_client):
"""If expires is passed, the lock will expire"""
"""If timeout is passed, the lock will expire"""
mocked_client.return_value.checkout_judgment.return_value = None
mocked_client.return_value.get_judgment_xml.return_value = b"<judgment></judgment>"
response = TestClient(app).request(
"PUT",
"/lock/judgment/uri",
auth=("user", "pass"),
params={"expires": "1"},
params={"timeout": "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 4578afd

Please sign in to comment.