Skip to content

Commit

Permalink
error handling for invalid status
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymedina committed Mar 1, 2024
1 parent d721e42 commit 0858373
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/orca/services/synapse/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,42 @@ def trigger_indexing(self, synapse_view: str) -> None:
"""
self.client.tableQuery(f"select * from {synapse_view} limit 1")

def is_valid_submission_status(self, submission_status: str) -> bool:
"""
Check if submission status is valid. Based on:
https://rest-docs.synapse.org/rest/org/sagebionetworks/evaluation/model/SubmissionStatusEnum.html
Arguments:
submission_status: The submission status to check.
Returns:
Boolean indicating if submission status is valid.
"""

# List all the available status options based on API docs
status_options = [
"OPEN",
"CLOSED",
"SCORED",
"INVALID",
"VALIDATED",
"EVALUATION_IN_PROGRESS",
"RECEIVED",
"REJECTED",
]
# Ensure that input status is valid (case-sensitive)
if submission_status.upper() not in status_options:
return False

return True

def get_submissions_with_status(
self, submission_view: str, submission_status: str = "RECEIVED"
) -> List[str]:
"""
Get all submissions with desired submission status in a Synapse
submission view.
submission view. Status can be one of:
https://rest-docs.synapse.org/rest/org/sagebionetworks/evaluation/model/SubmissionStatusEnum.html
Arguments:
submission_view: The Synapse ID of the table view to get submissions from.
Expand All @@ -88,6 +118,11 @@ def get_submissions_with_status(
A list of submission IDs.
"""
# Check if submission status is valid
if not self.is_valid_submission_status(submission_status):
message = f"Invalid submission status '{submission_status}'"
raise ValueError(message)

# Trigger indexing
self.trigger_indexing(submission_view)

Expand All @@ -107,6 +142,8 @@ def update_submission_status(
) -> None:
"""
Update the status of one or more submissions in Synapse.
Status can be one of:
https://rest-docs.synapse.org/rest/org/sagebionetworks/evaluation/model/SubmissionStatusEnum.html
Arguments:
submission_ids: The Synapse ID of the submission.
Expand Down
35 changes: 35 additions & 0 deletions tests/services/synapse/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ def test_trigger_indexing(mocker: pytest.fixture, mocked_ops: MagicMock) -> None
)


def test_is_valid_submission_status():
"""
Tests that the ``is_valid_submission_status`` method in ``SynapseOps``
returns a boolean indicating if the submission status is valid.
"""
submission_status = "receiveD"
assert SynapseOps().is_valid_submission_status(submission_status)


def test_is_valid_submission_status_incorrect_status():
"""
Tests that the ``is_valid_submission_status`` method in ``SynapseOps``
returns a boolean indicating if the submission status is valid.
"""
submission_status = "receved"
assert not SynapseOps().is_valid_submission_status(submission_status)


def test_get_submissions_with_status(
mocker: pytest.fixture, mocked_ops: MagicMock
) -> None:
Expand Down Expand Up @@ -140,6 +160,21 @@ def test_get_submissions_with_status(
assert result == input_dict["id"]


def test_get_submissions_with_status_incorrect_status():
"""
Tests that the ``get_submissions_with_status`` method in ``SynapseOps``
returns a list of submission IDs.
"""
submission_view = "syn111"
submission_status = "oops"
error_message = f"Invalid submission status '{submission_status}'"

# No need to mock anything here as it will fail before call to tableQuery
with pytest.raises(ValueError, match=error_message):
SynapseOps().get_submissions_with_status(submission_view, submission_status)


def test_update_submission_status(
mocker: pytest.fixture, mocked_ops: MagicMock
) -> None:
Expand Down

0 comments on commit 0858373

Please sign in to comment.