Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Sep 2, 2024
1 parent c03dcd6 commit 138e9ae
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
62 changes: 62 additions & 0 deletions integration_tests/base_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,68 @@ async def async_split_request_combined(
}


@app.post("/sync/split_request_typed_untyped/combined")
def sync_split_request_typed_untyped_combined(
query_params,
request_method: RequestMethod,
request_body: RequestBody,
url: RequestURL,
headers: Headers,
):
return {
"body": request_body,
"query_params": query_params.to_dict(),
"method": request_method,
"url": url.path,
"headers": headers.get("server"),
}


@app.post("/async/split_request_typed_untyped/combined")
async def async_split_request_typed_untyped_combined(
query_params,
request_method: RequestMethod,
request_body: RequestBody,
url: RequestURL,
headers: Headers,
):
return {
"body": request_body,
"query_params": query_params.to_dict(),
"method": request_method,
"url": url.path,
"headers": headers.get("server"),
}


@app.post("/sync/split_request_typed_untyped/combined/failure")
def sync_split_request_typed_untyped_combined_failure(
query_params, request_method: RequestMethod, request_body: RequestBody, url: RequestURL, headers: Headers, vishnu
):
return {
"body": request_body,
"query_params": query_params.to_dict(),
"method": request_method,
"url": url.path,
"headers": headers.get("server"),
"vishnu": vishnu,
}


@app.post("/async/split_request_typed_untyped/combined/failure")
async def async_split_request_typed_untyped_combined_failure(
query_params, request_method: RequestMethod, request_body: RequestBody, url: RequestURL, headers: Headers, vishnu
):
return {
"body": request_body,
"query_params": query_params.to_dict(),
"method": request_method,
"url": url.path,
"headers": headers.get("server"),
"vishnu": vishnu,
}


@app.get("/openapi_test", openapi_tags=["test tag"])
def sample_openapi_endpoint():
"""Get openapi"""
Expand Down
22 changes: 22 additions & 0 deletions integration_tests/test_split_request_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,25 @@ def test_split_request_params_get_combined(session, type_route, function_type):
assert out["method"] == "POST"
assert out["url"] == f"/{function_type}/{type_route}/combined"
assert out["headers"] == "robyn"


@pytest.mark.benchmark
@pytest.mark.parametrize("function_type", ["sync", "async"])
def test_split_request_params_typed_untyped_post_combined(session, function_type):
res = post(
f"/{function_type}/split_request_typed_untyped/combined?hello=robyn&a=1&b=2",
data={"hello": "world"},
)
out = res.json()
assert out["query_params"] == {"hello": ["robyn"], "a": ["1"], "b": ["2"]}
assert out["body"] == "hello=world"
assert out["method"] == "POST"
assert out["url"] == f"/{function_type}/split_request_typed_untyped/combined"
assert out["headers"] == "robyn"


@pytest.mark.benchmark
@pytest.mark.parametrize("function_type", ["sync", "async"])
def test_split_request_params_get_combined_failure(session, function_type):
res = post(f"/{function_type}/split_request_typed_untyped/combined/failure?hello=robyn&a=1&b=2", data={"hello": "world"}, should_check_response=False)
assert 500 == res.status_code

0 comments on commit 138e9ae

Please sign in to comment.