33
44import pydantic
55import pytest
6+ from pydantic import ValidationError
67from typing_extensions import Annotated
78
89from aws_lambda_powertools .utilities .parser import (
@@ -18,7 +19,7 @@ def test_parser_unsupported_event(dummy_schema, invalid_value):
1819 def handle_no_envelope (event : Dict , _ : LambdaContext ):
1920 return event
2021
21- with pytest .raises (exceptions . InvalidModelTypeError ):
22+ with pytest .raises (ValidationError ):
2223 handle_no_envelope (event = invalid_value , context = LambdaContext ())
2324
2425
@@ -75,7 +76,7 @@ def validate_field(cls, value):
7576 assert event_parsed .version == int (event_raw ["version" ])
7677
7778
78- @pytest .mark .parametrize ("invalid_schema" , [str , False , [], ()])
79+ @pytest .mark .parametrize ("invalid_schema" , [False , [], ()])
7980def test_parser_with_invalid_schema_type (dummy_event , invalid_schema ):
8081 @event_parser (model = invalid_schema )
8182 def handle_no_envelope (event : Dict , _ : LambdaContext ):
@@ -120,6 +121,15 @@ def handler(evt: dummy_schema, _: LambdaContext):
120121 handler (dummy_event ["payload" ], LambdaContext ())
121122
122123
124+ def test_parser_event_with_payload_not_match_schema (dummy_event , dummy_schema ):
125+ @event_parser (model = dummy_schema )
126+ def handler (event , _ ):
127+ assert event .message == "hello world"
128+
129+ with pytest .raises (ValidationError ):
130+ handler ({"project" : "powertools" }, LambdaContext ())
131+
132+
123133@pytest .mark .parametrize (
124134 "test_input,expected" ,
125135 [
0 commit comments