Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add e2e test for callback parsing
  • Loading branch information
dachucky committed Aug 27, 2022
commit b27aa1f23316f609e2d310c34ffda6c60509c16d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import types

from . import (
callback_test,
defaults_tests_defaults_post,
get_basic_list_of_booleans,
get_basic_list_of_floats,
Expand Down Expand Up @@ -150,3 +151,10 @@ def token_with_cookie_auth_token_with_cookie_get(cls) -> types.ModuleType:
Test optional cookie parameters
"""
return token_with_cookie_auth_token_with_cookie_get

@classmethod
def callback_test(cls) -> types.ModuleType:
"""
Try sending a request related to a callback
"""
return callback_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
from typing import Any, Dict, Optional, Union, cast

import httpx

from ...client import Client
from ...models.a_model import AModel
from ...models.http_validation_error import HTTPValidationError
from ...types import Response


def _get_kwargs(
*,
client: Client,
json_body: AModel,
) -> Dict[str, Any]:
url = "{}/tests/callback".format(client.base_url)

headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

json_json_body = json_body.to_dict()

return {
"method": "post",
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"json": json_json_body,
}


def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
if response.status_code == 200:
response_200 = cast(Any, response.json())
return response_200
if response.status_code == 422:
response_422 = HTTPValidationError.from_dict(response.json())

return response_422
return None


def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)


def sync_detailed(
*,
client: Client,
json_body: AModel,
) -> Response[Union[Any, HTTPValidationError]]:
"""Path with callback

Try sending a request related to a callback

Args:
json_body (AModel): A Model for testing all the ways custom objects can be used

Returns:
Response[Union[Any, HTTPValidationError]]
"""

kwargs = _get_kwargs(
client=client,
json_body=json_body,
)

response = httpx.request(
verify=client.verify_ssl,
**kwargs,
)

return _build_response(response=response)


def sync(
*,
client: Client,
json_body: AModel,
) -> Optional[Union[Any, HTTPValidationError]]:
"""Path with callback

Try sending a request related to a callback

Args:
json_body (AModel): A Model for testing all the ways custom objects can be used

Returns:
Response[Union[Any, HTTPValidationError]]
"""

return sync_detailed(
client=client,
json_body=json_body,
).parsed


async def asyncio_detailed(
*,
client: Client,
json_body: AModel,
) -> Response[Union[Any, HTTPValidationError]]:
"""Path with callback

Try sending a request related to a callback

Args:
json_body (AModel): A Model for testing all the ways custom objects can be used

Returns:
Response[Union[Any, HTTPValidationError]]
"""

kwargs = _get_kwargs(
client=client,
json_body=json_body,
)

async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.request(**kwargs)

return _build_response(response=response)


async def asyncio(
*,
client: Client,
json_body: AModel,
) -> Optional[Union[Any, HTTPValidationError]]:
"""Path with callback

Try sending a request related to a callback

Args:
json_body (AModel): A Model for testing all the ways custom objects can be used

Returns:
Response[Union[Any, HTTPValidationError]]
"""

return (
await asyncio_detailed(
client=client,
json_body=json_body,
)
).parsed
56 changes: 56 additions & 0 deletions end_to_end_tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,62 @@
}
}
}
},
"/tests/callback": {
"post": {
"tags": [
"tests"
],
"summary": "Path with callback",
"description": "Try sending a request related to a callback",
"operationId": "callback_test",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AModel"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
},
"callbacks": {
"event": {
"callback": {
"post": {
"responses": {
"200": {
"description": "Success"
},
"503": {
"description": "Unavailable"
}
}
}
}
}
}
}
}
},
"components": {
Expand Down