|
4 | 4 | from folioclient import FolioClient |
5 | 5 | from pymarc import Field, Indicators, Subfield |
6 | 6 |
|
7 | | -from folio_migration_tools.custom_exceptions import TransformationProcessError |
| 7 | +from folio_migration_tools.custom_exceptions import ( |
| 8 | + TransformationProcessError, |
| 9 | + TransformationRecordFailedError, |
| 10 | +) |
8 | 11 | from folio_migration_tools.library_configuration import FolioRelease |
9 | 12 | from folio_migration_tools.marc_rules_transformation.conditions import Conditions |
10 | 13 | from folio_migration_tools.marc_rules_transformation.rules_mapper_base import RulesMapperBase |
@@ -331,3 +334,51 @@ def test_condition_set_electronic_access_relations_id(folio_client_fixture): |
331 | 334 | # ], |
332 | 335 | # )) |
333 | 336 | # assert res == "d6488f88-1e74-40ce-81b5-b19a928ff5b6" |
| 337 | + |
| 338 | + |
| 339 | +def test_condition_set_holdings_note_type_id_exception_logs_error(caplog): |
| 340 | + """Test that condition_set_holdings_note_type_id logs error when lookup fails.""" |
| 341 | + mock = create_autospec(Conditions) |
| 342 | + mock.mapper = Mock(spec=BibsRulesMapper) |
| 343 | + mock.mapper.migration_report = Mock(spec=MigrationReport) |
| 344 | + mock.folio = Mock(spec=FolioClient) |
| 345 | + mock.folio.holding_note_types = [] |
| 346 | + # Simulate exception from get_ref_data_tuple_by_name |
| 347 | + mock.get_ref_data_tuple_by_name.side_effect = Exception("Note type not found") |
| 348 | + |
| 349 | + parameter = {"name": "Unknown Note Type"} |
| 350 | + marc_field = Field( |
| 351 | + tag="852", |
| 352 | + indicators=["0", "1"], |
| 353 | + subfields=[Subfield(code="a", value="Test")], |
| 354 | + ) |
| 355 | + |
| 356 | + with pytest.raises(TransformationRecordFailedError) as exc_info: |
| 357 | + Conditions.condition_set_holdings_note_type_id(mock, "legacy-id-123", "value", parameter, marc_field) |
| 358 | + |
| 359 | + assert "Holdings note type mapping error" in str(exc_info.value) |
| 360 | + |
| 361 | + |
| 362 | +def test_condition_set_identifier_type_id_by_name_exception_logs(caplog): |
| 363 | + """Test that condition_set_identifier_type_id_by_name logs exception when lookup fails.""" |
| 364 | + mock = create_autospec(Conditions) |
| 365 | + mock.mapper = Mock(spec=BibsRulesMapper) |
| 366 | + mock.mapper.migration_report = Mock(spec=MigrationReport) |
| 367 | + mock.folio = Mock(spec=FolioClient) |
| 368 | + mock.folio.identifier_types = [] |
| 369 | + # Simulate exception from get_ref_data_tuple_by_name |
| 370 | + mock.get_ref_data_tuple_by_name.side_effect = Exception("Identifier type not found") |
| 371 | + |
| 372 | + parameter = {"name": "Unknown Identifier Type"} |
| 373 | + marc_field = Field( |
| 374 | + tag="020", |
| 375 | + indicators=[" ", " "], |
| 376 | + subfields=[Subfield(code="a", value="1234567890")], |
| 377 | + ) |
| 378 | + |
| 379 | + with pytest.raises(TransformationProcessError) as exc_info: |
| 380 | + Conditions.condition_set_identifier_type_id_by_name( |
| 381 | + mock, "legacy-id-456", "value", parameter, marc_field |
| 382 | + ) |
| 383 | + |
| 384 | + assert "Unmapped identifier type" in str(exc_info.value) |
0 commit comments