From c5ae645061e33ebd5cfafdd316b89c63854149e9 Mon Sep 17 00:00:00 2001 From: Jenny Medina Date: Mon, 30 Sep 2024 12:44:12 -0400 Subject: [PATCH] Catch for non-digit values and add unit test --- synapseclient/core/utils.py | 7 ++++++- tests/unit/synapseclient/core/unit_test_utils.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/synapseclient/core/utils.py b/synapseclient/core/utils.py index 479113966..6a3de5a39 100644 --- a/synapseclient/core/utils.py +++ b/synapseclient/core/utils.py @@ -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}'." diff --git a/tests/unit/synapseclient/core/unit_test_utils.py b/tests/unit/synapseclient/core/unit_test_utils.py index 568cf733e..30478f7fe 100644 --- a/tests/unit/synapseclient/core/unit_test_utils.py +++ b/tests/unit/synapseclient/core/unit_test_utils.py @@ -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