[python] fixes bugs (#13581)

* Adds bug fixes

* Samples and docs regenerated

* Samples regenerated
This commit is contained in:
Justin Black
2022-10-03 11:15:16 -07:00
committed by GitHub
parent 2f48c596d1
commit 57f5cc4000
270 changed files with 6730 additions and 96 deletions

View File

@@ -55,10 +55,11 @@ class ApiTestMixin(unittest.TestCase):
content_type: typing.Optional[str] = 'application/json',
accept_content_type: typing.Optional[str] = 'application/json',
stream: bool = False,
headers: typing.Optional[typing.Dict] = None
):
headers = {
'User-Agent': cls.user_agent
}
if headers is None:
headers = {}
headers['User-Agent'] = cls.user_agent
if accept_content_type:
headers['Accept'] = accept_content_type
if content_type:

View File

@@ -0,0 +1,77 @@
# 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
"""
import unittest
import petstore_api
from petstore_api.model.object_with_invalid_named_refed_properties import ObjectWithInvalidNamedRefedProperties
from petstore_api.model.array_with_validations_in_items import ArrayWithValidationsInItems
from petstore_api.model.from_schema import FromSchema
class TestObjectWithInvalidNamedRefedProperties(unittest.TestCase):
"""ObjectWithInvalidNamedRefedProperties unit test stubs"""
def test_instantiation_success(self):
array_value = ArrayWithValidationsInItems(
[4, 5]
)
from_value = FromSchema(data='abc', id=1)
kwargs = {
'from': from_value,
'!reference': array_value
}
# __new__ creation works
inst = ObjectWithInvalidNamedRefedProperties(
**kwargs
)
primitive_data = {
'from': {'data': 'abc', 'id': 1},
'!reference': (4, 5)
}
assert inst == primitive_data
# from_openapi_data_oapg works
inst = ObjectWithInvalidNamedRefedProperties.from_openapi_data_oapg(primitive_data)
assert inst == primitive_data
def test_omitting_required_properties_fails(self):
array_value = ArrayWithValidationsInItems(
[4, 5]
)
from_value = FromSchema(data='abc', id=1)
with self.assertRaises(petstore_api.exceptions.ApiTypeError):
ObjectWithInvalidNamedRefedProperties(
**{
'from': from_value,
}
)
with self.assertRaises(petstore_api.exceptions.ApiTypeError):
ObjectWithInvalidNamedRefedProperties(
**{
'!reference': array_value
}
)
with self.assertRaises(petstore_api.exceptions.ApiTypeError):
ObjectWithInvalidNamedRefedProperties.from_openapi_data_oapg(
{
'from': {'data': 'abc', 'id': 1},
}
)
with self.assertRaises(petstore_api.exceptions.ApiTypeError):
ObjectWithInvalidNamedRefedProperties.from_openapi_data_oapg(
{
'!reference': [4, 5]
}
)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,75 @@
# coding: utf-8
"""
Generated by: https://openapi-generator.tech
"""
import json
import unittest
from unittest.mock import patch
import urllib3
from petstore_api.paths.pet_pet_id import get # noqa: E501
from petstore_api import configuration, schemas, api_client
from petstore_api.model.pet import Pet
from ... import ApiTestMixin
class TestPetPetId(ApiTestMixin, unittest.TestCase):
"""
PetPetId unit test stubs
Find pet by ID # noqa: E501
"""
def test_get(self):
config_with_auth = configuration.Configuration(api_key={'api_key': 'someKey'})
used_api_client = api_client.ApiClient(configuration=config_with_auth)
api = get.ApiForget(api_client=used_api_client) # noqa: E501
with patch.object(urllib3.PoolManager, 'request') as mock_request:
response_json = {
'photoUrls': [],
'name': 'Kitty',
'id': 1,
'category': {
'name': 'Cat',
'id': 1
},
'tags': [],
'status': 'available'
}
body = self.json_bytes(response_json)
mock_request.return_value = self.response(body)
api_response = api.get(path_params={'petId': 1})
self.assert_pool_manager_request_called_with(
mock_request,
'http://petstore.swagger.io:80/v2/pet/1',
body=None,
method='GET',
content_type=None,
accept_content_type='application/xml, application/json',
headers={'api_key': 'someKey'}
)
assert isinstance(api_response.response, urllib3.HTTPResponse)
assert isinstance(api_response.body, Pet)
assert isinstance(api_response.headers, schemas.Unset)
assert api_response.response.status == 200
response_status = 200
if __name__ == '__main__':
unittest.main()