mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-18 23:17:04 +00:00
python: test with more modern versions (#19452)
Python 3.12 has been released in October 2023, it should be tested in the CI. Python 3.7 is not maintained anymore, removing it from the minimum required version in `pyproject.toml` files.
This commit is contained in:
@@ -5,16 +5,12 @@
|
||||
import unittest
|
||||
import weakref
|
||||
|
||||
from tests.util import async_test
|
||||
import petstore_api
|
||||
|
||||
HOST = 'http://localhost/v2'
|
||||
|
||||
class TestApiClient(unittest.TestCase):
|
||||
|
||||
@async_test
|
||||
class TestApiClient(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_context_manager_closes_client(self):
|
||||
|
||||
async with petstore_api.ApiClient() as client:
|
||||
# pool_manager
|
||||
self.assertFalse(client.rest_client.pool_manager.closed)
|
||||
@@ -22,30 +18,29 @@ class TestApiClient(unittest.TestCase):
|
||||
|
||||
self.assertTrue(rest_pool_ref.closed)
|
||||
|
||||
@async_test
|
||||
async def test_ignore_operation_servers(self):
|
||||
config = petstore_api.Configuration(host=HOST)
|
||||
client = petstore_api.ApiClient(config)
|
||||
user_api_instance = petstore_api.api.user_api.UserApi(client)
|
||||
async with petstore_api.ApiClient(config) as client:
|
||||
user_api_instance = petstore_api.api.user_api.UserApi(client)
|
||||
|
||||
config_ignore = petstore_api.Configuration(host=HOST, ignore_operation_servers=True)
|
||||
client_ignore = petstore_api.ApiClient(config_ignore)
|
||||
user_api_instance_ignore = petstore_api.api.user_api.UserApi(client_ignore)
|
||||
config_ignore = petstore_api.Configuration(host=HOST, ignore_operation_servers=True)
|
||||
client_ignore = petstore_api.ApiClient(config_ignore)
|
||||
user_api_instance_ignore = petstore_api.api.user_api.UserApi(client_ignore)
|
||||
|
||||
params_to_serialize = {
|
||||
'user': petstore_api.User(id=1, username='test'),
|
||||
'_request_auth': None,
|
||||
'_content_type': 'application/json',
|
||||
'_headers': None,
|
||||
'_host_index': 0
|
||||
}
|
||||
params_to_serialize = {
|
||||
'user': petstore_api.User(id=1, username='test'),
|
||||
'_request_auth': None,
|
||||
'_content_type': 'application/json',
|
||||
'_headers': None,
|
||||
'_host_index': 0
|
||||
}
|
||||
|
||||
# operation servers should be used
|
||||
_, url, *_ = user_api_instance._create_user_serialize(**params_to_serialize)
|
||||
self.assertEqual(client.configuration.host, HOST)
|
||||
self.assertEqual(url, 'http://petstore.swagger.io/v2/user')
|
||||
# operation servers should be used
|
||||
_, url, *_ = user_api_instance._create_user_serialize(**params_to_serialize)
|
||||
self.assertEqual(client.configuration.host, HOST)
|
||||
self.assertEqual(url, 'http://petstore.swagger.io/v2/user')
|
||||
|
||||
# operation servers should be ignored
|
||||
_, url_ignore, *_ = user_api_instance_ignore._create_user_serialize(**params_to_serialize)
|
||||
self.assertEqual(client.configuration.host, HOST)
|
||||
self.assertEqual(url_ignore, HOST + '/user')
|
||||
# operation servers should be ignored
|
||||
_, url_ignore, *_ = user_api_instance_ignore._create_user_serialize(**params_to_serialize)
|
||||
self.assertEqual(client.configuration.host, HOST)
|
||||
self.assertEqual(url_ignore, HOST + '/user')
|
||||
|
||||
@@ -20,7 +20,7 @@ import petstore_api
|
||||
from petstore_api import Configuration
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
from .util import id_gen, async_test
|
||||
from .util import id_gen
|
||||
|
||||
import json
|
||||
|
||||
@@ -29,9 +29,8 @@ import urllib3
|
||||
HOST = 'http://localhost:80/v2'
|
||||
|
||||
|
||||
class TestPetApiTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
class TestPetApiTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def asyncSetUp(self):
|
||||
config = Configuration()
|
||||
config.host = HOST
|
||||
|
||||
@@ -40,6 +39,9 @@ class TestPetApiTests(unittest.TestCase):
|
||||
self.setUpModels()
|
||||
self.setUpFiles()
|
||||
|
||||
async def asyncTearDown(self):
|
||||
await self.api_client.close()
|
||||
|
||||
def setUpModels(self):
|
||||
self.category = petstore_api.Category(id=id_gen(), name="dog")
|
||||
#self.category.id = id_gen()
|
||||
@@ -88,7 +90,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
pet_api2 = petstore_api.PetApi()
|
||||
self.assertEqual(id(pet_api.api_client.configuration), id(pet_api2.api_client.configuration))
|
||||
|
||||
@async_test
|
||||
async def test_async_with_result(self):
|
||||
await self.pet_api.add_pet(self.pet)
|
||||
assert self.pet.id is not None
|
||||
@@ -106,7 +107,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
self.assertEqual(response.id, self.pet.id)
|
||||
self.assertEqual(len(responses), 2)
|
||||
|
||||
@async_test
|
||||
async def test_exception(self):
|
||||
await self.pet_api.add_pet(self.pet)
|
||||
|
||||
@@ -118,7 +118,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
self.assertIsInstance(exception, ApiException)
|
||||
self.assertEqual(exception.status, 404)
|
||||
|
||||
@async_test
|
||||
async def test_add_pet_and_get_pet_by_id(self):
|
||||
await self.pet_api.add_pet(self.pet)
|
||||
assert self.pet.id is not None
|
||||
@@ -129,7 +128,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
assert fetched.category is not None
|
||||
self.assertEqual(self.pet.category.name, fetched.category.name)
|
||||
|
||||
@async_test
|
||||
async def test_add_pet_and_get_pet_by_id_with_http_info(self):
|
||||
await self.pet_api.add_pet(self.pet)
|
||||
assert self.pet.id is not None
|
||||
@@ -140,7 +138,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
assert fetched.data.category is not None
|
||||
self.assertEqual(self.pet.category.name, fetched.data.category.name)
|
||||
|
||||
@async_test
|
||||
async def test_add_pet_and_get_pet_by_id_without_preload_content(self):
|
||||
await self.pet_api.add_pet(self.pet)
|
||||
assert self.pet.id is not None
|
||||
@@ -154,7 +151,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
self.assertEqual(await fetched.content.read(), b'')
|
||||
self.assertTrue(read.decode("utf-8").startswith('{"id":'))
|
||||
|
||||
@async_test
|
||||
async def test_update_pet(self):
|
||||
self.pet.name = "hello kity with updated"
|
||||
await self.pet_api.update_pet(self.pet)
|
||||
@@ -167,7 +163,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
assert fetched.category is not None
|
||||
self.assertEqual(fetched.category.name, self.pet.category.name)
|
||||
|
||||
@async_test
|
||||
async def test_find_pets_by_status(self):
|
||||
await self.pet_api.add_pet(self.pet)
|
||||
assert self.pet.status is not None
|
||||
@@ -177,7 +172,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
list(map(lambda x: getattr(x, 'id'), pets))
|
||||
)
|
||||
|
||||
@async_test
|
||||
async def test_find_pets_by_tags(self):
|
||||
await self.pet_api.add_pet(self.pet)
|
||||
assert self.tag.name is not None
|
||||
@@ -187,7 +181,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
list(map(lambda x: getattr(x, 'id'), pets))
|
||||
)
|
||||
|
||||
@async_test
|
||||
async def test_update_pet_with_form(self):
|
||||
await self.pet_api.add_pet(self.pet)
|
||||
assert self.pet.id is not None
|
||||
@@ -201,7 +194,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
self.assertEqual(name, fetched.name)
|
||||
self.assertEqual(status, fetched.status)
|
||||
|
||||
@async_test
|
||||
async def test_upload_file(self):
|
||||
# upload file with form parameter
|
||||
try:
|
||||
@@ -221,7 +213,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
except ApiException as e:
|
||||
self.fail("upload_file() raised {0} unexpectedly".format(type(e)))
|
||||
|
||||
@async_test
|
||||
async def test_delete_pet(self):
|
||||
await self.pet_api.add_pet(self.pet)
|
||||
assert self.pet.id is not None
|
||||
@@ -233,7 +224,6 @@ class TestPetApiTests(unittest.TestCase):
|
||||
except ApiException as e:
|
||||
self.assertEqual(404, e.status)
|
||||
|
||||
@async_test
|
||||
async def test_proxy(self):
|
||||
config = Configuration()
|
||||
# set not-existent proxy and catch an error to verify that
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
# flake8: noqa
|
||||
|
||||
import asyncio
|
||||
import random
|
||||
|
||||
|
||||
def id_gen(bits=32):
|
||||
""" Returns a n-bit randomly generated int """
|
||||
return int(random.getrandbits(bits))
|
||||
|
||||
|
||||
def async_test(f):
|
||||
def wrapper(*args, **kwargs):
|
||||
# coro = asyncio.coroutine(f)
|
||||
coro = f
|
||||
future = coro(*args, **kwargs)
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(future)
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user