Skip to content

Commit 8d0efd8

Browse files
committed
updated unittests of python client
1 parent 245ce64 commit 8d0efd8

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

modules/swagger-codegen/src/main/resources/python/swagger.mustache

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ApiClient(object):
105105
def to_path_value(self, obj):
106106
"""
107107
Convert a string or object to a path-friendly value
108-
108+
109109
:param obj: object or string value
110110
111111
:return string: quoted value
@@ -259,8 +259,11 @@ class ApiClient(object):
259259
Return `Accept` based on an array of accepts provided
260260
"""
261261
if not accepts:
262-
return
263-
if 'application/json'.lower() in accepts:
262+
return
263+
264+
accepts = list(map(lambda x: x.lower(), accepts))
265+
266+
if 'application/json' in accepts:
264267
return 'application/json'
265268
else:
266269
return ', '.join(accepts)
@@ -272,9 +275,10 @@ class ApiClient(object):
272275
"""
273276
if not content_types:
274277
return 'application/json'
275-
if 'application/json'.lower() in content_types:
278+
279+
content_types = list(map(lambda x: x.lower(), content_types))
280+
281+
if 'application/json' in content_types:
276282
return 'application/json'
277283
else:
278284
return content_types[0]
279-
280-

samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def call_api(self, resource_path, method, path_params=None, query_params=None, h
105105
def to_path_value(self, obj):
106106
"""
107107
Convert a string or object to a path-friendly value
108-
108+
109109
:param obj: object or string value
110110
111111
:return string: quoted value
@@ -259,8 +259,11 @@ def select_header_accept(accepts):
259259
Return `Accept` based on an array of accepts provided
260260
"""
261261
if not accepts:
262-
return
263-
if 'application/json'.lower() in accepts:
262+
return
263+
264+
accepts = list(map(lambda x: x.lower(), accepts))
265+
266+
if 'application/json' in accepts:
264267
return 'application/json'
265268
else:
266269
return ', '.join(accepts)
@@ -272,9 +275,10 @@ def select_header_content_type(content_types):
272275
"""
273276
if not content_types:
274277
return 'application/json'
275-
if 'application/json'.lower() in content_types:
278+
279+
content_types = list(map(lambda x: x.lower(), content_types))
280+
281+
if 'application/json' in content_types:
276282
return 'application/json'
277283
else:
278284
return content_types[0]
279-
280-

samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def setUp(self):
2222
self.api_client = SwaggerPetstore.ApiClient(HOST)
2323

2424
def test_select_header_accept(self):
25+
accepts = ['APPLICATION/JSON', 'APPLICATION/XML']
26+
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts)
27+
self.assertEqual(accept, 'application/json')
28+
2529
accepts = ['application/json', 'application/xml']
2630
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts)
2731
self.assertEqual(accept, 'application/json')
@@ -39,6 +43,10 @@ def test_select_header_accept(self):
3943
self.assertEqual(accept, None)
4044

4145
def test_select_header_content_type(self):
46+
content_types = ['APPLICATION/JSON', 'APPLICATION/XML']
47+
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types)
48+
self.assertEqual(content_type, 'application/json')
49+
4250
content_types = ['application/json', 'application/xml']
4351
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types)
4452
self.assertEqual(content_type, 'application/json')

0 commit comments

Comments
 (0)