Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ 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.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

Expand Down
3 changes: 0 additions & 3 deletions samples/client/petstore/python-tornado/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions samples/client/petstore/python-tornado/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python-tornado/git_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions samples/client/petstore/python-tornado/petstore_api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,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 = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
7 changes: 3 additions & 4 deletions samples/client/petstore/python-tornado/tests/test_pet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,8 +27,7 @@

import urllib3

HOST = 'http://petstore.swagger.io/v2'

HOST = 'http://localhost/v2'

class PetApiTests(AsyncTestCase):

Expand Down Expand Up @@ -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])
Expand All @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/python/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python/git_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python/test_python2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python/test_python2_and_3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
9 changes: 5 additions & 4 deletions samples/client/petstore/python/tests/test_pet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +24,7 @@

import urllib3

HOST = 'http://petstore.swagger.io/v2'
HOST = 'http://localhost/v2'


class TimeoutWithEqual(urllib3.Timeout):
Expand Down Expand Up @@ -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 ',
Expand Down Expand Up @@ -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)

Expand Down