forked from loafle/openapi-generator-original
[python-asyncio] tests and fixes (#7235)
* fix: creating ssl context and passing args/files/forms * feat: python-async add tests * chore: rebuild petstore sample for python, tornado and asyncio * feat: add python asyncio to travis * feat: print coverage (python-asyncio)
This commit is contained in:
committed by
William Cheng
parent
157e6b7fab
commit
f6e0e297eb
@@ -56,8 +56,7 @@ class RESTClientObject(object):
|
||||
# if not set certificate file, use Mozilla's root certificates.
|
||||
ca_certs = certifi.where()
|
||||
|
||||
ssl_context = ssl.SSLContext()
|
||||
ssl_context.load_verify_locations(cafile=ca_certs)
|
||||
ssl_context = ssl.create_default_context(cafile=ca_certs)
|
||||
if configuration.cert_file:
|
||||
ssl_context.load_cert_chain(
|
||||
configuration.cert_file, keyfile=configuration.key_file
|
||||
@@ -122,21 +121,34 @@ class RESTClientObject(object):
|
||||
"timeout": timeout,
|
||||
"headers": headers
|
||||
}
|
||||
|
||||
if query_params:
|
||||
args["url"] += '?' + urlencode(query_params)
|
||||
|
||||
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
||||
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
|
||||
if query_params:
|
||||
url += '?' + urlencode(query_params)
|
||||
if re.search('json', headers['Content-Type'], re.IGNORECASE):
|
||||
if body is not None:
|
||||
body = json.dumps(body)
|
||||
args["data"] = body
|
||||
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
|
||||
data = aiohttp.FormData()
|
||||
for k, v in post_params.items():
|
||||
data.add_field(k, v)
|
||||
args["data"] = data
|
||||
args["data"] = aiohttp.FormData(post_params)
|
||||
elif headers['Content-Type'] == 'multipart/form-data':
|
||||
args["data"] = post_params
|
||||
# must del headers['Content-Type'], or the correct
|
||||
# Content-Type which generated by aiohttp
|
||||
del headers['Content-Type']
|
||||
data = aiohttp.FormData()
|
||||
for param in post_params:
|
||||
k, v = param
|
||||
if isinstance(v, tuple) and len(v) == 3:
|
||||
data.add_field(k,
|
||||
value=v[1],
|
||||
filename=v[0],
|
||||
content_type=v[2])
|
||||
else:
|
||||
data.add_field(k, v)
|
||||
args["data"] = data
|
||||
|
||||
# Pass a `bytes` parameter directly in the body to support
|
||||
# other content types than Json when `body` argument is provided
|
||||
# in serialized form
|
||||
@@ -148,8 +160,6 @@ class RESTClientObject(object):
|
||||
arguments. Please check that your arguments match
|
||||
declared content type."""
|
||||
raise ApiException(status=0, reason=msg)
|
||||
else:
|
||||
args["data"] = query_params
|
||||
|
||||
async with self.pool_manager.request(**args) as r:
|
||||
data = await r.text()
|
||||
|
||||
Reference in New Issue
Block a user