Skip to content

Commit 5b1d604

Browse files
yizzyyizzy
authored andcommitted
tests(openapi): use specific ValueError in parse form data exception test
1 parent ce420e7 commit 5b1d604

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tests/functional/event_handler/_pydantic/test_openapi_validation_middleware.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,20 +2678,21 @@ def test_parse_form_data_exception(monkeypatch):
26782678
"""Test that _parse_form_data raises RequestValidationError on exception"""
26792679
import pytest
26802680
from aws_lambda_powertools.event_handler.middlewares.openapi_validation import OpenAPIRequestValidationMiddleware
2681+
from aws_lambda_powertools.event_handler.openapi.exceptions import RequestValidationError
26812682
class DummyEvent:
26822683
decoded_body = None
26832684
class DummyApp:
26842685
current_event = DummyEvent()
26852686
# Correct monkeypatch: replace parse_qs with a function that raises Exception
26862687
def _raise(*a, **kw):
2687-
raise Exception("fail")
2688+
raise ValueError("fail")
26882689

26892690
monkeypatch.setattr(
26902691
"aws_lambda_powertools.event_handler.middlewares.openapi_validation.parse_qs",
26912692
_raise,
26922693
)
26932694
middleware = OpenAPIRequestValidationMiddleware()
2694-
with pytest.raises(Exception) as excinfo:
2695+
with pytest.raises(RequestValidationError) as excinfo:
26952696
middleware._parse_form_data(DummyApp())
26962697
assert "Form data parsing error" in str(excinfo.value)
26972698
assert "fail" in str(excinfo.value)

0 commit comments

Comments
 (0)