Enable cli config options for python generator

This commit is contained in:
geekerzp
2015-06-12 17:51:05 +08:00
parent 6ad3a717fe
commit a32335dfbc
28 changed files with 105 additions and 54 deletions

View File

@@ -1,6 +1,9 @@
import sys
from setuptools import setup, find_packages
NAME = "swagger_client"
VERSION = "1.0.0"
# To install the library, open a Terminal shell, then run this
@@ -15,8 +18,8 @@ from setuptools import setup, find_packages
REQUIRES = ["urllib3 >= 1.10", "six >= 1.9", "certifi"]
setup(
name="SwaggerPetstore",
version="1.0.0",
name=NAME,
version=VERSION,
description="Swagger Petstore",
author_email="apiteam@swagger.io",
url="",

View File

@@ -11,8 +11,8 @@ import os
import time
import unittest
import SwaggerPetstore
import SwaggerPetstore.configuration
import swagger_client
import swagger_client.configuration
HOST = 'http://petstore.swagger.io/v2'
@@ -20,20 +20,20 @@ HOST = 'http://petstore.swagger.io/v2'
class ApiClientTests(unittest.TestCase):
def setUp(self):
self.api_client = SwaggerPetstore.ApiClient(HOST)
self.api_client = swagger_client.ApiClient(HOST)
def test_configuration(self):
SwaggerPetstore.configuration.api_key['api_key'] = '123456'
SwaggerPetstore.configuration.api_key_prefix['api_key'] = 'PREFIX'
SwaggerPetstore.configuration.username = 'test_username'
SwaggerPetstore.configuration.password = 'test_password'
swagger_client.configuration.api_key['api_key'] = '123456'
swagger_client.configuration.api_key_prefix['api_key'] = 'PREFIX'
swagger_client.configuration.username = 'test_username'
swagger_client.configuration.password = 'test_password'
header_params = {'test1': 'value1'}
query_params = {'test2': 'value2'}
auth_settings = ['api_key', 'unknown']
# test prefix
self.assertEqual('PREFIX', SwaggerPetstore.configuration.api_key_prefix['api_key'])
self.assertEqual('PREFIX', swagger_client.configuration.api_key_prefix['api_key'])
# update parameters based on auth setting
self.api_client.update_params_for_auth(header_params, query_params, auth_settings)
@@ -44,8 +44,8 @@ class ApiClientTests(unittest.TestCase):
self.assertEqual(query_params['test2'], 'value2')
# test basic auth
self.assertEqual('test_username', SwaggerPetstore.configuration.username)
self.assertEqual('test_password', SwaggerPetstore.configuration.password)
self.assertEqual('test_username', swagger_client.configuration.username)
self.assertEqual('test_password', swagger_client.configuration.password)
def test_select_header_accept(self):
accepts = ['APPLICATION/JSON', 'APPLICATION/XML']

View File

@@ -3,7 +3,7 @@
"""
Run the tests.
$ pip install nose (optional)
$ cd SwaggerPetstore-python
$ cd swagger_client-python
$ nosetests -v
"""
@@ -11,25 +11,25 @@ import os
import time
import unittest
import SwaggerPetstore
from SwaggerPetstore.rest import ApiException
import swagger_client
from swagger_client.rest import ApiException
class ApiExceptionTests(unittest.TestCase):
def setUp(self):
self.api_client = SwaggerPetstore.ApiClient()
self.pet_api = SwaggerPetstore.PetApi(self.api_client)
self.api_client = swagger_client.ApiClient()
self.pet_api = swagger_client.PetApi(self.api_client)
self.setUpModels()
def setUpModels(self):
self.category = SwaggerPetstore.Category()
self.category = swagger_client.Category()
self.category.id = int(time.time())
self.category.name = "dog"
self.tag = SwaggerPetstore.Tag()
self.tag = swagger_client.Tag()
self.tag.id = int(time.time())
self.tag.name = "blank"
self.pet = SwaggerPetstore.Pet()
self.pet = swagger_client.Pet()
self.pet.id = int(time.time())
self.pet.name = "hello kity"
self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"]

View File

@@ -3,7 +3,7 @@
"""
Run the tests.
$ pip install nose (optional)
$ cd SwaggerPetstore-python
$ cd swagger_client-python
$ nosetests -v
"""
@@ -11,8 +11,8 @@ import os
import time
import unittest
import SwaggerPetstore
from SwaggerPetstore.rest import ApiException
import swagger_client
from swagger_client.rest import ApiException
HOST = 'http://petstore.swagger.io/v2'
@@ -20,8 +20,8 @@ HOST = 'http://petstore.swagger.io/v2'
class PetApiTests(unittest.TestCase):
def setUp(self):
self.api_client = SwaggerPetstore.ApiClient(HOST)
self.pet_api = SwaggerPetstore.PetApi(self.api_client)
self.api_client = swagger_client.ApiClient(HOST)
self.pet_api = swagger_client.PetApi(self.api_client)
self.setUpModels()
self.setUpFiles()
@@ -30,13 +30,13 @@ class PetApiTests(unittest.TestCase):
time.sleep(1)
def setUpModels(self):
self.category = SwaggerPetstore.Category()
self.category = swagger_client.Category()
self.category.id = int(time.time())
self.category.name = "dog"
self.tag = SwaggerPetstore.Tag()
self.tag = swagger_client.Tag()
self.tag.id = int(time.time())
self.tag.name = "blank"
self.pet = SwaggerPetstore.Pet()
self.pet = swagger_client.Pet()
self.pet.id = int(time.time())
self.pet.name = "hello kity"
self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"]
@@ -50,22 +50,22 @@ class PetApiTests(unittest.TestCase):
self.foo = os.path.join(self.test_file_dir, "foo.png")
def test_create_api_instance(self):
pet_api = SwaggerPetstore.PetApi()
pet_api2 = SwaggerPetstore.PetApi()
api_client3 = SwaggerPetstore.ApiClient()
pet_api = swagger_client.PetApi()
pet_api2 = swagger_client.PetApi()
api_client3 = swagger_client.ApiClient()
api_client3.user_agent = 'api client 3'
api_client4 = SwaggerPetstore.ApiClient()
api_client4 = swagger_client.ApiClient()
api_client4.user_agent = 'api client 4'
pet_api3 = SwaggerPetstore.PetApi(api_client3)
pet_api3 = swagger_client.PetApi(api_client3)
# same default api client
self.assertEqual(pet_api.api_client, pet_api2.api_client)
# confirm using the default api client in the config module
self.assertEqual(pet_api.api_client, SwaggerPetstore.configuration.api_client)
self.assertEqual(pet_api.api_client, swagger_client.configuration.api_client)
# 2 different api clients are not the same
self.assertNotEqual(api_client3, api_client4)
# customized pet api not using the default api client
self.assertNotEqual(pet_api3.api_client, SwaggerPetstore.configuration.api_client)
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)