Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Sep 25, 2024
1 parent ff71f81 commit b5a9bcc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 52 deletions.
19 changes: 12 additions & 7 deletions integration_tests/base_routes.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
import pathlib
from collections import defaultdict
from typing import Optional, TypedDict
from typing import Optional

from integration_tests.subroutes import di_subrouter, sub_router
from integration_tests.views import AsyncView, SyncView
from robyn import Headers, Request, Response, Robyn, WebSocket, WebSocketConnector, jsonify, serve_file, serve_html
from robyn.authentication import AuthenticationHandler, BearerGetter, Identity
from robyn.robyn import QueryParams
from robyn.templating import JinjaTemplate
from robyn.types import PathParams, RequestBody, RequestMethod, RequestURL
from robyn.types import PathParams, RequestBody, RequestMethod, RequestURL, JSONResponse

app = Robyn(__file__)
websocket = WebSocket(app, "/web_socket")
Expand Down Expand Up @@ -1052,27 +1052,32 @@ def sample_openapi_endpoint():
return 200


class Initial(TypedDict):
class Initial(RequestBody):
is_present: bool
letter: Optional[str]


class FullName(TypedDict):
class FullName(RequestBody):
first: str
second: str
initial: Initial


class CreateItemBody(TypedDict):
class CreateItemBody(RequestBody):
name: FullName
description: str
price: float
tax: float


class CreateItemResponse(JSONResponse):
success: bool
items_changed: int


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


def main():
Expand Down
50 changes: 5 additions & 45 deletions integration_tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,54 +138,14 @@ def test_openapi_response_body():
assert "schema" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]
assert "properties" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]

assert "name" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]
assert "description" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]
assert "price" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]
assert "tax" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]
assert "success" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]
assert "items_changed" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]

assert (
"string"
== openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["description"]["type"]
"boolean" == openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["success"]["type"]
)
assert "number" == openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["price"]["type"]
assert "number" == openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["tax"]["type"]

assert "object" == openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["name"]["type"]

assert (
"first" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["name"]["properties"]
)
assert (
"second" in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["name"]["properties"]
"integer"
== openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["items_changed"]["type"]
)
assert (
"initial"
in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["name"]["properties"]
)

assert (
"object"
in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["name"]["properties"][
"initial"
]["type"]
)

assert (
"is_present"
in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["name"]["properties"][
"initial"
]["properties"]
)
assert (
"letter"
in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["name"]["properties"][
"initial"
]["properties"]
)

assert {"type": "string"} in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["name"][
"properties"
]["initial"]["properties"]["letter"]["anyOf"]
assert {"type": "null"} in openapi_spec["paths"][endpoint][route_type]["responses"]["200"]["content"]["application/json"]["schema"]["properties"]["name"][
"properties"
]["initial"]["properties"]["letter"]["anyOf"]

0 comments on commit b5a9bcc

Please sign in to comment.