|
1 | 1 | """Unit tests for the synapseclient.models.StorageLocation class.""" |
2 | 2 |
|
3 | 3 | import re |
4 | | -from unittest.mock import AsyncMock, patch |
| 4 | +from unittest.mock import AsyncMock, MagicMock, patch |
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
@@ -445,6 +445,49 @@ def test_fill_from_dict(self, response, expected_attrs): |
445 | 445 | for attr, value in expected_attrs.items(): |
446 | 446 | assert getattr(storage, attr) == value |
447 | 447 |
|
| 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 | + |
448 | 491 | def test_fill_from_dict_type_isolation(self): |
449 | 492 | """Test that fill_from_dict only populates fields relevant to the storage type.""" |
450 | 493 | # GIVEN an EXTERNAL_SFTP response (no S3 or proxy fields) |
|
0 commit comments