Skip to content

Commit 5056ce2

Browse files
committed
Add a test example for list responses
To demonstrate and ensure it does work.
1 parent a65ed87 commit 5056ce2

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

tests/test_validation.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22
from io import BytesIO
3-
from typing import Annotated, Any, List, Optional, Tuple, Type, TypeVar, Union
3+
from typing import Annotated, Any, List, Literal, Optional, Tuple, Type, TypeVar, Union
44

55
import pytest
66
from attrs import define
@@ -197,6 +197,43 @@ async def item() -> ResponseReturnValue:
197197
assert response.status_code == status
198198

199199

200+
@pytest.mark.parametrize(
201+
"type_, preference",
202+
[
203+
(AItem, "msgspec"),
204+
(DCItem, "msgspec"),
205+
(MItem, "msgspec"),
206+
(DCItem, "pydantic"),
207+
(PyItem, "pydantic"),
208+
(PyDCItem, "pydantic"),
209+
],
210+
)
211+
@pytest.mark.parametrize(
212+
"return_value, status",
213+
[
214+
(VALID_DICT, 200),
215+
(INVALID_DICT, 500),
216+
],
217+
)
218+
async def test_response_list_validation(
219+
type_: Type[Union[AItem, DCItem, MItem, PyItem, PyDCItem]],
220+
preference: Literal["msgspec", "pydantic"],
221+
return_value: Any,
222+
status: int,
223+
) -> None:
224+
app = Quart(__name__)
225+
QuartSchema(app, conversion_preference=preference)
226+
227+
@app.route("/")
228+
@validate_response(List[type_]) # type: ignore
229+
async def item() -> ResponseReturnValue:
230+
return [return_value]
231+
232+
test_client = app.test_client()
233+
response = await test_client.get("/")
234+
assert response.status_code == status
235+
236+
200237
async def test_redirect_validation() -> None:
201238
app = Quart(__name__)
202239
QuartSchema(app)

0 commit comments

Comments
 (0)