add test cases for ApiClient.select_header_accept and

ApiClient.select_header_content_type of python client.
This commit is contained in:
geekerzp 2015-05-22 15:28:36 +08:00
parent bc9abceef3
commit 245ce642ce
7 changed files with 144 additions and 86 deletions

View File

@ -71,12 +71,12 @@ class {{classname}}(object):
body_params = {{#bodyParam}}params.get('{{paramName}}'){{/bodyParam}}{{^bodyParam}}None{{/bodyParam}} body_params = {{#bodyParam}}params.get('{{paramName}}'){{/bodyParam}}{{^bodyParam}}None{{/bodyParam}}
# HTTP header `Accept` # HTTP header `Accept`
accepts = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}] header_params['Accept'] = ApiClient.select_header_accept([{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}] header_params['Content-Type'] = ApiClient.select_header_content_type([{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,

View File

@ -259,7 +259,7 @@ class ApiClient(object):
Return `Accept` based on an array of accepts provided Return `Accept` based on an array of accepts provided
""" """
if not accepts: if not accepts:
return 'application/json' return
if 'application/json'.lower() in accepts: if 'application/json'.lower() in accepts:
return 'application/json' return 'application/json'
else: else:

View File

@ -66,12 +66,12 @@ class PetApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = ['application/json', 'application/xml'] header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml'])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -107,12 +107,12 @@ class PetApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = ['application/json', 'application/xml'] header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml'])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -148,12 +148,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -191,12 +191,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -238,12 +238,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -287,12 +287,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = ['application/x-www-form-urlencoded'] header_params['Content-Type'] = ApiClient.select_header_content_type(['application/x-www-form-urlencoded'])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -333,12 +333,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -380,12 +380,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = ['multipart/form-data'] header_params['Content-Type'] = ApiClient.select_header_content_type(['multipart/form-data'])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,

View File

@ -65,12 +65,12 @@ class StoreApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -108,12 +108,12 @@ class StoreApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -155,12 +155,12 @@ class StoreApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -202,12 +202,12 @@ class StoreApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,

View File

@ -66,12 +66,12 @@ class UserApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -107,12 +107,12 @@ class UserApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -148,12 +148,12 @@ class UserApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -190,12 +190,12 @@ class UserApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -232,12 +232,12 @@ class UserApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -277,12 +277,12 @@ class UserApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -325,12 +325,12 @@ class UserApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -370,12 +370,12 @@ class UserApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
header_params['Accept'] = ApiClient.select_header_accept(accepts) if not header_params['Accept']:
del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type([])
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,

View File

@ -259,7 +259,7 @@ class ApiClient(object):
Return `Accept` based on an array of accepts provided Return `Accept` based on an array of accepts provided
""" """
if not accepts: if not accepts:
return 'application/json' return
if 'application/json'.lower() in accepts: if 'application/json'.lower() in accepts:
return 'application/json' return 'application/json'
else: else:

View File

@ -0,0 +1,58 @@
# coding: utf-8
"""
Run the tests.
$ pip install nose (optional)
$ cd SwaggerPetstore-python
$ nosetests -v
"""
import os
import time
import unittest
import SwaggerPetstore
HOST = 'http://petstore.swagger.io/v2'
class ApiClientTests(unittest.TestCase):
def setUp(self):
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/xml', 'application/json']
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts)
self.assertEqual(accept, 'application/json')
accepts = ['text/plain', 'application/xml']
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts)
self.assertEqual(accept, 'text/plain, application/xml')
accepts = []
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts)
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/xml', 'application/json']
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json')
content_types = ['text/plain', 'application/xml']
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types)
self.assertEqual(content_type, 'text/plain')
content_types = []
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json')