forked from loafle/openapi-generator-original
[python] json like str response (#18069)
* [python] json like str response * [python] fix response deserialize * [python] update sample * [python] fix echo_api test quotes
This commit is contained in:
@@ -97,7 +97,15 @@ Class | Method | HTTP request | Description
|
||||
*FakeApi* | [**fake_outer_string_serialize**](docs/FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string |
|
||||
*FakeApi* | [**fake_property_enum_integer_serialize**](docs/FakeApi.md#fake_property_enum_integer_serialize) | **POST** /fake/property/enum-int |
|
||||
*FakeApi* | [**fake_ref_enum_string**](docs/FakeApi.md#fake_ref_enum_string) | **GET** /fake/ref_enum_string | test ref to enum string
|
||||
*FakeApi* | [**fake_return_boolean**](docs/FakeApi.md#fake_return_boolean) | **GET** /fake/return_boolean | test returning boolean
|
||||
*FakeApi* | [**fake_return_byte_like_json**](docs/FakeApi.md#fake_return_byte_like_json) | **GET** /fake/return_byte_like_json | test byte like json
|
||||
*FakeApi* | [**fake_return_enum**](docs/FakeApi.md#fake_return_enum) | **GET** /fake/return_enum | test returning enum
|
||||
*FakeApi* | [**fake_return_enum_like_json**](docs/FakeApi.md#fake_return_enum_like_json) | **GET** /fake/return_enum_like_json | test enum like json
|
||||
*FakeApi* | [**fake_return_float**](docs/FakeApi.md#fake_return_float) | **GET** /fake/return_float | test returning float
|
||||
*FakeApi* | [**fake_return_int**](docs/FakeApi.md#fake_return_int) | **GET** /fake/return_int | test returning int
|
||||
*FakeApi* | [**fake_return_list_of_objects**](docs/FakeApi.md#fake_return_list_of_objects) | **GET** /fake/return_list_of_object | test returning list of objects
|
||||
*FakeApi* | [**fake_return_str_like_json**](docs/FakeApi.md#fake_return_str_like_json) | **GET** /fake/return_str_like_json | test str like json
|
||||
*FakeApi* | [**fake_return_string**](docs/FakeApi.md#fake_return_string) | **GET** /fake/return_string | test returning string
|
||||
*FakeApi* | [**fake_uuid_example**](docs/FakeApi.md#fake_uuid_example) | **GET** /fake/uuid_example | test uuid example
|
||||
*FakeApi* | [**test_additional_properties_reference**](docs/FakeApi.md#test_additional_properties_reference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties
|
||||
*FakeApi* | [**test_body_with_binary**](docs/FakeApi.md#test_body_with_binary) | **PUT** /fake/body-with-binary |
|
||||
|
||||
@@ -14,7 +14,15 @@ Method | HTTP request | Description
|
||||
[**fake_outer_string_serialize**](FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string |
|
||||
[**fake_property_enum_integer_serialize**](FakeApi.md#fake_property_enum_integer_serialize) | **POST** /fake/property/enum-int |
|
||||
[**fake_ref_enum_string**](FakeApi.md#fake_ref_enum_string) | **GET** /fake/ref_enum_string | test ref to enum string
|
||||
[**fake_return_boolean**](FakeApi.md#fake_return_boolean) | **GET** /fake/return_boolean | test returning boolean
|
||||
[**fake_return_byte_like_json**](FakeApi.md#fake_return_byte_like_json) | **GET** /fake/return_byte_like_json | test byte like json
|
||||
[**fake_return_enum**](FakeApi.md#fake_return_enum) | **GET** /fake/return_enum | test returning enum
|
||||
[**fake_return_enum_like_json**](FakeApi.md#fake_return_enum_like_json) | **GET** /fake/return_enum_like_json | test enum like json
|
||||
[**fake_return_float**](FakeApi.md#fake_return_float) | **GET** /fake/return_float | test returning float
|
||||
[**fake_return_int**](FakeApi.md#fake_return_int) | **GET** /fake/return_int | test returning int
|
||||
[**fake_return_list_of_objects**](FakeApi.md#fake_return_list_of_objects) | **GET** /fake/return_list_of_object | test returning list of objects
|
||||
[**fake_return_str_like_json**](FakeApi.md#fake_return_str_like_json) | **GET** /fake/return_str_like_json | test str like json
|
||||
[**fake_return_string**](FakeApi.md#fake_return_string) | **GET** /fake/return_string | test returning string
|
||||
[**fake_uuid_example**](FakeApi.md#fake_uuid_example) | **GET** /fake/uuid_example | test uuid example
|
||||
[**test_additional_properties_reference**](FakeApi.md#test_additional_properties_reference) | **POST** /fake/additionalProperties-reference | test referenced additionalProperties
|
||||
[**test_body_with_binary**](FakeApi.md#test_body_with_binary) | **PUT** /fake/body-with-binary |
|
||||
@@ -751,6 +759,372 @@ No authorization required
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_return_boolean**
|
||||
> bool fake_return_boolean()
|
||||
|
||||
test returning boolean
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```python
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
|
||||
try:
|
||||
# test returning boolean
|
||||
api_response = api_instance.fake_return_boolean()
|
||||
print("The response of FakeApi->fake_return_boolean:\n")
|
||||
pprint(api_response)
|
||||
except Exception as e:
|
||||
print("Exception when calling FakeApi->fake_return_boolean: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
**bool**
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/json
|
||||
|
||||
### HTTP response details
|
||||
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | OK | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_return_byte_like_json**
|
||||
> bytearray fake_return_byte_like_json()
|
||||
|
||||
test byte like json
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```python
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
|
||||
try:
|
||||
# test byte like json
|
||||
api_response = api_instance.fake_return_byte_like_json()
|
||||
print("The response of FakeApi->fake_return_byte_like_json:\n")
|
||||
pprint(api_response)
|
||||
except Exception as e:
|
||||
print("Exception when calling FakeApi->fake_return_byte_like_json: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
**bytearray**
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: plain/text
|
||||
|
||||
### HTTP response details
|
||||
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | OK | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_return_enum**
|
||||
> str fake_return_enum()
|
||||
|
||||
test returning enum
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```python
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
|
||||
try:
|
||||
# test returning enum
|
||||
api_response = api_instance.fake_return_enum()
|
||||
print("The response of FakeApi->fake_return_enum:\n")
|
||||
pprint(api_response)
|
||||
except Exception as e:
|
||||
print("Exception when calling FakeApi->fake_return_enum: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
**str**
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/json
|
||||
|
||||
### HTTP response details
|
||||
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | OK | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_return_enum_like_json**
|
||||
> str fake_return_enum_like_json()
|
||||
|
||||
test enum like json
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```python
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
|
||||
try:
|
||||
# test enum like json
|
||||
api_response = api_instance.fake_return_enum_like_json()
|
||||
print("The response of FakeApi->fake_return_enum_like_json:\n")
|
||||
pprint(api_response)
|
||||
except Exception as e:
|
||||
print("Exception when calling FakeApi->fake_return_enum_like_json: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
**str**
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: plain/text
|
||||
|
||||
### HTTP response details
|
||||
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | OK | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_return_float**
|
||||
> float fake_return_float()
|
||||
|
||||
test returning float
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```python
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
|
||||
try:
|
||||
# test returning float
|
||||
api_response = api_instance.fake_return_float()
|
||||
print("The response of FakeApi->fake_return_float:\n")
|
||||
pprint(api_response)
|
||||
except Exception as e:
|
||||
print("Exception when calling FakeApi->fake_return_float: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
**float**
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/json
|
||||
|
||||
### HTTP response details
|
||||
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | OK | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_return_int**
|
||||
> int fake_return_int()
|
||||
|
||||
test returning int
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```python
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
|
||||
try:
|
||||
# test returning int
|
||||
api_response = api_instance.fake_return_int()
|
||||
print("The response of FakeApi->fake_return_int:\n")
|
||||
pprint(api_response)
|
||||
except Exception as e:
|
||||
print("Exception when calling FakeApi->fake_return_int: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
**int**
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/json
|
||||
|
||||
### HTTP response details
|
||||
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | OK | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_return_list_of_objects**
|
||||
> List[List[Tag]] fake_return_list_of_objects()
|
||||
|
||||
@@ -813,6 +1187,128 @@ No authorization required
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_return_str_like_json**
|
||||
> str fake_return_str_like_json()
|
||||
|
||||
test str like json
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```python
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
|
||||
try:
|
||||
# test str like json
|
||||
api_response = api_instance.fake_return_str_like_json()
|
||||
print("The response of FakeApi->fake_return_str_like_json:\n")
|
||||
pprint(api_response)
|
||||
except Exception as e:
|
||||
print("Exception when calling FakeApi->fake_return_str_like_json: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
**str**
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: plain/text
|
||||
|
||||
### HTTP response details
|
||||
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | OK | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_return_string**
|
||||
> str fake_return_string()
|
||||
|
||||
test returning string
|
||||
|
||||
### Example
|
||||
|
||||
|
||||
```python
|
||||
import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
|
||||
try:
|
||||
# test returning string
|
||||
api_response = api_instance.fake_return_string()
|
||||
print("The response of FakeApi->fake_return_string:\n")
|
||||
pprint(api_response)
|
||||
except Exception as e:
|
||||
print("Exception when calling FakeApi->fake_return_string: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
**str**
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/json
|
||||
|
||||
### HTTP response details
|
||||
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | OK | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **fake_uuid_example**
|
||||
> fake_uuid_example(uuid_example)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -312,7 +312,10 @@ class ApiClient:
|
||||
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
|
||||
encoding = match.group(1) if match else "utf-8"
|
||||
response_text = response_data.data.decode(encoding)
|
||||
return_data = self.deserialize(response_text, response_type)
|
||||
if response_type in ["bytearray", "str"]:
|
||||
return_data = self.__deserialize_primitive(response_text, response_type)
|
||||
else:
|
||||
return_data = self.deserialize(response_text, response_type)
|
||||
finally:
|
||||
if not 200 <= response_data.status <= 299:
|
||||
raise ApiException.from_response(
|
||||
|
||||
144
samples/openapi3/client/petstore/python/tests/test_fake_api.py
Normal file
144
samples/openapi3/client/petstore/python/tests/test_fake_api.py
Normal file
@@ -0,0 +1,144 @@
|
||||
# coding: utf-8
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
"""
|
||||
Run the tests.
|
||||
$ pip install -U pytest
|
||||
$ cd petstore_api-python
|
||||
$ pytest
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch, Mock
|
||||
import petstore_api
|
||||
|
||||
class TestFakeApi(unittest.TestCase):
|
||||
"""StrLikeJson unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
self.api_client = petstore_api.ApiClient()
|
||||
self.fake_api = petstore_api.FakeApi(self.api_client)
|
||||
|
||||
def testReturnString(self):
|
||||
"""Test ReturnString"""
|
||||
mock_resp = Mock()
|
||||
mock_resp.status = 200
|
||||
mock_resp.data = b'string'
|
||||
mock_resp.getheaders.return_value = {}
|
||||
mock_resp.getheader = (
|
||||
lambda name: "text/plain" if name == "content-type" else Mock()
|
||||
)
|
||||
with patch(
|
||||
"petstore_api.api_client.ApiClient.call_api", return_value=mock_resp
|
||||
):
|
||||
returned = self.fake_api.fake_return_string()
|
||||
self.assertEqual("string", returned)
|
||||
|
||||
def testReturnInt(self):
|
||||
"""Test ReturnInt"""
|
||||
mock_resp = Mock()
|
||||
mock_resp.status = 200
|
||||
mock_resp.data = b'1'
|
||||
mock_resp.getheaders.return_value = {}
|
||||
mock_resp.getheader = (
|
||||
lambda name: "text/plain" if name == "content-type" else Mock()
|
||||
)
|
||||
with patch(
|
||||
"petstore_api.api_client.ApiClient.call_api", return_value=mock_resp
|
||||
):
|
||||
returned = self.fake_api.fake_return_int()
|
||||
self.assertEqual(1, returned)
|
||||
|
||||
def testReturnFloat(self):
|
||||
"""Test ReturnFloat"""
|
||||
mock_resp = Mock()
|
||||
mock_resp.status = 200
|
||||
mock_resp.data = b'3.4'
|
||||
mock_resp.getheaders.return_value = {}
|
||||
mock_resp.getheader = (
|
||||
lambda name: "text/plain" if name == "content-type" else Mock()
|
||||
)
|
||||
with patch(
|
||||
"petstore_api.api_client.ApiClient.call_api", return_value=mock_resp
|
||||
):
|
||||
returned = self.fake_api.fake_return_float()
|
||||
self.assertEqual(3.4, returned)
|
||||
|
||||
def testReturnBoolean(self):
|
||||
"""Test ReturnBool"""
|
||||
mock_resp = Mock()
|
||||
mock_resp.status = 200
|
||||
mock_resp.data = b'true'
|
||||
mock_resp.getheaders.return_value = {}
|
||||
mock_resp.getheader = (
|
||||
lambda name: "text/plain" if name == "content-type" else Mock()
|
||||
)
|
||||
with patch(
|
||||
"petstore_api.api_client.ApiClient.call_api", return_value=mock_resp
|
||||
):
|
||||
returned = self.fake_api.fake_return_boolean()
|
||||
self.assertEqual(True, returned)
|
||||
|
||||
def testReturnEnum(self):
|
||||
"""Test ReturnEnum"""
|
||||
mock_resp = Mock()
|
||||
mock_resp.status = 200
|
||||
mock_resp.data = b'a'
|
||||
mock_resp.getheaders.return_value = {}
|
||||
mock_resp.getheader = (
|
||||
lambda name: "text/plain" if name == "content-type" else Mock()
|
||||
)
|
||||
with patch(
|
||||
"petstore_api.api_client.ApiClient.call_api", return_value=mock_resp
|
||||
):
|
||||
returned = self.fake_api.fake_return_enum()
|
||||
self.assertEqual("a", returned)
|
||||
|
||||
def testStrLikeJson(self):
|
||||
"""Test StrLikeJson"""
|
||||
mock_resp = Mock()
|
||||
mock_resp.status = 200
|
||||
mock_resp.data = b'{"a": "a"}'
|
||||
mock_resp.getheaders.return_value = {}
|
||||
mock_resp.getheader = (
|
||||
lambda name: "text/plain" if name == "content-type" else Mock()
|
||||
)
|
||||
with patch(
|
||||
"petstore_api.api_client.ApiClient.call_api", return_value=mock_resp
|
||||
):
|
||||
returned = self.fake_api.fake_return_str_like_json()
|
||||
self.assertEqual('{"a": "a"}', returned)
|
||||
|
||||
def testEnumLikeJson(self):
|
||||
"""Test EnumLikeJson"""
|
||||
mock_resp = Mock()
|
||||
mock_resp.status = 200
|
||||
mock_resp.data = b'{"a": "a"}'
|
||||
mock_resp.getheaders.return_value = {}
|
||||
mock_resp.getheader = (
|
||||
lambda name: "text/plain" if name == "content-type" else Mock()
|
||||
)
|
||||
with patch(
|
||||
"petstore_api.api_client.ApiClient.call_api", return_value=mock_resp
|
||||
):
|
||||
returned = self.fake_api.fake_return_enum_like_json()
|
||||
self.assertEqual('{"a": "a"}', returned)
|
||||
|
||||
def testByteLikeJson(self):
|
||||
"""Test ByteLikeJson"""
|
||||
mock_resp = Mock()
|
||||
mock_resp.status = 200
|
||||
mock_resp.data = b'{"a": "a"}'
|
||||
mock_resp.getheaders.return_value = {}
|
||||
mock_resp.getheader = (
|
||||
lambda name: "text/plain" if name == "content-type" else Mock()
|
||||
)
|
||||
with patch(
|
||||
"petstore_api.api_client.ApiClient.call_api", return_value=mock_resp
|
||||
):
|
||||
returned = self.fake_api.fake_return_byte_like_json()
|
||||
self.assertEqual(b'{"a": "a"}', returned)
|
||||
Reference in New Issue
Block a user