Skip to content

Commit

Permalink
test queryparams
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Sep 28, 2024
1 parent c7a3f97 commit c41cd66
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions integration_tests/base_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from robyn.authentication import AuthenticationHandler, BearerGetter, Identity
from robyn.robyn import QueryParams
from robyn.templating import JinjaTemplate
from robyn.types import JSONResponse, PathParams, RequestBody, RequestMethod, RequestURL
from robyn.types import JSONResponse, PathParams, RequestBody, RequestMethod, RequestURL, RequestQuery

app = Robyn(__file__)
websocket = WebSocket(app, "/web_socket")
Expand Down Expand Up @@ -1075,8 +1075,12 @@ class CreateItemResponse(JSONResponse):
items_changed: int


class CreateItemQueryParams(RequestQuery):
required: bool


@app.post("/openapi_request_body")
def create_item(request, body: CreateItemBody) -> CreateItemResponse:
def create_item(request, body: CreateItemBody, query: CreateItemQueryParams) -> CreateItemResponse:
return CreateItemResponse(success=True, items_changed=2)


Expand Down
18 changes: 18 additions & 0 deletions integration_tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,21 @@ def test_openapi_response_body():
"integer"
== openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["items_changed"]["type"]
)


@pytest.mark.benchmark
def test_openapi_query_params():
openapi_spec = get("/openapi.json").json()

assert isinstance(openapi_spec, dict)

route_type = "post"
endpoint = "/openapi_request_body"

assert endpoint in openapi_spec["paths"]
assert route_type in openapi_spec["paths"][endpoint]
assert "parameters" in openapi_spec["paths"][endpoint][route_type]

assert "required" == openapi_spec["paths"][endpoint][route_type]["parameters"][0]["name"]
assert "query" == openapi_spec["paths"][endpoint][route_type]["parameters"][0]["in"]
assert {"type": "boolean"} == openapi_spec["paths"][endpoint][route_type]["parameters"][0]["schema"]

0 comments on commit c41cd66

Please sign in to comment.