Skip to content

Commit

Permalink
feat(unit-test): add tests for incorrect types and invalid configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Amin Farjadi committed Feb 28, 2025
1 parent f8ead84 commit eb2430b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/unit/event_handler/test_response_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,25 @@ def handle_response_validation_error(ex: ResponseValidationError):

assert response["statusCode"] == HTTPStatus.INTERNAL_SERVER_ERROR
assert response["body"] == "Unexpected response."

def test_incorrect_resolver_config_no_validation(self):
with pytest.raises(ValueError) as exception_info:
APIGatewayRestResolver(response_validation_error_http_status=500)

assert (
str(exception_info.value)
== "'response_validation_error_http_status' cannot be set when enable_validation is False."
)

@pytest.mark.parametrize("response_validation_error_http_status", [(20), ("hi"), (1.21)])
def test_incorrect_resolver_config_bad_http_status_code(self, response_validation_error_http_status):
with pytest.raises(ValueError) as exception_info:
APIGatewayRestResolver(
enable_validation=True,
response_validation_error_http_status=response_validation_error_http_status,
)

assert (
str(exception_info.value)
== f"'{response_validation_error_http_status}' must be an integer representing an HTTP status code."
)

0 comments on commit eb2430b

Please sign in to comment.