Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-unlock if save_locked_judgment_xml fails and unlock was requested #303

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/openapi_server/apis/writing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,18 @@ async def judgment_uri_patch( # noqa: PLR0913
message=annotation if annotation else None,
)

with error_handling():
client.save_locked_judgment_xml(
judgment_uri=judgmentUri,
judgment_xml=bytes_body,
annotation=rich_annotation,
)
try:
with error_handling():
client.save_locked_judgment_xml(
judgment_uri=judgmentUri,
judgment_xml=bytes_body,
annotation=rich_annotation,
)
except Exception:
if unlock:
with error_handling():
_ml_response = client.checkin_judgment(judgment_uri=judgmentUri)
raise

if not unlock:
response.status_code = 200
Expand Down
22 changes: 22 additions & 0 deletions tests/test_writing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,25 @@ def test_validation_error_message_in_api_response(mocked_client):

assert response.status_code == 422
assert response.json()["detail"] == "a message"


@patch("openapi_server.apis.writing_api.client_for_basic_auth")
def test_unlock_on_fail(mocked_client):
# More generally testing errors are passed through from the client
mocked_client.return_value.save_locked_judgment_xml.side_effect = Mock(
side_effect=MarklogicResourceLockedError(),
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a newline, to have the arrange - act - assert separation clearer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


response = TestClient(app).request(
"PATCH",
"/judgment/uri/path",
auth=("user", "pass"),
data="<judgment></judgment>",
params={"unlock": "1"},
)

mocked_client.return_value.save_locked_judgment_xml.assert_called()
mocked_client.return_value.checkin_judgment.assert_called_with(
judgment_uri="uri/path",
)
assert response.status_code == 409