[python] Some cleanup of samples folder (#17127)

* Delete sample folders of discontinued clients

* Remove duplicate python-flask server sample

The python-flask sample actually lives in samples/server/petstore/python-flask.

* Move hand-written test to "tests" folder

Now, "test" only contains generated stubs and all hand-written tests are in "tests".

* Delete left-over files in Python samples

These are not created by the generators (anymore) and not hand-written
for testing.

* Regenerate test file to fix import error
This commit is contained in:
Robert Schweizer
2023-11-19 07:43:34 +01:00
committed by GitHub
parent 1da970b3b1
commit 75ff110449
71 changed files with 47 additions and 5403 deletions

View File

@@ -1,28 +0,0 @@
# List
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**var_123_list** | **str** | | [optional]
## Example
```python
from petstore_api.models.list import List
# TODO update the JSON string below
json = "{}"
# create an instance of List from a JSON string
list_instance = List.from_json(json)
# print the JSON string representation of the object
print List.to_json()
# convert the object into a dict
list_dict = list_instance.to_dict()
# create an instance of List from a dict
list_form_dict = list.from_dict(list_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -1,178 +0,0 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import re # noqa: F401
from petstore_api.api_client import ApiClient
from petstore_api.exceptions import ( # noqa: F401
ApiTypeError,
ApiValueError
)
class FakeClassnameTags123Api(object):
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
def __init__(self, api_client=None):
if api_client is None:
api_client = ApiClient()
self.api_client = api_client
def test_classname(self, client, **kwargs): # noqa: E501
"""To test class name in snake case # noqa: E501
To test class name in snake case # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.test_classname(client, async_req=True)
>>> result = thread.get()
:param client: client model (required)
:type client: Client
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _preload_content: if False, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Default is True.
:type _preload_content: bool, optional
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: Client
"""
kwargs['_return_http_data_only'] = True
return self.test_classname_with_http_info(client, **kwargs) # noqa: E501
def test_classname_with_http_info(self, client, **kwargs): # noqa: E501
"""To test class name in snake case # noqa: E501
To test class name in snake case # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.test_classname_with_http_info(client, async_req=True)
>>> result = thread.get()
:param client: client model (required)
:type client: Client
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _return_http_data_only: response data without head status code
and headers
:type _return_http_data_only: bool, optional
:param _preload_content: if False, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Default is True.
:type _preload_content: bool, optional
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_auth: dict, optional
:type _content_type: string, optional: force content-type for the request
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: tuple(Client, status_code(int), headers(HTTPHeaderDict))
"""
local_var_params = locals()
all_params = [
'client'
]
all_params.extend(
[
'async_req',
'_return_http_data_only',
'_preload_content',
'_request_timeout',
'_request_auth',
'_content_type',
'_headers'
]
)
for key, val in local_var_params['kwargs'].items():
if key not in all_params:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
" to method test_classname" % key
)
local_var_params[key] = val
del local_var_params['kwargs']
# verify the required parameter 'client' is set
if self.api_client.client_side_validation and ('client' not in local_var_params or # noqa: E501
local_var_params['client'] is None): # noqa: E501
raise ApiValueError("Missing the required parameter `client` when calling `test_classname`") # noqa: E501
collection_formats = {}
path_params = {}
query_params = []
header_params = dict(local_var_params.get('_headers', {}))
form_params = []
local_var_files = {}
body_params = None
if 'client' in local_var_params:
body_params = local_var_params['client']
# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json']) # noqa: E501
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PATCH', body_params)) # noqa: E501
# Authentication setting
auth_settings = ['api_key_query'] # noqa: E501
response_types_map = {
200: "Client",
}
return self.api_client.call_api(
'/fake_classname_test', 'PATCH',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_types_map=response_types_map,
auth_settings=auth_settings,
async_req=local_var_params.get('async_req'),
_return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501
_preload_content=local_var_params.get('_preload_content', True),
_request_timeout=local_var_params.get('_request_timeout'),
collection_formats=collection_formats,
_request_auth=local_var_params.get('_request_auth'))

View File

@@ -1,83 +0,0 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from typing import Any, Dict, Optional
from pydantic import BaseModel, Field, StrictStr
class List(BaseModel):
"""
List
"""
var_123_list: Optional[StrictStr] = Field(None, alias="123-list")
additional_properties: Dict[str, Any] = {}
__properties = ["123-list"]
class Config:
"""Pydantic configuration"""
allow_population_by_field_name = True
validate_assignment = True
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.dict(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> List:
"""Create an instance of List from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self):
"""Returns the dictionary representation of the model using alias"""
_dict = self.dict(by_alias=True,
exclude={
"additional_properties"
},
exclude_none=True)
# puts key-value pairs in additional_properties in the top level
if self.additional_properties is not None:
for _key, _value in self.additional_properties.items():
_dict[_key] = _value
return _dict
@classmethod
def from_dict(cls, obj: dict) -> List:
"""Create an instance of List from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return List.parse_obj(obj)
_obj = List.parse_obj({
"var_123_list": obj.get("123-list")
})
# store additional fields in additional_properties
for _key in obj.keys():
if _key not in cls.__properties:
_obj.additional_properties[_key] = obj.get(_key)
return _obj

View File

@@ -1,54 +0,0 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
OpenAPI spec version: 1.0.0
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import petstore_api
from petstore_api import Configuration # noqa: E501
from petstore_api.rest import ApiException
class TestConfiguration(unittest.TestCase):
"""Configuration unit test stubs"""
def setUp(self):
self.config= Configuration()
def tearDown(self):
pass
def test_configuration(self):
"""Test configuration
Test host settings # noqa: E501
"""
host_settings = self.config.get_host_settings()
self.assertEqual('http://{server}.swagger.io:{port}/v2', host_settings[0]['url'])
self.assertEqual('petstore', host_settings[0]['variables']['server']['default_value'])
self.assertEqual('https://localhost:8080/{version}', host_settings[1]['url'])
self.assertEqual('v2', host_settings[1]['variables']['version']['default_value'])
def test_get_host_from_settings(self):
""" Test get_host_from_settings
Test get URL from host settings
"""
self.assertEqual("http://petstore.swagger.io:80/v2", self.config.get_host_from_settings(0))
self.assertEqual("http://petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'port': '8080'}))
self.assertEqual("http://dev-petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'server': 'dev-petstore', 'port': '8080'}))
if __name__ == '__main__':
unittest.main()

View File

@@ -3,32 +3,30 @@
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import absolute_import
import unittest
import petstore_api
from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api # noqa: E501
from petstore_api.rest import ApiException
from petstore_api.api.fake_classname_tags123_api import FakeClassnameTags123Api # noqa: E501
class TestFakeClassnameTags123Api(unittest.TestCase):
"""FakeClassnameTags123Api unit test stubs"""
def setUp(self):
self.api = petstore_api.api.fake_classname_tags_123_api.FakeClassnameTags123Api() # noqa: E501
def setUp(self) -> None:
self.api = FakeClassnameTags123Api() # noqa: E501
def tearDown(self):
def tearDown(self) -> None:
pass
def test_test_classname(self):
def test_test_classname(self) -> None:
"""Test case for test_classname
To test class name in snake case # noqa: E501

View File

@@ -1,40 +0,0 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import petstore_api
from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api # noqa: E501
from petstore_api.rest import ApiException
class TestFakeClassnameTags123Api(unittest.TestCase):
"""FakeClassnameTags123Api unit test stubs"""
def setUp(self):
self.api = petstore_api.api.fake_classname_tags_123_api.FakeClassnameTags123Api() # noqa: E501
def tearDown(self):
pass
def test_test_classname(self):
"""Test case for test_classname
To test class name in snake case # noqa: E501
"""
pass
if __name__ == '__main__':
unittest.main()

View File

@@ -1,51 +0,0 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import datetime
import petstore_api
from petstore_api.models.list import List # noqa: E501
from petstore_api.rest import ApiException
class TestList(unittest.TestCase):
"""List unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test List
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# model = petstore_api.models.list.List() # noqa: E501
if include_optional :
return List(
_123_list = ''
)
else :
return List(
)
def testList(self):
"""Test List"""
inst_req_only = self.make_instance(include_optional=False)
inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@@ -19,7 +19,7 @@ class TestConfiguration(unittest.TestCase):
"""Animal unit test stubs"""
def setUp(self):
pass
self.config = petstore_api.Configuration()
def tearDown(self):
# reset Configuration
@@ -57,6 +57,24 @@ class TestConfiguration(unittest.TestCase):
def testAccessTokenWhenConstructingConfiguration(self):
c1 = petstore_api.Configuration(access_token="12345")
self.assertEqual(c1.access_token, "12345")
def test_get_host_settings(self):
host_settings = self.config.get_host_settings()
self.assertEqual('http://{server}.swagger.io:{port}/v2', host_settings[0]['url'])
self.assertEqual('petstore', host_settings[0]['variables']['server']['default_value'])
self.assertEqual('https://localhost:8080/{version}', host_settings[1]['url'])
self.assertEqual('v2', host_settings[1]['variables']['version']['default_value'])
def test_get_host_from_settings(self):
""" Test get_host_from_settings
Test get URL from host settings
"""
self.assertEqual("http://petstore.swagger.io:80/v2", self.config.get_host_from_settings(0))
self.assertEqual("http://petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'port': '8080'}))
self.assertEqual("http://dev-petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'server': 'dev-petstore', 'port': '8080'}))
if __name__ == '__main__':
unittest.main()