mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-03 15:30:59 +00:00
[python] fix tests, tornado ssl fix (#6968)
* fix: non-zero exit code if tests fail * tests: use local petserver to run tests * fix: non-zero exit code if tests fail * tests: use local petserver to run tests * fix: creating ssl context in old version of Python * chore: remove unused target from Makefile * doc: changes from upstream * fix: tornado client raises NotImplementedError in older version of Python
This commit is contained in:
parent
c6ffbd38ad
commit
73cb68ee7b
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -60,12 +60,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
|
||||
|
||||
|
@ -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/
|
||||
|
@ -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 json
|
||||
|
||||
import urllib3
|
||||
|
||||
HOST = 'http://petstore.swagger.io/v2'
|
||||
|
||||
HOST = 'http://localhost/v2'
|
||||
|
||||
class PetApiTests(AsyncTestCase):
|
||||
|
||||
@ -152,7 +153,6 @@ class PetApiTests(AsyncTestCase):
|
||||
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 @@ class PetApiTests(AsyncTestCase):
|
||||
)
|
||||
|
||||
@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])
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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/
|
||||
|
@ -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/
|
||||
|
@ -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 json
|
||||
|
||||
import urllib3
|
||||
|
||||
HOST = 'http://petstore.swagger.io/v2'
|
||||
HOST = 'http://localhost/v2'
|
||||
|
||||
|
||||
class TimeoutWithEqual(urllib3.Timeout):
|
||||
@ -102,14 +104,14 @@ class PetApiTests(unittest.TestCase):
|
||||
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 @@ class PetApiTests(unittest.TestCase):
|
||||
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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user