Skip to content

Commit

Permalink
Test default UUID convertor
Browse files Browse the repository at this point in the history
  • Loading branch information
edthrn committed Dec 17, 2024
1 parent a6d581e commit 85e92be
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_convertors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from typing import Iterator
from uuid import UUID

import pytest

Expand Down Expand Up @@ -70,3 +71,26 @@ def float_convertor(request: Request) -> JSONResponse:
client = test_client_factory(app)
response = client.get(f"/{param}")
assert response.status_code == status_code


@pytest.mark.parametrize(
"param, status_code",
[
("00000000-aaaa-ffff-9999-000000000000", 200),
("00000000aaaaffff9999000000000000", 200),
("00000000-AAAA-FFFF-9999-000000000000", 200),
("00000000AAAAFFFF9999000000000000", 200),
("not-a-uuid", 404),
],
)
def test_default_uuid_convertor(test_client_factory: TestClientFactory, param: str, status_code: int) -> None:
def uuid_convertor(request: Request) -> JSONResponse:
param = request.path_params["param"]
assert isinstance(param, UUID)
return JSONResponse("ok")

app = Router(routes=[Route("/{param:uuid}", endpoint=uuid_convertor)])

client = test_client_factory(app)
response = client.get(f"/{param}")
assert response.status_code == status_code

0 comments on commit 85e92be

Please sign in to comment.