[python-client] Enable per-request auth settings (#6569)

* Enable per-request access token in Python client.

* Add missing regenerated sample files.

* Rework to the more general case of overriding the auth settings for a request.

* Add unit tests.

* Update api_client.mustache so that request_auth overrides all other auth settings when specified.
This commit is contained in:
Warren Gray
2020-06-11 02:40:10 -04:00
committed by GitHub
parent ebcce67419
commit 933ab0640a
32 changed files with 1437 additions and 382 deletions

View File

@@ -121,6 +121,30 @@ class PetApiTests(unittest.TestCase):
self.pet_api.add_pet(self.pet, _request_timeout=5)
self.pet_api.add_pet(self.pet, _request_timeout=(1, 2))
def test_auth_settings(self):
mock_pool = MockPoolManager(self)
self.api_client.rest_client.pool_manager = mock_pool
mock_pool.expect_request('POST', HOST + '/pet',
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
headers={'Content-Type': 'application/json',
'Authorization': 'Bearer ACCESS_TOKEN',
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
preload_content=True, timeout=None)
mock_pool.expect_request('POST', HOST + '/pet',
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
headers={'Content-Type': 'application/json',
'Authorization': 'Prefix ANOTHER_TOKEN',
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
preload_content=True, timeout=None)
self.pet_api.add_pet(self.pet, _request_auth=None)
self.pet_api.add_pet(self.pet, _request_auth={
'in': 'header',
'key': 'Authorization',
'value': 'Prefix ANOTHER_TOKEN'
})
def test_separate_default_client_instances(self):
pet_api = petstore_api.PetApi()
pet_api2 = petstore_api.PetApi()