forked from loafle/openapi-generator-original
updated ApiClient of python sdk.
When create api instance, if we don't pass the `api_client` parameter, then use the default api_client in `config` module.
This commit is contained in:
@@ -13,6 +13,7 @@ import unittest
|
||||
|
||||
import SwaggerPetstore
|
||||
from SwaggerPetstore.rest import ErrorResponse
|
||||
from SwaggerPetstore import config
|
||||
|
||||
HOST = 'http://petstore.swagger.io/v2'
|
||||
|
||||
@@ -49,6 +50,26 @@ class PetApiTests(unittest.TestCase):
|
||||
self.test_file_dir = os.path.realpath(self.test_file_dir)
|
||||
self.foo = os.path.join(self.test_file_dir, "foo.png")
|
||||
|
||||
def test_create_api_instance(self):
|
||||
pet_api = SwaggerPetstore.PetApi()
|
||||
pet_api2 = SwaggerPetstore.PetApi()
|
||||
api_client3 = SwaggerPetstore.ApiClient()
|
||||
api_client3.user_agent = 'api client 3'
|
||||
api_client4 = SwaggerPetstore.ApiClient()
|
||||
api_client4.user_agent = 'api client 4'
|
||||
pet_api3 = SwaggerPetstore.PetApi(api_client3)
|
||||
|
||||
# same default api client
|
||||
self.assertEqual(pet_api.api_client, pet_api2.api_client)
|
||||
# confirm using the default api client in the config module
|
||||
self.assertEqual(pet_api.api_client, config.api_client)
|
||||
# 2 different api clients are not the same
|
||||
self.assertNotEqual(api_client3, api_client4)
|
||||
# customized pet api not using the default api client
|
||||
self.assertNotEqual(pet_api3.api_client, config.api_client)
|
||||
# customized pet api not using the old pet api's api client
|
||||
self.assertNotEqual(pet_api3.api_client, pet_api2.api_client)
|
||||
|
||||
def test_add_pet_and_get_pet_by_id(self):
|
||||
self.pet_api.add_pet(body=self.pet)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user