Skip to content

Commit 5cd0006

Browse files
author
Michael Brewer
committed
chore: add a strict comparison
1 parent 11b887a commit 5cd0006

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

aws_lambda_powertools/utilities/validation/exceptions.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,28 @@ def __init__(
2424
message : str
2525
Powertools formatted error message
2626
validation_message : str, optional
27-
Containing human-readable information what is wrong (e.g. ``data.property[index] must be smaller than or
28-
equal to 42``)
27+
Containing human-readable information what is wrong
28+
(e.g. `data.property[index] must be smaller than or equal to 42`)
2929
name : str, optional
30-
name of a path in the data structure (e.g. ``data.property[index]``)
30+
name of a path in the data structure
31+
(e.g. `data.property[index]`)
3132
path: List, optional
32-
``path`` as an array in the data structure (e.g. ``['data', 'property', 'index']``),
33+
`path` as an array in the data structure
34+
(e.g. `['data', 'property', 'index']`),
3335
value : Any, optional
34-
the invalid value
36+
The invalid value
3537
definition : Any, optional
36-
The full rule ``definition`` (e.g. ``42``)
38+
The full rule `definition`
39+
(e.g. `42`)
3740
rule : str, optional
38-
`rule`` which the ``data`` is breaking (e.g. ``maximum``)
41+
`rule` which the `data` is breaking
42+
(e.g. `maximum`)
3943
rule_definition : Any, optional
40-
The full rule ``definition`` (e.g. ``42``)
44+
The specific rule `definition`
45+
(e.g. `42`)
4146
"""
4247
super().__init__(message)
4348
self.message = message
44-
4549
self.validation_message = validation_message
4650
self.name = name
4751
self.path = path

tests/functional/validator/test_validator.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
import jmespath
24
import pytest
35
from jmespath import functions
@@ -22,8 +24,15 @@ def test_validate_base64_string_envelope(schema, wrapped_event_base64_json_strin
2224

2325

2426
def test_validate_event_does_not_conform_with_schema(schema):
25-
with pytest.raises(exceptions.SchemaValidationError):
26-
validate(event={"message": "hello_world"}, schema=schema)
27+
data = {"message": "hello_world"}
28+
with pytest.raises(
29+
exceptions.SchemaValidationError,
30+
match=re.escape(
31+
"Failed schema validation. Error: data must contain ['message', 'username'] properties, "
32+
f"Path: ['data'], Data: {data}"
33+
),
34+
):
35+
validate(event=data, schema=schema)
2736

2837

2938
def test_validate_json_string_no_envelope(schema, wrapped_event_json_string):

0 commit comments

Comments
 (0)