Skip to content

Commit e301020

Browse files
committed
Merge pull request #1295 from geekerzp/python_upload_file
[Python] Fix issue in python client
2 parents c26a387 + 9b148be commit e301020

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class ApiClient(object):
126126
for k, v in iteritems(query_params)}
127127

128128
# post parameters
129-
if post_params:
129+
if post_params or files:
130130
post_params = self.prepare_post_parameters(post_params, files)
131131
post_params = self.sanitize_for_serialization(post_params)
132132

samples/client/petstore/python/swagger_client/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def __call_api(self, resource_path, method,
126126
for k, v in iteritems(query_params)}
127127

128128
# post parameters
129-
if post_params:
129+
if post_params or files:
130130
post_params = self.prepare_post_parameters(post_params, files)
131131
post_params = self.sanitize_for_serialization(post_params)
132132

samples/client/petstore/python/tests/test_pet_api.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_create_api_instance(self):
6868
self.assertNotEqual(pet_api3.api_client, swagger_client.configuration.api_client)
6969
# customized pet api not using the old pet api's api client
7070
self.assertNotEqual(pet_api3.api_client, pet_api2.api_client)
71-
71+
7272
def test_async_request(self):
7373
self.pet_api.add_pet(body=self.pet)
7474

@@ -110,23 +110,23 @@ def test_update_pet(self):
110110

111111
def test_find_pets_by_status(self):
112112
self.pet_api.add_pet(body=self.pet)
113-
113+
114114
self.assertIn(
115115
self.pet.id,
116116
list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_status(status=[self.pet.status])))
117117
)
118118

119119
def test_find_pets_by_tags(self):
120120
self.pet_api.add_pet(body=self.pet)
121-
121+
122122
self.assertIn(
123123
self.pet.id,
124124
list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_tags(tags=[self.tag.name])))
125125
)
126126

127127
def test_update_pet_with_form(self):
128128
self.pet_api.add_pet(body=self.pet)
129-
129+
130130
name = "hello kity with form updated"
131131
status = "pending"
132132
self.pet_api.update_pet_with_form(pet_id=self.pet.id, name=name, status=status)
@@ -137,6 +137,7 @@ def test_update_pet_with_form(self):
137137
self.assertEqual(status, fetched.status)
138138

139139
def test_upload_file(self):
140+
# upload file with form parameter
140141
try:
141142
additional_metadata = "special"
142143
self.pet_api.upload_file(
@@ -147,10 +148,16 @@ def test_upload_file(self):
147148
except ApiException as e:
148149
self.fail("upload_file() raised {0} unexpectedly".format(type(e)))
149150

151+
# upload only file
152+
try:
153+
self.pet_api.upload_file(pet_id=self.pet.id, file=self.foo)
154+
except ApiException as e:
155+
self.fail("upload_file() raised {0} unexpectedly".format(type(e)))
156+
150157
def test_delete_pet(self):
151158
self.pet_api.add_pet(body=self.pet)
152159
self.pet_api.delete_pet(pet_id=self.pet.id, api_key="special-key")
153-
160+
154161
try:
155162
self.pet_api.get_pet_by_id(pet_id=self.pet.id)
156163
raise "expected an error"
@@ -159,8 +166,3 @@ def test_delete_pet(self):
159166

160167
if __name__ == '__main__':
161168
unittest.main()
162-
163-
164-
165-
166-

0 commit comments

Comments
 (0)