From f7060951c561683fbab2a55b4ed27852649f3f3a Mon Sep 17 00:00:00 2001 From: ruslanlazin Date: Mon, 28 Jan 2019 11:25:58 +0200 Subject: [PATCH 1/6] add assertions to separate config instances test --- samples/client/petstore/python/tests/test_pet_api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index aae22b4d438..b0d485465c3 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -137,10 +137,18 @@ def test_separate_default_config_instances(self): pet_api2 = petstore_api.PetApi() self.assertNotEqual(pet_api.api_client.configuration, pet_api2.api_client.configuration) - pet_api.api_client.configuration.host = 'somehost' - pet_api2.api_client.configuration.host = 'someotherhost' + pet_api.api_client.configuration.host = 'some_host' + pet_api2.api_client.configuration.host = 'some_other_host' self.assertNotEqual(pet_api.api_client.configuration.host, pet_api2.api_client.configuration.host) + pet_api.api_client.configuration.api_key['api_key'] = 'some_key' + pet_api2.api_client.configuration.api_key['api_key'] = 'some_other_key' + self.assertNotEqual(pet_api.api_client.configuration.api_key['api_key'], pet_api2.api_client.configuration.api_key['api_key']) + + pet_api.api_client.configuration.api_key_prefix['prefix'] = 'some_prefix' + pet_api2.api_client.configuration.api_key_prefix['prefix'] = 'some_other_prefix' + self.assertNotEqual(pet_api.api_client.configuration.api_key_prefix['prefix'], pet_api2.api_client.configuration.api_key_prefix['prefix']) + def test_async_request(self): thread = self.pet_api.add_pet(body=self.pet, async_req=True) response = thread.get() From d94139a0ade35ae254ff82f6f24d2c5fe493853b Mon Sep 17 00:00:00 2001 From: ruslanlazin Date: Mon, 28 Jan 2019 20:55:00 +0200 Subject: [PATCH 2/6] fix issue 9117 --- .../src/main/resources/python/configuration.mustache | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/configuration.mustache b/modules/swagger-codegen/src/main/resources/python/configuration.mustache index 84e6ad4d208..8cb0e61c896 100644 --- a/modules/swagger-codegen/src/main/resources/python/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/python/configuration.mustache @@ -22,10 +22,16 @@ class TypeWithDefault(type): def __call__(cls): if cls._default is None: cls._default = type.__call__(cls) - return copy.copy(cls._default) + return cls._two_level_copy(cls._default) def set_default(cls, default): - cls._default = copy.copy(default) + cls._default = cls._two_level_copy(default) + + def _two_level_copy(cls, obj): + newone = copy.copy(obj) + for key in obj.__dict__.keys(): + newone.__dict__[key] = copy.copy(obj.__dict__[key]) + return newone class Configuration(six.with_metaclass(TypeWithDefault, object)): From f9b6755a7fd5a686a49247e2f5aa4fa11afe4f7b Mon Sep 17 00:00:00 2001 From: ruslanlazin Date: Mon, 28 Jan 2019 21:57:28 +0200 Subject: [PATCH 3/6] regenerate petstore --- .../python/petstore_api/configuration.py | 10 ++++++++-- .../python-asyncio/petstore_api/configuration.py | 10 ++++++++-- .../python-tornado/petstore_api/configuration.py | 10 ++++++++-- .../petstore/python/petstore_api/configuration.py | 10 ++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/samples/client/petstore-security-test/python/petstore_api/configuration.py b/samples/client/petstore-security-test/python/petstore_api/configuration.py index c5a442ee576..e3827af20f6 100644 --- a/samples/client/petstore-security-test/python/petstore_api/configuration.py +++ b/samples/client/petstore-security-test/python/petstore_api/configuration.py @@ -31,10 +31,16 @@ def __init__(cls, name, bases, dct): def __call__(cls): if cls._default is None: cls._default = type.__call__(cls) - return copy.copy(cls._default) + return cls._two_level_copy(cls._default) def set_default(cls, default): - cls._default = copy.copy(default) + cls._default = cls._two_level_copy(default) + + def _two_level_copy(cls, obj): + newone = copy.copy(obj) + for key in obj.__dict__.keys(): + newone.__dict__[key] = copy.copy(obj.__dict__[key]) + return newone class Configuration(six.with_metaclass(TypeWithDefault, object)): diff --git a/samples/client/petstore/python-asyncio/petstore_api/configuration.py b/samples/client/petstore/python-asyncio/petstore_api/configuration.py index f6273cf28cc..0b0e2ed6dbe 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/configuration.py +++ b/samples/client/petstore/python-asyncio/petstore_api/configuration.py @@ -31,10 +31,16 @@ def __init__(cls, name, bases, dct): def __call__(cls): if cls._default is None: cls._default = type.__call__(cls) - return copy.copy(cls._default) + return cls._two_level_copy(cls._default) def set_default(cls, default): - cls._default = copy.copy(default) + cls._default = cls._two_level_copy(default) + + def _two_level_copy(cls, obj): + newone = copy.copy(obj) + for key in obj.__dict__.keys(): + newone.__dict__[key] = copy.copy(obj.__dict__[key]) + return newone class Configuration(six.with_metaclass(TypeWithDefault, object)): diff --git a/samples/client/petstore/python-tornado/petstore_api/configuration.py b/samples/client/petstore/python-tornado/petstore_api/configuration.py index f6273cf28cc..0b0e2ed6dbe 100644 --- a/samples/client/petstore/python-tornado/petstore_api/configuration.py +++ b/samples/client/petstore/python-tornado/petstore_api/configuration.py @@ -31,10 +31,16 @@ def __init__(cls, name, bases, dct): def __call__(cls): if cls._default is None: cls._default = type.__call__(cls) - return copy.copy(cls._default) + return cls._two_level_copy(cls._default) def set_default(cls, default): - cls._default = copy.copy(default) + cls._default = cls._two_level_copy(default) + + def _two_level_copy(cls, obj): + newone = copy.copy(obj) + for key in obj.__dict__.keys(): + newone.__dict__[key] = copy.copy(obj.__dict__[key]) + return newone class Configuration(six.with_metaclass(TypeWithDefault, object)): diff --git a/samples/client/petstore/python/petstore_api/configuration.py b/samples/client/petstore/python/petstore_api/configuration.py index f6273cf28cc..0b0e2ed6dbe 100644 --- a/samples/client/petstore/python/petstore_api/configuration.py +++ b/samples/client/petstore/python/petstore_api/configuration.py @@ -31,10 +31,16 @@ def __init__(cls, name, bases, dct): def __call__(cls): if cls._default is None: cls._default = type.__call__(cls) - return copy.copy(cls._default) + return cls._two_level_copy(cls._default) def set_default(cls, default): - cls._default = copy.copy(default) + cls._default = cls._two_level_copy(default) + + def _two_level_copy(cls, obj): + newone = copy.copy(obj) + for key in obj.__dict__.keys(): + newone.__dict__[key] = copy.copy(obj.__dict__[key]) + return newone class Configuration(six.with_metaclass(TypeWithDefault, object)): From 0988b1e9aa4009eac4372127c008efd1beb67641 Mon Sep 17 00:00:00 2001 From: ruslanlazin Date: Tue, 5 Feb 2019 07:28:35 +0200 Subject: [PATCH 4/6] refactor configuration.py --- .../resources/python/configuration.mustache | 33 +++++++------------ .../python/petstore_api/configuration.py | 33 +++++++------------ .../petstore_api/configuration.py | 33 +++++++------------ .../petstore_api/configuration.py | 33 +++++++------------ .../python/petstore_api/configuration.py | 33 +++++++------------ 5 files changed, 60 insertions(+), 105 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/configuration.mustache b/modules/swagger-codegen/src/main/resources/python/configuration.mustache index 8cb0e61c896..bb85b8f3902 100644 --- a/modules/swagger-codegen/src/main/resources/python/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/python/configuration.mustache @@ -14,35 +14,22 @@ import six from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls): - if cls._default is None: - cls._default = type.__call__(cls) - return cls._two_level_copy(cls._default) - - def set_default(cls, default): - cls._default = cls._two_level_copy(default) - - def _two_level_copy(cls, obj): - newone = copy.copy(obj) - for key in obj.__dict__.keys(): - newone.__dict__[key] = copy.copy(obj.__dict__[key]) - return newone - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen Do not edit the class manually. """ + _default = None + def __init__(self): """Constructor""" + if self._default: + for key in self._default.__dict__.keys(): + self.__dict__[key] = copy.copy(self._default.__dict__[key]) + return + # Default Base url self.host = "{{{basePath}}}" # Temp file folder for downloading files @@ -101,6 +88,10 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): # Safe chars for path_param self.safe_chars_for_path_param = '' + @classmethod + def set_default(cls, default): + cls._default = default + @property def logger_file(self): """The logger file. diff --git a/samples/client/petstore-security-test/python/petstore_api/configuration.py b/samples/client/petstore-security-test/python/petstore_api/configuration.py index e3827af20f6..13adc41a387 100644 --- a/samples/client/petstore-security-test/python/petstore_api/configuration.py +++ b/samples/client/petstore-security-test/python/petstore_api/configuration.py @@ -23,35 +23,22 @@ from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls): - if cls._default is None: - cls._default = type.__call__(cls) - return cls._two_level_copy(cls._default) - - def set_default(cls, default): - cls._default = cls._two_level_copy(default) - - def _two_level_copy(cls, obj): - newone = copy.copy(obj) - for key in obj.__dict__.keys(): - newone.__dict__[key] = copy.copy(obj.__dict__[key]) - return newone - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen Do not edit the class manually. """ + _default = None + def __init__(self): """Constructor""" + if self._default: + for key in self._default.__dict__.keys(): + self.__dict__[key] = copy.copy(self._default.__dict__[key]) + return + # Default Base url self.host = "https://petstore.swagger.io */ ' \" =end -- \\r\\n \\n \\r/v2 */ ' \" =end -- \\r\\n \\n \\r" # Temp file folder for downloading files @@ -110,6 +97,10 @@ def __init__(self): # Safe chars for path_param self.safe_chars_for_path_param = '' + @classmethod + def set_default(cls, default): + cls._default = default + @property def logger_file(self): """The logger file. diff --git a/samples/client/petstore/python-asyncio/petstore_api/configuration.py b/samples/client/petstore/python-asyncio/petstore_api/configuration.py index 0b0e2ed6dbe..2734d66b44b 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/configuration.py +++ b/samples/client/petstore/python-asyncio/petstore_api/configuration.py @@ -23,35 +23,22 @@ from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls): - if cls._default is None: - cls._default = type.__call__(cls) - return cls._two_level_copy(cls._default) - - def set_default(cls, default): - cls._default = cls._two_level_copy(default) - - def _two_level_copy(cls, obj): - newone = copy.copy(obj) - for key in obj.__dict__.keys(): - newone.__dict__[key] = copy.copy(obj.__dict__[key]) - return newone - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen Do not edit the class manually. """ + _default = None + def __init__(self): """Constructor""" + if self._default: + for key in self._default.__dict__.keys(): + self.__dict__[key] = copy.copy(self._default.__dict__[key]) + return + # Default Base url self.host = "http://petstore.swagger.io:80/v2" # Temp file folder for downloading files @@ -110,6 +97,10 @@ def __init__(self): # Safe chars for path_param self.safe_chars_for_path_param = '' + @classmethod + def set_default(cls, default): + cls._default = default + @property def logger_file(self): """The logger file. diff --git a/samples/client/petstore/python-tornado/petstore_api/configuration.py b/samples/client/petstore/python-tornado/petstore_api/configuration.py index 0b0e2ed6dbe..2734d66b44b 100644 --- a/samples/client/petstore/python-tornado/petstore_api/configuration.py +++ b/samples/client/petstore/python-tornado/petstore_api/configuration.py @@ -23,35 +23,22 @@ from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls): - if cls._default is None: - cls._default = type.__call__(cls) - return cls._two_level_copy(cls._default) - - def set_default(cls, default): - cls._default = cls._two_level_copy(default) - - def _two_level_copy(cls, obj): - newone = copy.copy(obj) - for key in obj.__dict__.keys(): - newone.__dict__[key] = copy.copy(obj.__dict__[key]) - return newone - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen Do not edit the class manually. """ + _default = None + def __init__(self): """Constructor""" + if self._default: + for key in self._default.__dict__.keys(): + self.__dict__[key] = copy.copy(self._default.__dict__[key]) + return + # Default Base url self.host = "http://petstore.swagger.io:80/v2" # Temp file folder for downloading files @@ -110,6 +97,10 @@ def __init__(self): # Safe chars for path_param self.safe_chars_for_path_param = '' + @classmethod + def set_default(cls, default): + cls._default = default + @property def logger_file(self): """The logger file. diff --git a/samples/client/petstore/python/petstore_api/configuration.py b/samples/client/petstore/python/petstore_api/configuration.py index 0b0e2ed6dbe..2734d66b44b 100644 --- a/samples/client/petstore/python/petstore_api/configuration.py +++ b/samples/client/petstore/python/petstore_api/configuration.py @@ -23,35 +23,22 @@ from six.moves import http_client as httplib -class TypeWithDefault(type): - def __init__(cls, name, bases, dct): - super(TypeWithDefault, cls).__init__(name, bases, dct) - cls._default = None - - def __call__(cls): - if cls._default is None: - cls._default = type.__call__(cls) - return cls._two_level_copy(cls._default) - - def set_default(cls, default): - cls._default = cls._two_level_copy(default) - - def _two_level_copy(cls, obj): - newone = copy.copy(obj) - for key in obj.__dict__.keys(): - newone.__dict__[key] = copy.copy(obj.__dict__[key]) - return newone - - -class Configuration(six.with_metaclass(TypeWithDefault, object)): +class Configuration(object): """NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen Do not edit the class manually. """ + _default = None + def __init__(self): """Constructor""" + if self._default: + for key in self._default.__dict__.keys(): + self.__dict__[key] = copy.copy(self._default.__dict__[key]) + return + # Default Base url self.host = "http://petstore.swagger.io:80/v2" # Temp file folder for downloading files @@ -110,6 +97,10 @@ def __init__(self): # Safe chars for path_param self.safe_chars_for_path_param = '' + @classmethod + def set_default(cls, default): + cls._default = default + @property def logger_file(self): """The logger file. From 3a8918ad2ede188cbe90831f88ef58e6f15b34e8 Mon Sep 17 00:00:00 2001 From: ruslanlazin Date: Tue, 5 Feb 2019 08:47:05 +0200 Subject: [PATCH 5/6] add default config test --- .../petstore/python/tests/test_pet_api.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index b0d485465c3..40b381786a2 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -132,7 +132,27 @@ def test_separate_default_client_instances(self): self.assertNotEqual(pet_api.api_client.user_agent, pet_api2.api_client.user_agent) - def test_separate_default_config_instances(self): + def test_default_config(self): + default = Configuration() + default.host = 'default_host' + default.api_key['api_key'] = 'default_key' + default.api_key_prefix['prefix'] = 'default_prefix' + Configuration.set_default(default) + + configuration = Configuration() + self.assertIsNot(configuration, default) + self.assertEqual(configuration.host, default.host) + self.assertEqual(configuration.api_key['api_key'], default.api_key['api_key']) + self.assertEqual(configuration.api_key_prefix['prefix'], default.api_key_prefix['prefix']) + + configuration.host = 'some_host' + configuration.api_key['api_key'] = 'some_key' + configuration.api_key_prefix['prefix'] = 'some_prefix' + self.assertEqual(default.host, 'default_host') + self.assertEqual(default.api_key['api_key'], 'default_key') + self.assertEqual(default.api_key_prefix['prefix'], 'default_prefix') + + def test_separate_config_instances(self): pet_api = petstore_api.PetApi() pet_api2 = petstore_api.PetApi() self.assertNotEqual(pet_api.api_client.configuration, pet_api2.api_client.configuration) From fe8c08b6f38760c1194e67aef812effdac935502 Mon Sep 17 00:00:00 2001 From: ruslanlazin Date: Tue, 5 Feb 2019 09:29:44 +0200 Subject: [PATCH 6/6] clean default configuration in tearDown() --- samples/client/petstore/python/tests/test_pet_api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index 40b381786a2..23b2ca0ec55 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -80,6 +80,9 @@ def setUpFiles(self): self.test_file_dir = os.path.realpath(self.test_file_dir) self.foo = os.path.join(self.test_file_dir, "foo.png") + def tearDown(self): + Configuration.set_default(None) + def test_preload_content_flag(self): self.pet_api.add_pet(body=self.pet)