[python-experimental] Adds response body tests for json content type (#12988)

* Tags renamed

* Spec updated to add response bodies

* Adds correct tag to response body routes

* Adds response body autogen tests

* Adds pos test cases, removes dead code

* Adds and uses api_test_partial

* Samples regenerated
This commit is contained in:
Justin Black
2022-07-24 12:33:23 -07:00
committed by GitHub
parent 96b7d35e97
commit 30f1f11205
545 changed files with 122756 additions and 37045 deletions

View File

@@ -1109,9 +1109,6 @@ class DictBase(Discriminable):
ApiValueError: when a string can't be converted into a date or datetime and it must be one of those classes
ApiTypeError: when the input type is not in the list of allowed spec types
"""
if isinstance(arg, cls):
# an instance of the correct type was passed in
return {}
_path_to_schemas = super()._validate(arg, validation_metadata=validation_metadata)
if not isinstance(arg, frozendict):
return _path_to_schemas
@@ -1662,18 +1659,6 @@ class ComposedBase(Discriminable):
ApiValueError: when a string can't be converted into a date or datetime and it must be one of those classes
ApiTypeError: when the input type is not in the list of allowed spec types
"""
if isinstance(arg, Schema) and validation_metadata.from_server is False:
if isinstance(arg, cls):
# an instance of the correct type was passed in
return {}
raise ApiTypeError(
'Incorrect type passed in, required type was {} and passed type was {} at {}'.format(
cls,
type(arg),
validation_metadata.path_to_item
)
)
# validation checking on types, validations, and enums
path_to_schemas = super()._validate(arg, validation_metadata=validation_metadata)
@@ -2105,43 +2090,6 @@ class DictSchema(
schema_type_classes = set([NoneSchema, DictSchema, ListSchema, NumberSchema, StrSchema, BoolSchema])
def deserialize_file(response_data, configuration, content_disposition=None):
"""Deserializes body to file
Saves response body into a file in a temporary folder,
using the filename from the `Content-Disposition` header if provided.
Args:
param response_data (str): the file data to write
configuration (Configuration): the instance to use to convert files
Keyword Args:
content_disposition (str): the value of the Content-Disposition
header
Returns:
(file_type): the deserialized file which is open
The user is responsible for closing and reading the file
"""
fd, path = tempfile.mkstemp(dir=configuration.temp_folder_path)
os.close(fd)
os.remove(path)
if content_disposition:
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition).group(1)
path = os.path.join(os.path.dirname(path), filename)
with open(path, "wb") as f:
if isinstance(response_data, str):
# change str to bytes so we can write it
response_data = response_data.encode('utf-8')
f.write(response_data)
f = open(path, "rb")
return f
@functools.cache
def get_new_class(
class_name: str,

View File

@@ -16,8 +16,8 @@ class ApiTestMixin:
url: str,
method: str = 'POST',
body: typing.Optional[bytes] = None,
content_type: typing.Optional[str] = 'application/json',
accept_content_type: typing.Optional[str] = 'application/json',
content_type: typing.Optional[str] = None,
accept_content_type: typing.Optional[str] = None,
stream: bool = False,
):
headers = {