Skip to content

Commit a8ca734

Browse files
authored
Merge pull request #85 from gridsmartercities/fix_null_with_regex
fixed mandatory with regex when field is missing
2 parents e1e7dc8 + 92a8852 commit a8ca734

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

aws_lambda_decorators/validators.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def validate(self, value=None):
7777
Args:
7878
value (str): Value to be validated.
7979
"""
80+
if not value:
81+
return True
82+
8083
return self._regexp.fullmatch(value) is not None
8184

8285

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
LONG_DESCRIPTION = open('README.md').read()
44

55
setup(name='aws-lambda-decorators',
6-
version='0.32',
6+
version='0.33',
77
description='A set of python decorators to simplify aws python lambda development',
88
long_description=LONG_DESCRIPTION,
99
long_description_content_type="text/markdown",

tests/test_decorators.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,3 +1257,21 @@ def handler(event, context, c=None, d=None): # noqa: pylint - unused-argument
12571257
]}
12581258
]
12591259
)
1260+
1261+
def test_extract_returns_400_on_missing_mandatory_key_with_regex(self):
1262+
path = "/a/b/c"
1263+
dictionary = {
1264+
"a": {
1265+
"b": {
1266+
}
1267+
}
1268+
}
1269+
1270+
@extract([Parameter(path, 'event', validators=[Mandatory, RegexValidator("[0-9]+")])], group_errors=True)
1271+
def handler(event, context, c=None): # noqa
1272+
return {}
1273+
1274+
response = handler(dictionary, None)
1275+
1276+
self.assertEqual(400, response["statusCode"])
1277+
self.assertEqual('{"message": [{"c": ["Missing mandatory value"]}]}', response["body"])

0 commit comments

Comments
 (0)