1- from aws_lambda_powertools .utilities .validation import validate
1+ import pytest
2+
3+ from aws_lambda_powertools .utilities .validation import exceptions , validate
24
35
46def test_validate_raw_event (schema , raw_event ):
57 validate (event = raw_event , schema = schema )
68
79
8- def test_validate_raw_envelope (schema , wrapped_event ):
10+ def test_validate_wrapped_event_raw_envelope (schema , wrapped_event ):
911 validate (event = wrapped_event , schema = schema , envelope = "data.payload" )
1012
1113
@@ -17,20 +19,31 @@ def test_validate_base64_string_envelope(schema, wrapped_event_base64_json_strin
1719 validate (event = wrapped_event_base64_json_string , schema = schema , envelope = "powertools_json(powertools_base64(data))" )
1820
1921
22+ def test_validate_event_does_not_conform_with_schema (schema ):
23+ with pytest .raises (exceptions .SchemaValidationError ):
24+ validate (event = {"message" : "hello_world" }, schema = schema )
25+
26+
2027def test_validate_json_string_no_envelope (schema , wrapped_event_json_string ):
21- raise NotImplementedError ()
28+ # WHEN data key contains a JSON String
29+ with pytest .raises (exceptions .SchemaValidationError , match = ".*data must be object" ):
30+ validate (event = wrapped_event_json_string , schema = schema , envelope = "data.payload" )
2231
2332
24- def test_invalid_schema_format_exception ():
25- raise NotImplementedError ()
33+ def test_validate_invalid_schema_format (raw_event ):
34+ with pytest .raises (exceptions .InvalidSchemaFormatError ):
35+ validate (event = raw_event , schema = "" )
2636
2737
28- def test_invalid_envelope_expression ():
29- raise NotImplementedError ()
38+ def test_validate_invalid_envelope_expression (schema , wrapped_event ):
39+ with pytest .raises (exceptions .InvalidEnvelopeExpressionError ):
40+ validate (event = wrapped_event , schema = schema , envelope = True )
3041
3142
32- def test_invalid_event ():
33- raise NotImplementedError ()
43+ def test_validate_invalid_event (schema ):
44+ b64_event = "eyJtZXNzYWdlIjogImhlbGxvIGhlbGxvIiwgInVzZXJuYW1lIjogImJsYWggYmxhaCJ9="
45+ with pytest .raises (exceptions .SchemaValidationError ):
46+ validate (event = b64_event , schema = schema )
3447
3548
3649def test_apigateway_http_envelope ():
0 commit comments