Skip to content

Commit

Permalink
Catch for non-digit values and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymedina committed Sep 30, 2024
1 parent cdeab20 commit c5ae645
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion synapseclient/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ def validate_submission_id(
if syn_id is not None:
return validate_submission_id(syn_id)
else:
int_submission_id = int(float(submission_id))
try:
int_submission_id = int(float(submission_id))
except ValueError:
raise ValueError(
f"Submission ID '{submission_id}' is not a valid submission ID. Please use digits only."
)
LOGGER.warning(
f"Submission ID '{submission_id}' contains decimals which are not supported. "
f"Submission ID will be converted to '{int_submission_id}'."
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/synapseclient/core/unit_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ def test_validate_submission_id(input_value, expected_output, expected_warning,
assert not caplog.text


def test_validate_submission_id_letters_input() -> None:
letters_input = "syn123"
expected_error = f"Submission ID '{letters_input}' is not a valid submission ID. Please use digits only."
with pytest.raises(ValueError) as err:
utils.validate_submission_id(letters_input)

assert str(err.value) == expected_error


# TODO: Add a test for is_synapse_id_str(...)
# https://sagebionetworks.jira.com/browse/SYNPY-1425

Expand Down

0 comments on commit c5ae645

Please sign in to comment.