From d18d9b2042f69c560e3b52f2f77b72e832962cbc Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Wed, 15 Nov 2017 00:20:33 +0100 Subject: [PATCH 1/8] fix: non-zero exit code if tests fail --- samples/client/petstore/python-tornado/test_python2_and_3.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/client/petstore/python-tornado/test_python2_and_3.sh b/samples/client/petstore/python-tornado/test_python2_and_3.sh index a224ffe75dc..7b5795ec24a 100755 --- a/samples/client/petstore/python-tornado/test_python2_and_3.sh +++ b/samples/client/petstore/python-tornado/test_python2_and_3.sh @@ -21,7 +21,7 @@ pip install -r $REQUIREMENTS_FILE | tee -a $REQUIREMENTS_OUT python setup.py develop ### run tests -tox +tox || exit 1 ### static analysis of code flake8 --show-source petstore_api/ From cb9b605c6b85a3270ac8d5c2c8ed81b337803013 Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Wed, 15 Nov 2017 00:20:50 +0100 Subject: [PATCH 2/8] tests: use local petserver to run tests --- .../client/petstore/python-tornado/tests/test_pet_api.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/samples/client/petstore/python-tornado/tests/test_pet_api.py b/samples/client/petstore/python-tornado/tests/test_pet_api.py index ad4ec29b2bc..622b89868a1 100644 --- a/samples/client/petstore/python-tornado/tests/test_pet_api.py +++ b/samples/client/petstore/python-tornado/tests/test_pet_api.py @@ -4,6 +4,8 @@ """ Run the tests. +$ docker pull swaggerapi/petstore +$ docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore $ pip install nose (optional) $ cd petstore_api-python $ nosetests -v @@ -25,8 +27,7 @@ import urllib3 -HOST = 'http://petstore.swagger.io/v2' - +HOST = 'http://localhost/v2' class PetApiTests(AsyncTestCase): @@ -152,7 +153,6 @@ def test_update_pet(self): self.assertEqual(fetched.category.name, self.pet.category.name) @gen_test - @unittest.skip('skipping the test as the method sometimes invalid Petstore object with incorrect status') def test_find_pets_by_status(self): yield self.pet_api.add_pet(body=self.pet) pets = yield self.pet_api.find_pets_by_status(status=[self.pet.status]) @@ -162,7 +162,6 @@ def test_find_pets_by_status(self): ) @gen_test - @unittest.skip("skipping the test as the method sometimes invalid Petstore object with incorrect status") def test_find_pets_by_tags(self): yield self.pet_api.add_pet(body=self.pet) pets = yield self.pet_api.find_pets_by_tags(tags=[self.tag.name]) From c0219707360f0e3cc3143beb897409453d4ce2a4 Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Wed, 15 Nov 2017 00:27:28 +0100 Subject: [PATCH 3/8] fix: non-zero exit code if tests fail --- samples/client/petstore/python/test_python2.sh | 2 +- samples/client/petstore/python/test_python2_and_3.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/client/petstore/python/test_python2.sh b/samples/client/petstore/python/test_python2.sh index c88094efc2d..fb0eaed6ffa 100755 --- a/samples/client/petstore/python/test_python2.sh +++ b/samples/client/petstore/python/test_python2.sh @@ -21,7 +21,7 @@ pip install -r $REQUIREMENTS_FILE | tee -a $REQUIREMENTS_OUT python setup.py develop ### run tests -nosetests +nosetests || exit 1 ### static analysis of code flake8 --show-source petstore_api/ diff --git a/samples/client/petstore/python/test_python2_and_3.sh b/samples/client/petstore/python/test_python2_and_3.sh index a224ffe75dc..7b5795ec24a 100755 --- a/samples/client/petstore/python/test_python2_and_3.sh +++ b/samples/client/petstore/python/test_python2_and_3.sh @@ -21,7 +21,7 @@ pip install -r $REQUIREMENTS_FILE | tee -a $REQUIREMENTS_OUT python setup.py develop ### run tests -tox +tox || exit 1 ### static analysis of code flake8 --show-source petstore_api/ From a8122f8802ce0e3002ea23cc895a28e5f7a78ab6 Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Wed, 15 Nov 2017 00:27:37 +0100 Subject: [PATCH 4/8] tests: use local petserver to run tests --- samples/client/petstore/python/tests/test_pet_api.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index 1c5b2739062..f987f38eb8c 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -4,6 +4,8 @@ """ Run the tests. +$ docker pull swaggerapi/petstore +$ docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore $ pip install nose (optional) $ cd petstore_api-python $ nosetests -v @@ -22,7 +24,7 @@ import urllib3 -HOST = 'http://petstore.swagger.io/v2' +HOST = 'http://localhost/v2' class TimeoutWithEqual(urllib3.Timeout): @@ -102,14 +104,14 @@ def test_timeout(self): mock_pool = MockPoolManager(self) self.api_client.rest_client.pool_manager = mock_pool - mock_pool.expect_request('POST', 'http://petstore.swagger.io/v2/pet', + mock_pool.expect_request('POST', 'http://localhost/v2/pet', body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)), headers={'Content-Type': 'application/json', 'Authorization': 'Bearer ', 'Accept': 'application/json', 'User-Agent': 'Swagger-Codegen/1.0.0/python'}, preload_content=True, timeout=TimeoutWithEqual(total=5)) - mock_pool.expect_request('POST', 'http://petstore.swagger.io/v2/pet', + mock_pool.expect_request('POST', 'http://localhost/v2/pet', body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)), headers={'Content-Type': 'application/json', 'Authorization': 'Bearer ', @@ -220,7 +222,6 @@ def test_find_pets_by_status(self): list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_status(status=[self.pet.status]))) ) - @unittest.skip("skipping the test as the method sometimes invalid Petstore object with incorrect status") def test_find_pets_by_tags(self): self.pet_api.add_pet(body=self.pet) From ff978363854001d2de21c6d660cacf87ee68cc3b Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Wed, 15 Nov 2017 22:38:47 +0100 Subject: [PATCH 5/8] fix: creating ssl context in old version of Python --- .../src/main/resources/python/tornado/rest.mustache | 9 ++++++++- .../client/petstore/python-tornado/petstore_api/rest.py | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/tornado/rest.mustache b/modules/swagger-codegen/src/main/resources/python/tornado/rest.mustache index 805e9d4badd..e23ef8cb6e0 100644 --- a/modules/swagger-codegen/src/main/resources/python/tornado/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/tornado/rest.mustache @@ -6,7 +6,14 @@ import io import json import logging import re + import ssl +try: + from ssl import create_default_context +except ImportError: + # backward capability create_default_context is on Python 3.4+, 2.7.9+ + def create_default_context(): + return ssl.SSLContext(ssl.PROTOCOL_SSLv23) import certifi # python 2 and python 3 compatibility library @@ -51,7 +58,7 @@ class RESTClientObject(object): # if not set certificate file, use Mozilla's root certificates. ca_certs = certifi.where() - self.ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) + self.ssl_context = create_default_context() self.ssl_context.load_verify_locations(cafile=ca_certs) if configuration.cert_file: self.ssl_context.load_cert_chain( diff --git a/samples/client/petstore/python-tornado/petstore_api/rest.py b/samples/client/petstore/python-tornado/petstore_api/rest.py index 2186454a352..635e6b00e95 100644 --- a/samples/client/petstore/python-tornado/petstore_api/rest.py +++ b/samples/client/petstore/python-tornado/petstore_api/rest.py @@ -15,7 +15,14 @@ import json import logging import re + import ssl +try: + from ssl import create_default_context +except ImportError: + # backward capability create_default_context is on Python 3.4+, 2.7.9+ + def create_default_context(): + return ssl.SSLContext(ssl.PROTOCOL_SSLv23) import certifi # python 2 and python 3 compatibility library @@ -60,7 +67,7 @@ def __init__(self, configuration, pools_size=4, maxsize=4): # if not set certificate file, use Mozilla's root certificates. ca_certs = certifi.where() - self.ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) + self.ssl_context = create_default_context() self.ssl_context.load_verify_locations(cafile=ca_certs) if configuration.cert_file: self.ssl_context.load_cert_chain( From 32a8ce4cdc32db7314039c2bce3e4c66cb22dfbe Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Wed, 15 Nov 2017 22:39:31 +0100 Subject: [PATCH 6/8] chore: remove unused target from Makefile --- samples/client/petstore/python-tornado/Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/samples/client/petstore/python-tornado/Makefile b/samples/client/petstore/python-tornado/Makefile index ba5c5e73c63..1f9d5625226 100644 --- a/samples/client/petstore/python-tornado/Makefile +++ b/samples/client/petstore/python-tornado/Makefile @@ -14,8 +14,5 @@ clean: find . -name "*.py[oc]" -delete find . -name "__pycache__" -delete -test: clean - bash ./test_python2.sh - test-all: clean bash ./test_python2_and_3.sh From d5676c8779264cdcbb13b3fb50604bbfa3f1b91c Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Wed, 15 Nov 2017 22:41:31 +0100 Subject: [PATCH 7/8] doc: changes from upstream --- samples/client/petstore/python-tornado/docs/FakeApi.md | 4 ++-- samples/client/petstore/python-tornado/git_push.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/client/petstore/python-tornado/docs/FakeApi.md b/samples/client/petstore/python-tornado/docs/FakeApi.md index 1da84500bfe..b910ba2b464 100644 --- a/samples/client/petstore/python-tornado/docs/FakeApi.md +++ b/samples/client/petstore/python-tornado/docs/FakeApi.md @@ -273,10 +273,10 @@ configuration.password = 'YOUR_PASSWORD' # create an instance of the API class api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration)) -number = 8.14 # float | None +number = 3.4 # float | None double = 1.2 # float | None pattern_without_delimiter = 'pattern_without_delimiter_example' # str | None -byte = 'B' # str | None +byte = 'byte_example' # str | None integer = 56 # int | None (optional) int32 = 56 # int | None (optional) int64 = 789 # int | None (optional) diff --git a/samples/client/petstore/python-tornado/git_push.sh b/samples/client/petstore/python-tornado/git_push.sh index ed374619b13..ae01b182ae9 100644 --- a/samples/client/petstore/python-tornado/git_push.sh +++ b/samples/client/petstore/python-tornado/git_push.sh @@ -36,7 +36,7 @@ git_remote=`git remote` if [ "$git_remote" = "" ]; then # git remote not defined if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment." + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git else git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git From 1a36b2eb59ff576d07ffe999c703901d3c98ab69 Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Thu, 16 Nov 2017 00:32:43 +0100 Subject: [PATCH 8/8] fix: tornado client raises NotImplementedError in older version of Python --- .../resources/python/tornado/rest.mustache | 27 ++++++++++--------- .../python-tornado/petstore_api/rest.py | 27 ++++++++++--------- .../client/petstore/python/docs/FakeApi.md | 4 +-- samples/client/petstore/python/git_push.sh | 2 +- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/tornado/rest.mustache b/modules/swagger-codegen/src/main/resources/python/tornado/rest.mustache index e23ef8cb6e0..ad3ddc8d717 100644 --- a/modules/swagger-codegen/src/main/resources/python/tornado/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/tornado/rest.mustache @@ -6,14 +6,7 @@ import io import json import logging import re - import ssl -try: - from ssl import create_default_context -except ImportError: - # backward capability create_default_context is on Python 3.4+, 2.7.9+ - def create_default_context(): - return ssl.SSLContext(ssl.PROTOCOL_SSLv23) import certifi # python 2 and python 3 compatibility library @@ -58,12 +51,20 @@ class RESTClientObject(object): # if not set certificate file, use Mozilla's root certificates. ca_certs = certifi.where() - self.ssl_context = create_default_context() - self.ssl_context.load_verify_locations(cafile=ca_certs) - if configuration.cert_file: - self.ssl_context.load_cert_chain( - configuration.cert_file, keyfile=configuration.key_file - ) + if hasattr(ssl, 'create_default_context'): + # require Python 2.7.9+, 3.4+ + self.ssl_context = ssl.create_default_context() + self.ssl_context.load_verify_locations(cafile=ca_certs) + if configuration.cert_file: + self.ssl_context.load_cert_chain( + configuration.cert_file, keyfile=configuration.key_file + ) + + elif configuration.cert_file or configuration.ssl_ca_cert: + raise NotImplementedError('SSL requires Python 2.7.9+, 3.4+') + + else: + self.ssl_context = None self.proxy_port = self.proxy_host = None diff --git a/samples/client/petstore/python-tornado/petstore_api/rest.py b/samples/client/petstore/python-tornado/petstore_api/rest.py index 635e6b00e95..091a5747ccb 100644 --- a/samples/client/petstore/python-tornado/petstore_api/rest.py +++ b/samples/client/petstore/python-tornado/petstore_api/rest.py @@ -15,14 +15,7 @@ import json import logging import re - import ssl -try: - from ssl import create_default_context -except ImportError: - # backward capability create_default_context is on Python 3.4+, 2.7.9+ - def create_default_context(): - return ssl.SSLContext(ssl.PROTOCOL_SSLv23) import certifi # python 2 and python 3 compatibility library @@ -67,12 +60,20 @@ def __init__(self, configuration, pools_size=4, maxsize=4): # if not set certificate file, use Mozilla's root certificates. ca_certs = certifi.where() - self.ssl_context = create_default_context() - self.ssl_context.load_verify_locations(cafile=ca_certs) - if configuration.cert_file: - self.ssl_context.load_cert_chain( - configuration.cert_file, keyfile=configuration.key_file - ) + if hasattr(ssl, 'create_default_context'): + # require Python 2.7.9+, 3.4+ + self.ssl_context = ssl.create_default_context() + self.ssl_context.load_verify_locations(cafile=ca_certs) + if configuration.cert_file: + self.ssl_context.load_cert_chain( + configuration.cert_file, keyfile=configuration.key_file + ) + + elif configuration.cert_file or configuration.ssl_ca_cert: + raise NotImplementedError('SSL requires Python 2.7.9+, 3.4+') + + else: + self.ssl_context = None self.proxy_port = self.proxy_host = None diff --git a/samples/client/petstore/python/docs/FakeApi.md b/samples/client/petstore/python/docs/FakeApi.md index 1da84500bfe..b910ba2b464 100644 --- a/samples/client/petstore/python/docs/FakeApi.md +++ b/samples/client/petstore/python/docs/FakeApi.md @@ -273,10 +273,10 @@ configuration.password = 'YOUR_PASSWORD' # create an instance of the API class api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration)) -number = 8.14 # float | None +number = 3.4 # float | None double = 1.2 # float | None pattern_without_delimiter = 'pattern_without_delimiter_example' # str | None -byte = 'B' # str | None +byte = 'byte_example' # str | None integer = 56 # int | None (optional) int32 = 56 # int | None (optional) int64 = 789 # int | None (optional) diff --git a/samples/client/petstore/python/git_push.sh b/samples/client/petstore/python/git_push.sh index ed374619b13..ae01b182ae9 100644 --- a/samples/client/petstore/python/git_push.sh +++ b/samples/client/petstore/python/git_push.sh @@ -36,7 +36,7 @@ git_remote=`git remote` if [ "$git_remote" = "" ]; then # git remote not defined if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment." + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git else git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git