Skip to content

Commit

Permalink
Switch from ResponseHeadersValidationError to RuntimeError
Browse files Browse the repository at this point in the history
Response instances cannot be validated, and hence it is considered a
programming error (RuntimeError) to try.

It isn't clear why b5c610b choose a
ResponseHeadersValidationError, but it doesn't make sense as the
exception type.
  • Loading branch information
pgjones committed Jan 1, 2025
1 parent b20121e commit 4c47081
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/quart_schema/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async def wrapper(*args: Any, **kwargs: Any) -> Any:

if isinstance(value, (Response, WerkzeugResponse)):
if status == status_code:
raise ResponseHeadersValidationError()
raise RuntimeError("Cannot validate Response instance")
else:
return result

Expand Down
14 changes: 14 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,20 @@ async def item() -> ResponseReturnValue:
assert response.status_code == 302


async def test_response_validation_of_response() -> None:
app = Quart(__name__)
QuartSchema(app)

@app.route("/")
@validate_response(PyItem)
async def item() -> ResponseReturnValue:
return Response(200)

test_client = app.test_client()
response = await test_client.get("/")
assert response.status_code == 500


@pytest.mark.parametrize(
"return_value, status",
[
Expand Down

0 comments on commit 4c47081

Please sign in to comment.