Skip to content

Commit eb2430b

Browse files
author
Amin Farjadi
committed
feat(unit-test): add tests for incorrect types and invalid configs
1 parent f8ead84 commit eb2430b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/unit/event_handler/test_response_validation.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,25 @@ def handle_response_validation_error(ex: ResponseValidationError):
179179

180180
assert response["statusCode"] == HTTPStatus.INTERNAL_SERVER_ERROR
181181
assert response["body"] == "Unexpected response."
182+
183+
def test_incorrect_resolver_config_no_validation(self):
184+
with pytest.raises(ValueError) as exception_info:
185+
APIGatewayRestResolver(response_validation_error_http_status=500)
186+
187+
assert (
188+
str(exception_info.value)
189+
== "'response_validation_error_http_status' cannot be set when enable_validation is False."
190+
)
191+
192+
@pytest.mark.parametrize("response_validation_error_http_status", [(20), ("hi"), (1.21)])
193+
def test_incorrect_resolver_config_bad_http_status_code(self, response_validation_error_http_status):
194+
with pytest.raises(ValueError) as exception_info:
195+
APIGatewayRestResolver(
196+
enable_validation=True,
197+
response_validation_error_http_status=response_validation_error_http_status,
198+
)
199+
200+
assert (
201+
str(exception_info.value)
202+
== f"'{response_validation_error_http_status}' must be an integer representing an HTTP status code."
203+
)

0 commit comments

Comments
 (0)