Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Fixes requirements.txt, applies default headers before header params #37

Merged
merged 4 commits into from
Oct 10, 2022
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 @@ -994,7 +994,7 @@ class ApiClient:
self.pool_threads = pool_threads

self.rest_client = rest.RESTClientObject(configuration)
self.default_headers = {}
self.default_headers = HTTPHeaderDict()
if header_name is not None:
self.default_headers[header_name] = header_value
self.cookie = cookie
Expand Down Expand Up @@ -1054,15 +1054,18 @@ class ApiClient:
) -> urllib3.HTTPResponse:

# header parameters
headers = headers or HTTPHeaderDict()
headers.update(self.default_headers)
used_headers = HTTPHeaderDict(self.default_headers)
if self.cookie:
headers['Cookie'] = self.cookie

# auth setting
self.update_params_for_auth(headers,
self.update_params_for_auth(used_headers,
auth_settings, resource_path, method, body)

# must happen after cookie setting and auth setting in case user is overriding those
if headers:
used_headers.update(headers)

# request url
if host is None:
url = self.configuration.host + resource_path
Expand All @@ -1074,7 +1077,7 @@ class ApiClient:
response = {{#if asyncio}}await {{/if}}{{#if tornado}}yield {{/if}}self.request(
method,
url,
headers=headers,
headers=used_headers,
fields=fields,
body=body,
stream=stream,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{#if asyncio}}
{{#if quoted}}"{{/if}}aiohttp >= 3.0.0{{#if quoted}}",{{/if}}
{{/if}}
{{#if quoted}}"{{/if}}certifi >= 14.5.14{{#if quoted}}",{{/if}}
{{#if quoted}}"{{/if}}frozendict ~= 2.3.4{{#if quoted}}",{{/if}}
{{#if hasHttpSignatureMethods}}
{{#if quoted}}"{{/if}}pem >= 19.3.0{{#if quoted}}",{{/if}}
{{#if quoted}}"{{/if}}pycryptodome >= 3.9.0{{#if quoted}}",{{/if}}
{{/if}}
{{#if quoted}}"{{/if}}python-dateutil ~= 2.7.0{{#if quoted}}",{{/if}}
{{#if quoted}}"{{/if}}setuptools >= 21.0.0{{#if quoted}}",{{/if}}
{{#if tornado}}
{{#if quoted}}"{{/if}}tornado >= 4.2{{#if quoted}}",{{/if}}
{{/if}}
{{#if quoted}}"{{/if}}typing_extensions ~= 4.3.0{{#if quoted}}",{{/if}}
{{#if quoted}}"{{/if}}urllib3 ~= 1.26.7{{#if quoted}}",{{/if}}
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
certifi >= 14.05.14
frozendict >= 2.0.3
python_dateutil >= 2.5.3
setuptools >= 21.0.0
urllib3 >= 1.15.1
{{> required_libraries quoted=false }}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,7 @@ VERSION = "{{packageVersion}}"
# http://pypi.python.org/pypi/setuptools

REQUIRES = [
"urllib3 >= 1.15",
"certifi",
"python-dateutil",
"frozendict >= 2.0.3",
{{#if asyncio}}
"aiohttp >= 3.0.0",
{{/if}}
{{#if tornado}}
"tornado>=4.2,<5",
{{/if}}
{{#if hasHttpSignatureMethods}}
"pem>=19.3.0",
"pycryptodome>=3.9.0",
{{/if}}
"typing_extensions",
{{> required_libraries quoted=true }}
]

setup(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
certifi >= 14.05.14
frozendict >= 2.0.3
python_dateutil >= 2.5.3
certifi >= 14.5.14
frozendict ~= 2.3.4
python-dateutil ~= 2.7.0
setuptools >= 21.0.0
urllib3 >= 1.15.1
typing_extensions ~= 4.3.0
urllib3 ~= 1.26.7
11 changes: 6 additions & 5 deletions samples/openapi3/client/3_0_3_unit_test/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
# http://pypi.python.org/pypi/setuptools

REQUIRES = [
"urllib3 >= 1.15",
"certifi",
"python-dateutil",
"frozendict >= 2.0.3",
"typing_extensions",
"certifi >= 14.5.14",
"frozendict ~= 2.3.4",
"python-dateutil ~= 2.7.0",
"setuptools >= 21.0.0",
"typing_extensions ~= 4.3.0",
"urllib3 ~= 1.26.7",
]

setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def __init__(
self.pool_threads = pool_threads

self.rest_client = rest.RESTClientObject(configuration)
self.default_headers = {}
self.default_headers = HTTPHeaderDict()
if header_name is not None:
self.default_headers[header_name] = header_value
self.cookie = cookie
Expand Down Expand Up @@ -1055,15 +1055,18 @@ def __call_api(
) -> urllib3.HTTPResponse:

# header parameters
headers = headers or HTTPHeaderDict()
headers.update(self.default_headers)
used_headers = HTTPHeaderDict(self.default_headers)
if self.cookie:
headers['Cookie'] = self.cookie

# auth setting
self.update_params_for_auth(headers,
self.update_params_for_auth(used_headers,
auth_settings, resource_path, method, body)

# must happen after cookie setting and auth setting in case user is overriding those
if headers:
used_headers.update(headers)

# request url
if host is None:
url = self.configuration.host + resource_path
Expand All @@ -1075,7 +1078,7 @@ def __call_api(
response = self.request(
method,
url,
headers=headers,
headers=used_headers,
fields=fields,
body=body,
stream=stream,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
certifi >= 14.05.14
frozendict >= 2.0.3
python_dateutil >= 2.5.3
certifi >= 14.5.14
frozendict ~= 2.3.4
python-dateutil ~= 2.7.0
setuptools >= 21.0.0
urllib3 >= 1.15.1
typing_extensions ~= 4.3.0
urllib3 ~= 1.26.7
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
# http://pypi.python.org/pypi/setuptools

REQUIRES = [
"urllib3 >= 1.15",
"certifi",
"python-dateutil",
"frozendict >= 2.0.3",
"typing_extensions",
"certifi >= 14.5.14",
"frozendict ~= 2.3.4",
"python-dateutil ~= 2.7.0",
"setuptools >= 21.0.0",
"typing_extensions ~= 4.3.0",
"urllib3 ~= 1.26.7",
]

setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def __init__(
self.pool_threads = pool_threads

self.rest_client = rest.RESTClientObject(configuration)
self.default_headers = {}
self.default_headers = HTTPHeaderDict()
if header_name is not None:
self.default_headers[header_name] = header_value
self.cookie = cookie
Expand Down Expand Up @@ -1055,15 +1055,18 @@ def __call_api(
) -> urllib3.HTTPResponse:

# header parameters
headers = headers or HTTPHeaderDict()
headers.update(self.default_headers)
used_headers = HTTPHeaderDict(self.default_headers)
if self.cookie:
headers['Cookie'] = self.cookie

# auth setting
self.update_params_for_auth(headers,
self.update_params_for_auth(used_headers,
auth_settings, resource_path, method, body)

# must happen after cookie setting and auth setting in case user is overriding those
if headers:
used_headers.update(headers)

# request url
if host is None:
url = self.configuration.host + resource_path
Expand All @@ -1075,7 +1078,7 @@ def __call_api(
response = self.request(
method,
url,
headers=headers,
headers=used_headers,
fields=fields,
body=body,
stream=stream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def __init__(
self.pool_threads = pool_threads

self.rest_client = rest.RESTClientObject(configuration)
self.default_headers = {}
self.default_headers = HTTPHeaderDict()
if header_name is not None:
self.default_headers[header_name] = header_value
self.cookie = cookie
Expand Down Expand Up @@ -1055,15 +1055,18 @@ def __call_api(
) -> urllib3.HTTPResponse:

# header parameters
headers = headers or HTTPHeaderDict()
headers.update(self.default_headers)
used_headers = HTTPHeaderDict(self.default_headers)
if self.cookie:
headers['Cookie'] = self.cookie

# auth setting
self.update_params_for_auth(headers,
self.update_params_for_auth(used_headers,
auth_settings, resource_path, method, body)

# must happen after cookie setting and auth setting in case user is overriding those
if headers:
used_headers.update(headers)

# request url
if host is None:
url = self.configuration.host + resource_path
Expand All @@ -1075,7 +1078,7 @@ def __call_api(
response = self.request(
method,
url,
headers=headers,
headers=used_headers,
fields=fields,
body=body,
stream=stream,
Expand Down
11 changes: 7 additions & 4 deletions samples/openapi3/client/petstore/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
certifi >= 14.05.14
frozendict >= 2.0.3
python_dateutil >= 2.5.3
certifi >= 14.5.14
frozendict ~= 2.3.4
pem >= 19.3.0
pycryptodome >= 3.9.0
python-dateutil ~= 2.7.0
setuptools >= 21.0.0
urllib3 >= 1.15.1
typing_extensions ~= 4.3.0
urllib3 ~= 1.26.7
15 changes: 8 additions & 7 deletions samples/openapi3/client/petstore/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
# http://pypi.python.org/pypi/setuptools

REQUIRES = [
"urllib3 >= 1.15",
"certifi",
"python-dateutil",
"frozendict >= 2.0.3",
"pem>=19.3.0",
"pycryptodome>=3.9.0",
"typing_extensions",
"certifi >= 14.5.14",
"frozendict ~= 2.3.4",
"pem >= 19.3.0",
"pycryptodome >= 3.9.0",
"python-dateutil ~= 2.7.0",
"setuptools >= 21.0.0",
"typing_extensions ~= 4.3.0",
"urllib3 ~= 1.26.7",
]

setup(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# coding: utf-8

"""


Generated by: https://openapi-generator.tech
"""

import unittest
from unittest.mock import patch

import urllib3

import petstore_api
from petstore_api.paths.fake import get # noqa: E501
from petstore_api import configuration, schemas, api_client

from ... import ApiTestMixin


class TestFake(ApiTestMixin, unittest.TestCase):
"""
Fake unit test stubs
To test enum parameters # noqa: E501
"""
used_api_client = api_client.ApiClient(
header_name='enum_header_string',
header_value='_abc'
)
api = get.ApiForget(api_client=used_api_client)

@patch.object(urllib3.PoolManager, 'request')
def test_passed_in_header_overrides_default(self, mock_request):
mock_request.return_value = self.response(b'')

api_response = self.api.get(header_params={'enum_header_string': '-efg'})
self.assert_pool_manager_request_called_with(
mock_request,
f'http://petstore.swagger.io:80/v2/fake',
body=None,
method='GET',
content_type=None,
accept_content_type=None,
headers={'enum_header_string': '-efg'}
)

assert isinstance(api_response.response, urllib3.HTTPResponse)
assert isinstance(api_response.body, schemas.Unset)
assert isinstance(api_response.headers, schemas.Unset)
assert api_response.response.status == 200

@patch.object(urllib3.PoolManager, 'request')
def test_default_header_used_when_no_header_params_input(self, mock_request):
mock_request.return_value = self.response(b'')

api_response = self.api.get()
self.assert_pool_manager_request_called_with(
mock_request,
f'http://petstore.swagger.io:80/v2/fake',
body=None,
method='GET',
content_type=None,
accept_content_type=None,
headers={'enum_header_string': '_abc'}
)

assert isinstance(api_response.response, urllib3.HTTPResponse)
assert isinstance(api_response.body, schemas.Unset)
assert isinstance(api_response.headers, schemas.Unset)
assert api_response.response.status == 200

if __name__ == '__main__':
unittest.main()