|
1 | 1 | from dataclasses import dataclass
|
2 | 2 | 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 |
4 | 4 |
|
5 | 5 | import pytest
|
6 | 6 | from attrs import define
|
@@ -197,6 +197,43 @@ async def item() -> ResponseReturnValue:
|
197 | 197 | assert response.status_code == status
|
198 | 198 |
|
199 | 199 |
|
| 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 | + |
200 | 237 | async def test_redirect_validation() -> None:
|
201 | 238 | app = Quart(__name__)
|
202 | 239 | QuartSchema(app)
|
|
0 commit comments