diff --git a/tests/test_convertors.py b/tests/test_convertors.py index ced1b86cc7..7082b370e8 100644 --- a/tests/test_convertors.py +++ b/tests/test_convertors.py @@ -1,5 +1,6 @@ from datetime import datetime from typing import Iterator +from uuid import UUID import pytest @@ -58,15 +59,30 @@ def test_datetime_convertor(test_client_factory: TestClientFactory, app: Router) ) -@pytest.mark.parametrize("param, status_code", [("1.0", 200), ("1-0", 404)]) -def test_default_float_convertor(test_client_factory: TestClientFactory, param: str, status_code: int) -> None: - def float_convertor(request: Request) -> JSONResponse: +@pytest.mark.parametrize( + "param_type, param_value, status_code", + [ + ("float", "1.0", 200), + ("float", "1-0", 404), + ("uuid", "00000000-aaaa-ffff-9999-000000000000", 200), + ("uuid", "00000000aaaaffff9999000000000000", 200), + ("uuid", "00000000-AAAA-FFFF-9999-000000000000", 200), + ("uuid", "00000000AAAAFFFF9999000000000000", 200), + ("uuid", "not-a-uuid", 404), + ], +) +def test_default_convertor( + test_client_factory: TestClientFactory, param_type: str, param_value: str, status_code: int +) -> None: + expected_types = {"float": float, "uuid": UUID} + + def convertor(request: Request) -> JSONResponse: param = request.path_params["param"] - assert isinstance(param, float) - return JSONResponse({"float": param}) + assert isinstance(param, expected_types[param_type]) + return JSONResponse("ok") - app = Router(routes=[Route("/{param:float}", endpoint=float_convertor)]) + app = Router(routes=[Route(f"/{{param:{param_type}}}", endpoint=convertor)]) client = test_client_factory(app) - response = client.get(f"/{param}") + response = client.get(f"/{param_value}") assert response.status_code == status_code