| 
15 | 15 |     batch_processor,  | 
16 | 16 |     process_partial_response,  | 
17 | 17 | )  | 
18 |  | -from aws_lambda_powertools.utilities.batch.exceptions import BatchProcessingError  | 
 | 18 | +from aws_lambda_powertools.utilities.batch.exceptions import BatchProcessingError, UnexpectedBatchTypeError  | 
19 | 19 | from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import (  | 
20 | 20 |     DynamoDBRecord,  | 
21 | 21 | )  | 
@@ -708,3 +708,56 @@ def test_async_process_partial_response_invalid_input(async_record_handler: Call  | 
708 | 708 |     # WHEN/THEN  | 
709 | 709 |     with pytest.raises(ValueError):  | 
710 | 710 |         async_process_partial_response(batch, record_handler, processor)  | 
 | 711 | + | 
 | 712 | + | 
 | 713 | +@pytest.mark.parametrize(  | 
 | 714 | +    "event",  | 
 | 715 | +    [  | 
 | 716 | +        {},  | 
 | 717 | +        {"Records": None},  | 
 | 718 | +        {"Records": "not a list"},  | 
 | 719 | +    ],  | 
 | 720 | +)  | 
 | 721 | +def test_process_partial_response_raises_unexpected_batch_type(event, record_handler):  | 
 | 722 | +    # GIVEN a batch processor configured for SQS events  | 
 | 723 | +    processor = BatchProcessor(event_type=EventType.SQS)  | 
 | 724 | + | 
 | 725 | +    # WHEN processing an event with invalid Records  | 
 | 726 | +    with pytest.raises(UnexpectedBatchTypeError) as exc_info:  | 
 | 727 | +        process_partial_response(  | 
 | 728 | +            event=event,  | 
 | 729 | +            record_handler=record_handler,  | 
 | 730 | +            processor=processor,  | 
 | 731 | +        )  | 
 | 732 | + | 
 | 733 | +    # THEN the correct error message is raised  | 
 | 734 | +    assert "Unexpected batch event type. Possible values are: SQS, KinesisDataStreams, DynamoDBStreams" in str(  | 
 | 735 | +        exc_info.value,  | 
 | 736 | +    )  | 
 | 737 | + | 
 | 738 | + | 
 | 739 | +@pytest.mark.asyncio  | 
 | 740 | +@pytest.mark.parametrize(  | 
 | 741 | +    "event",  | 
 | 742 | +    [  | 
 | 743 | +        {},  | 
 | 744 | +        {"Records": None},  | 
 | 745 | +        {"Records": "not a list"},  | 
 | 746 | +    ],  | 
 | 747 | +)  | 
 | 748 | +async def test_async_process_partial_response_raises_unexpected_batch_type(event, async_record_handler):  | 
 | 749 | +    # GIVEN a batch processor configured for SQS events  | 
 | 750 | +    processor = BatchProcessor(event_type=EventType.SQS)  | 
 | 751 | + | 
 | 752 | +    # WHEN processing an event with invalid Records asynchronously  | 
 | 753 | +    with pytest.raises(UnexpectedBatchTypeError) as exc_info:  | 
 | 754 | +        await async_process_partial_response(  | 
 | 755 | +            event=event,  | 
 | 756 | +            record_handler=async_record_handler,  | 
 | 757 | +            processor=processor,  | 
 | 758 | +        )  | 
 | 759 | + | 
 | 760 | +    # THEN the correct error message is raised  | 
 | 761 | +    assert "Unexpected batch event type. Possible values are: SQS, KinesisDataStreams, DynamoDBStreams" in str(  | 
 | 762 | +        exc_info.value,  | 
 | 763 | +    )  | 
0 commit comments