From 9d6588ee780d4da95c75a6fbd8dec51f5be79880 Mon Sep 17 00:00:00 2001 From: David McKee Date: Wed, 6 Nov 2024 11:48:29 +0000 Subject: [PATCH] Add 15 minute default timeout to checkout/lock --- pyproject.toml | 2 +- src/openapi_server/apis/writing_api.py | 8 +++----- tests/test_writing_api.py | 8 ++++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 39ae0e7..afe228c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT" diff --git a/src/openapi_server/apis/writing_api.py b/src/openapi_server/apis/writing_api.py index 290b228..b4085a3 100644 --- a/src/openapi_server/apis/writing_api.py +++ b/src/openapi_server/apis/writing_api.py @@ -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") diff --git a/tests/test_writing_api.py b/tests/test_writing_api.py index fb170d6..ce541e9 100644 --- a/tests/test_writing_api.py +++ b/tests/test_writing_api.py @@ -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 "" in response.text @@ -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 "" in response.text @@ -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