Skip to content

Commit de20094

Browse files
committed
add test case for the warning
1 parent 9eac7e5 commit de20094

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

tests/unit/synapseclient/models/unit_test_storage_location.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Unit tests for the synapseclient.models.StorageLocation class."""
22

33
import re
4-
from unittest.mock import AsyncMock, patch
4+
from unittest.mock import AsyncMock, MagicMock, patch
55

66
import pytest
77

@@ -445,6 +445,49 @@ def test_fill_from_dict(self, response, expected_attrs):
445445
for attr, value in expected_attrs.items():
446446
assert getattr(storage, attr) == value
447447

448+
def test_fill_from_dict_unknown_concrete_type_logs_warning(self):
449+
"""Test that fill_from_dict logs a warning for an unrecognized concreteType/uploadType pair
450+
instead of raising an exception, and still populates common fields."""
451+
# GIVEN a response with an unrecognized concreteType paired with a valid uploadType.
452+
# "FutureStorageLocationSetting" is not in _CONCRETE_UPLOAD_TO_STORAGE_TYPE,
453+
# so the (suffix, uploadType) key won't match any known storage type.
454+
response = {
455+
"storageLocationId": 99999,
456+
"concreteType": "org.sagebionetworks.repo.model.project.FutureStorageLocationSetting",
457+
"uploadType": "S3",
458+
"banner": "some banner",
459+
"description": "some description",
460+
"etag": "xyz",
461+
"createdOn": "2024-01-01T00:00:00.000Z",
462+
"createdBy": 111,
463+
}
464+
storage = StorageLocation()
465+
mock_client = MagicMock()
466+
467+
# WHEN we fill from the response
468+
with patch(
469+
"synapseclient.models.storage_location.Synapse.get_client",
470+
return_value=mock_client,
471+
):
472+
storage.fill_from_dict(response)
473+
474+
# THEN a warning is logged
475+
mock_client.logger.warning.assert_called_once_with(
476+
"Unrecognized concreteType/uploadType pair "
477+
"(org.sagebionetworks.repo.model.project.FutureStorageLocationSetting, S3); "
478+
"storage_type will not be set and type-specific fields will be empty."
479+
)
480+
# AND common fields are still populated
481+
assert storage.storage_location_id == 99999
482+
assert storage.banner == "some banner"
483+
assert storage.description == "some description"
484+
assert storage.etag == "xyz"
485+
assert storage.created_on == "2024-01-01T00:00:00.000Z"
486+
assert storage.created_by == 111
487+
488+
# AND storage_type is not set
489+
assert storage.storage_type is None
490+
448491
def test_fill_from_dict_type_isolation(self):
449492
"""Test that fill_from_dict only populates fields relevant to the storage type."""
450493
# GIVEN an EXTERNAL_SFTP response (no S3 or proxy fields)

0 commit comments

Comments
 (0)