From 9b148be57e17fc832c79136f92052f448abbe504 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Fri, 25 Sep 2015 15:10:32 +0800 Subject: [PATCH] Fix issue in python client. If upload only file it will not send file content. --- .../main/resources/python/api_client.mustache | 2 +- .../python/swagger_client/api_client.py | 2 +- .../petstore/python/tests/test_pet_api.py | 22 ++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/api_client.mustache b/modules/swagger-codegen/src/main/resources/python/api_client.mustache index 62048f4b29f..969eb4e7992 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -126,7 +126,7 @@ class ApiClient(object): for k, v in iteritems(query_params)} # post parameters - if post_params: + if post_params or files: post_params = self.prepare_post_parameters(post_params, files) post_params = self.sanitize_for_serialization(post_params) diff --git a/samples/client/petstore/python/swagger_client/api_client.py b/samples/client/petstore/python/swagger_client/api_client.py index 86c4a161110..fdc92cae77f 100644 --- a/samples/client/petstore/python/swagger_client/api_client.py +++ b/samples/client/petstore/python/swagger_client/api_client.py @@ -126,7 +126,7 @@ class ApiClient(object): for k, v in iteritems(query_params)} # post parameters - if post_params: + if post_params or files: post_params = self.prepare_post_parameters(post_params, files) post_params = self.sanitize_for_serialization(post_params) diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index 6994ddbd649..300a7bee783 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -68,7 +68,7 @@ class PetApiTests(unittest.TestCase): self.assertNotEqual(pet_api3.api_client, swagger_client.configuration.api_client) # customized pet api not using the old pet api's api client self.assertNotEqual(pet_api3.api_client, pet_api2.api_client) - + def test_async_request(self): self.pet_api.add_pet(body=self.pet) @@ -110,7 +110,7 @@ class PetApiTests(unittest.TestCase): def test_find_pets_by_status(self): self.pet_api.add_pet(body=self.pet) - + self.assertIn( self.pet.id, list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_status(status=[self.pet.status]))) @@ -118,7 +118,7 @@ class PetApiTests(unittest.TestCase): def test_find_pets_by_tags(self): self.pet_api.add_pet(body=self.pet) - + self.assertIn( self.pet.id, list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_tags(tags=[self.tag.name]))) @@ -126,7 +126,7 @@ class PetApiTests(unittest.TestCase): def test_update_pet_with_form(self): self.pet_api.add_pet(body=self.pet) - + name = "hello kity with form updated" status = "pending" self.pet_api.update_pet_with_form(pet_id=self.pet.id, name=name, status=status) @@ -137,6 +137,7 @@ class PetApiTests(unittest.TestCase): self.assertEqual(status, fetched.status) def test_upload_file(self): + # upload file with form parameter try: additional_metadata = "special" self.pet_api.upload_file( @@ -147,10 +148,16 @@ class PetApiTests(unittest.TestCase): except ApiException as e: self.fail("upload_file() raised {0} unexpectedly".format(type(e))) + # upload only file + try: + self.pet_api.upload_file(pet_id=self.pet.id, file=self.foo) + except ApiException as e: + self.fail("upload_file() raised {0} unexpectedly".format(type(e))) + def test_delete_pet(self): self.pet_api.add_pet(body=self.pet) self.pet_api.delete_pet(pet_id=self.pet.id, api_key="special-key") - + try: self.pet_api.get_pet_by_id(pet_id=self.pet.id) raise "expected an error" @@ -159,8 +166,3 @@ class PetApiTests(unittest.TestCase): if __name__ == '__main__': unittest.main() - - - - -