From 8d0efd812cbfe088c2a8c47bc7c93263d8ac6aa6 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Fri, 22 May 2015 15:50:09 +0800 Subject: [PATCH] updated unittests of python client --- .../src/main/resources/python/swagger.mustache | 16 ++++++++++------ .../SwaggerPetstore/swagger.py | 16 ++++++++++------ .../tests/test_api_client.py | 8 ++++++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/swagger.mustache index 569f0cd9e8d..ab45eace646 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/swagger.mustache @@ -105,7 +105,7 @@ class ApiClient(object): def to_path_value(self, obj): """ Convert a string or object to a path-friendly value - + :param obj: object or string value :return string: quoted value @@ -259,8 +259,11 @@ class ApiClient(object): Return `Accept` based on an array of accepts provided """ if not accepts: - return - if 'application/json'.lower() in accepts: + return + + accepts = list(map(lambda x: x.lower(), accepts)) + + if 'application/json' in accepts: return 'application/json' else: return ', '.join(accepts) @@ -272,9 +275,10 @@ class ApiClient(object): """ if not content_types: return 'application/json' - if 'application/json'.lower() in content_types: + + content_types = list(map(lambda x: x.lower(), content_types)) + + if 'application/json' in content_types: return 'application/json' else: return content_types[0] - - diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py index 569f0cd9e8d..ab45eace646 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py @@ -105,7 +105,7 @@ class ApiClient(object): def to_path_value(self, obj): """ Convert a string or object to a path-friendly value - + :param obj: object or string value :return string: quoted value @@ -259,8 +259,11 @@ class ApiClient(object): Return `Accept` based on an array of accepts provided """ if not accepts: - return - if 'application/json'.lower() in accepts: + return + + accepts = list(map(lambda x: x.lower(), accepts)) + + if 'application/json' in accepts: return 'application/json' else: return ', '.join(accepts) @@ -272,9 +275,10 @@ class ApiClient(object): """ if not content_types: return 'application/json' - if 'application/json'.lower() in content_types: + + content_types = list(map(lambda x: x.lower(), content_types)) + + if 'application/json' in content_types: return 'application/json' else: return content_types[0] - - diff --git a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py index 437e94d09c6..9adf7cdb99d 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py @@ -22,6 +22,10 @@ class ApiClientTests(unittest.TestCase): self.api_client = SwaggerPetstore.ApiClient(HOST) def test_select_header_accept(self): + accepts = ['APPLICATION/JSON', 'APPLICATION/XML'] + accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) + self.assertEqual(accept, 'application/json') + accepts = ['application/json', 'application/xml'] accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) self.assertEqual(accept, 'application/json') @@ -39,6 +43,10 @@ class ApiClientTests(unittest.TestCase): self.assertEqual(accept, None) def test_select_header_content_type(self): + content_types = ['APPLICATION/JSON', 'APPLICATION/XML'] + content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) + self.assertEqual(content_type, 'application/json') + content_types = ['application/json', 'application/xml'] content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) self.assertEqual(content_type, 'application/json')