added python 2.7 and python 3.4 test environments

This commit is contained in:
geekerzp 2015-05-15 14:38:06 +08:00
parent 86e48ceef8
commit d798b943f5
29 changed files with 551 additions and 662 deletions

View File

@ -70,6 +70,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
supportingFiles.add(new SupportingFile("setup.mustache", eggPackage, "setup.py"));
supportingFiles.add(new SupportingFile("swagger.mustache", invokerPackage, "swagger.py"));
supportingFiles.add(new SupportingFile("rest.mustache", invokerPackage, "rest.py"));
supportingFiles.add(new SupportingFile("util.mustache", invokerPackage, "util.py"));
supportingFiles.add(new SupportingFile("__init__package.mustache", invokerPackage, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage.replace('.', File.separatorChar), "__init__.py"));
supportingFiles.add(new SupportingFile("__init__api.mustache", apiPackage.replace('.', File.separatorChar), "__init__.py"));

View File

@ -38,5 +38,22 @@ TODO
## Tests
TODO
We use some external dependencies, multiple interpreters and code coverage analysis while running test suite.
Our Makefile handles much of this for you as long as you're running it inside of a [virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/):
```sh
$ make test
[... magically installs dependencies and runs tests on your virtualenv]
Ran 182 tests in 1.633s
OK (SKIP=6)
```
You can test in various python versions using:
```sh
$ make test-all
[... tox creates a virtualenv for every platform and runs tests inside of each]
py27: commands succeeded
py34: commands succeeded
```

View File

@ -1,15 +1,5 @@
#!/usr/bin/env python
"""Add all of the modules in the current directory to __all__"""
from __future__ import absolute_import
import os
{{#apiInfo}}{{#apis}}
from .{{classVarName}} import {{classname}}
# import apis into api package
{{#apiInfo}}{{#apis}}from .{{classVarName}} import {{classname}}
{{/apis}}{{/apiInfo}}
__all__ = []
for module in os.listdir(os.path.dirname(__file__)):
if module != '__init__.py' and module[-3:] == '.py':
__all__.append(module[:-3])

View File

@ -1,15 +1,5 @@
#!/usr/bin/env python
"""Add all of the modules in the current directory to __all__"""
from __future__ import absolute_import
import os
{{#models}}{{#model}}
from .{{classVarName}} import {{classname}}
# import models into model package
{{#models}}{{#model}}from .{{classVarName}} import {{classname}}
{{/model}}{{/models}}
__all__ = []
for module in os.listdir(os.path.dirname(__file__)):
if module != '__init__.py' and module[-3:] == '.py':
__all__.append(module[:-3])

View File

@ -1,24 +1,10 @@
#!/usr/bin/env python
"""Add all of the modules in the current directory to __all__"""
from __future__ import absolute_import
import os
# import models into package
{{#models}}{{#model}}
from .models.{{classVarName}} import {{classname}}
# import models into sdk package
{{#models}}{{#model}}from .models.{{classVarName}} import {{classname}}
{{/model}}{{/models}}
# import apis into package
{{#apiInfo}}{{#apis}}
from .apis.{{classVarName}} import {{classname}}
# import apis into sdk package
{{#apiInfo}}{{#apis}}from .apis.{{classVarName}} import {{classname}}
{{/apis}}{{/apiInfo}}
# import ApiClient
from .swagger import ApiClient
__all__ = []
for module in os.listdir(os.path.dirname(__file__)):
if module != '__init__.py' and module[-3:] == '.py':
__all__.append(module[:-3])

View File

@ -19,31 +19,36 @@ Copyright 2015 Reverb Technologies, Inc.
NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
"""
from __future__ import absolute_import
import sys
import os
# python 2 and python 3 compatibility library
from six import iteritems
from ..util import remove_none
{{#operations}}
class {{classname}}(object):
def __init__(self, api_client):
self.api_client = api_client
self.api_client = api_client
{{#operation}}
def {{nickname}}(self, {{#requiredParams}}{{paramName}}{{#defaultValue}} = None{{/defaultValue}}, {{/requiredParams}}**kwargs):
def {{nickname}}(self, {{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}**kwargs):
"""
{{{summary}}}
{{{notes}}}
{{#allParams}}
:param {{dataType}} {{paramName}}: {{{description}}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
{{#allParams}}:param {{dataType}} {{paramName}}: {{{description}}} {{#required}}(required){{/required}}{{#optional}}(optional){{/optional}}
{{/allParams}}
:return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
"""
{{#allParams}}{{#required}}
# verify the required parameter '{{paramName}}' is set
if {{paramName}} is None:
raise ValueError("Missing the required parameter `{{paramName}}` when calling `{{nickname}}`")
{{/required}}{{/allParams}}
all_params = [{{#allParams}}'{{paramName}}'{{#hasMore}}, {{/hasMore}}{{/allParams}}]
params = locals()
@ -56,16 +61,11 @@ class {{classname}}(object):
resource_path = '{{path}}'.replace('{format}', 'json')
method = '{{httpMethod}}'
path_params = dict({{#pathParams}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/pathParams}})
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict({{#queryParams}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/queryParams}})
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict({{#headerParams}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/headerParams}})
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict({{#formParams}}{{^isFile}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/isFile}}{{/formParams}})
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict({{#formParams}}{{#isFile}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/isFile}}{{/formParams}})
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict({{#pathParams}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/pathParams}}))
query_params = remove_none(dict({{#queryParams}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/queryParams}}))
header_params = remove_none(dict({{#headerParams}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/headerParams}}))
form_params = remove_none(dict({{#formParams}}{{^isFile}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/isFile}}{{/formParams}}))
files = remove_none(dict({{#formParams}}{{#isFile}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/isFile}}{{/formParams}}))
body_params = {{#bodyParam}}params.get('{{paramName}}'){{/bodyParam}}{{^bodyParam}}None{{/bodyParam}}
accepts = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]
@ -79,7 +79,14 @@ class {{classname}}(object):
response={{#returnType}}'{{returnType}}'{{/returnType}}{{^returnType}}None{{/returnType}})
{{#returnType}}
return response
{{/returnType}}
{{/operation}}
{{/returnType}}{{/operation}}
{{/operations}}
{{newline}}

View File

@ -25,7 +25,6 @@ class {{classname}}(object):
Do not edit the class manually.
"""
def __init__(self):
"""
Swagger model
@ -34,22 +33,19 @@ class {{classname}}(object):
:param dict attributeMap: The key is attribute name and the value is json key in definition.
"""
self.swagger_types = {
{{#vars}}
'{{name}}': '{{{datatype}}}'{{#hasMore}},
{{/hasMore}}
{{/vars}}{{newline}}
{{#vars}}'{{name}}': '{{{datatype}}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
}
self.attribute_map = {
{{#vars}}
'{{name}}': '{{baseName}}'{{#hasMore}},{{/hasMore}}
{{/vars}}
{{#vars}}'{{name}}': '{{baseName}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
}
{{#vars}}
{{#description}}#{{description}}
{{/description}}
self.{{name}} = None # {{{datatype}}}
{{#description}}# {{description}}{{/description}}
self.{{name}} = None # {{{datatype}}}
{{/vars}}
{{/model}}
{{/models}}

View File

@ -30,3 +30,11 @@ setup(
)
{{/hasMore}}{{/apis}}{{/apiInfo}}

View File

@ -0,0 +1,17 @@
from six import iteritems
def remove_none(obj):
if isinstance(obj, (list, tuple, set)):
return type(obj)(remove_none(x) for x in obj if x is not None)
elif isinstance(obj, dict):
return type(obj)((remove_none(k), remove_none(v))
for k, v in iteritems(obj) if k is not None and v is not None)
else:
return obj
def inspect_vars(obj):
if not hasattr(obj, '__dict__'):
return obj
else:
return {k: inspect_vars(getattr(obj, k)) for k in dir(obj)}

View File

@ -0,0 +1,35 @@
REQUIREMENTS_FILE=dev-requirements.txt
REQUIREMENTS_OUT=dev-requirements.txt.log
SETUP_OUT=*.egg-info
virtualenv:
ifndef VIRTUAL_ENV
$(error Must be run inside of a virtualenv\
http://docs.python-guide.org/en/latest/dev/virtualenvs/)
endif
setup: virtualenv $(SETUP_OUT)
$(SETUP_OUT): setup.py setup.cfg
python setup.py develop
touch $(SETUP_OUT)
$(REQUIREMENTS_OUT): $(REQUIREMENTS_FILE)
pip install -r $(REQUIREMENTS_FILE) | tee -a $(REQUIREMENTS_OUT)
python setup.py develop
clean:
find . -name "*.py[oc]" -delete
find . -name "__pycache__" -delete
rm -f $(REQUIREMENTS_OUT)
rm -rf $(SETUP_OUT)
requirements: setup $(REQUIREMENTS_OUT)
test: requirements
nosetests
test-all: requirements
tox

View File

@ -38,5 +38,21 @@ TODO
## Tests
TODO
We use some external dependencies, multiple interpreters and code coverage analysis while running test suite.
Our Makefile handles much of this for you as long as you're running it inside of a [virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/):
```sh
$ make test
[... magically installs dependencies and runs tests on your virtualenv]
Ran 182 tests in 1.633s
OK (SKIP=6)
```
You can test in various python versions using:
```sh
$ make test-all
[... tox creates a virtualenv for every platform and runs tests inside of each]
py27: commands succeeded
py34: commands succeeded
```

View File

@ -1,36 +1,16 @@
#!/usr/bin/env python
"""Add all of the modules in the current directory to __all__"""
from __future__ import absolute_import
import os
# import models into package
# import models into sdk package
from .models.user import User
from .models.category import Category
from .models.pet import Pet
from .models.tag import Tag
from .models.order import Order
# import apis into package
# import apis into sdk package
from .apis.user_api import UserApi
from .apis.pet_api import PetApi
from .apis.store_api import StoreApi
# import ApiClient
from .swagger import ApiClient
__all__ = []
for module in os.listdir(os.path.dirname(__file__)):
if module != '__init__.py' and module[-3:] == '.py':
__all__.append(module[:-3])

View File

@ -1,19 +1,7 @@
#!/usr/bin/env python
"""Add all of the modules in the current directory to __all__"""
from __future__ import absolute_import
import os
# import apis into api package
from .user_api import UserApi
from .pet_api import PetApi
from .store_api import StoreApi
__all__ = []
for module in os.listdir(os.path.dirname(__file__)):
if module != '__init__.py' and module[-3:] == '.py':
__all__.append(module[:-3])

View File

@ -19,26 +19,27 @@ Copyright 2015 Reverb Technologies, Inc.
NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
"""
from __future__ import absolute_import
import sys
import os
# python 2 and python 3 compatibility library
from six import iteritems
from ..util import remove_none
class PetApi(object):
def __init__(self, api_client):
self.api_client = api_client
self.api_client = api_client
def update_pet(self, **kwargs):
"""
Update an existing pet
:param Pet body: Pet object that needs to be added to the store (required)
:param Pet body: Pet object that needs to be added to the store
:return: None
"""
@ -55,16 +56,11 @@ class PetApi(object):
resource_path = '/pet'.replace('{format}', 'json')
method = 'PUT'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = params.get('body')
accepts = ['application/json', 'application/xml']
@ -77,15 +73,12 @@ class PetApi(object):
body=body_params, post_params=form_params, files=files,
response=None)
def add_pet(self, **kwargs):
"""
Add a new pet to the store
:param Pet body: Pet object that needs to be added to the store (required)
:param Pet body: Pet object that needs to be added to the store
:return: None
"""
@ -102,16 +95,11 @@ class PetApi(object):
resource_path = '/pet'.replace('{format}', 'json')
method = 'POST'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = params.get('body')
accepts = ['application/json', 'application/xml']
@ -124,15 +112,12 @@ class PetApi(object):
body=body_params, post_params=form_params, files=files,
response=None)
def find_pets_by_status(self, **kwargs):
"""
Finds Pets by status
Multiple status values can be provided with comma seperated strings
:param list[str] status: Status values that need to be considered for filter (required)
:param list[str] status: Status values that need to be considered for filter
:return: list[Pet]
"""
@ -149,16 +134,11 @@ class PetApi(object):
resource_path = '/pet/findByStatus'.replace('{format}', 'json')
method = 'GET'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict(status=params.get('status'))
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict(status=params.get('status')))
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -173,15 +153,12 @@ class PetApi(object):
return response
def find_pets_by_tags(self, **kwargs):
"""
Finds Pets by tags
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
:param list[str] tags: Tags to filter by (required)
:param list[str] tags: Tags to filter by
:return: list[Pet]
"""
@ -198,16 +175,11 @@ class PetApi(object):
resource_path = '/pet/findByTags'.replace('{format}', 'json')
method = 'GET'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict(tags=params.get('tags'))
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict(tags=params.get('tags')))
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -222,19 +194,20 @@ class PetApi(object):
return response
def get_pet_by_id(self, **kwargs):
def get_pet_by_id(self, pet_id, **kwargs):
"""
Find pet by ID
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
:param int pet_id: ID of pet that needs to be fetched (required)
:return: Pet
"""
# verify the required parameter 'pet_id' is set
if pet_id is None:
raise ValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`")
all_params = ['pet_id']
params = locals()
@ -247,16 +220,11 @@ class PetApi(object):
resource_path = '/pet/{petId}'.replace('{format}', 'json')
method = 'GET'
path_params = dict(petId=params.get('pet_id'))
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict(petId=params.get('pet_id')))
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -271,23 +239,22 @@ class PetApi(object):
return response
def update_pet_with_form(self, **kwargs):
def update_pet_with_form(self, pet_id, **kwargs):
"""
Updates a pet in the store with form data
:param str pet_id: ID of pet that needs to be updated (required)
:param str name: Updated name of the pet (required)
:param str status: Updated status of the pet (required)
:param str name: Updated name of the pet
:param str status: Updated status of the pet
:return: None
"""
# verify the required parameter 'pet_id' is set
if pet_id is None:
raise ValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`")
all_params = ['pet_id', 'name', 'status']
params = locals()
@ -300,16 +267,11 @@ class PetApi(object):
resource_path = '/pet/{petId}'.replace('{format}', 'json')
method = 'POST'
path_params = dict(petId=params.get('pet_id'))
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict(name=params.get('name'), status=params.get('status'))
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict(petId=params.get('pet_id')))
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict(name=params.get('name'), status=params.get('status')))
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -322,21 +284,21 @@ class PetApi(object):
body=body_params, post_params=form_params, files=files,
response=None)
def delete_pet(self, **kwargs):
def delete_pet(self, pet_id, **kwargs):
"""
Deletes a pet
:param str api_key: (required)
:param str api_key:
:param int pet_id: Pet id to delete (required)
:return: None
"""
# verify the required parameter 'pet_id' is set
if pet_id is None:
raise ValueError("Missing the required parameter `pet_id` when calling `delete_pet`")
all_params = ['api_key', 'pet_id']
params = locals()
@ -349,16 +311,11 @@ class PetApi(object):
resource_path = '/pet/{petId}'.replace('{format}', 'json')
method = 'DELETE'
path_params = dict(petId=params.get('pet_id'))
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict(api_key=params.get('api_key'))
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict(petId=params.get('pet_id')))
query_params = remove_none(dict())
header_params = remove_none(dict(api_key=params.get('api_key')))
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -371,23 +328,22 @@ class PetApi(object):
body=body_params, post_params=form_params, files=files,
response=None)
def upload_file(self, **kwargs):
def upload_file(self, pet_id, **kwargs):
"""
uploads an image
:param int pet_id: ID of pet to update (required)
:param str additional_metadata: Additional data to pass to server (required)
:param file file: file to upload (required)
:param str additional_metadata: Additional data to pass to server
:param file file: file to upload
:return: None
"""
# verify the required parameter 'pet_id' is set
if pet_id is None:
raise ValueError("Missing the required parameter `pet_id` when calling `upload_file`")
all_params = ['pet_id', 'additional_metadata', 'file']
params = locals()
@ -400,16 +356,11 @@ class PetApi(object):
resource_path = '/pet/{petId}/uploadImage'.replace('{format}', 'json')
method = 'POST'
path_params = dict(petId=params.get('pet_id'))
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict(additionalMetadata=params.get('additional_metadata'), )
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict(file=params.get('file'))
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict(petId=params.get('pet_id')))
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict(additionalMetadata=params.get('additional_metadata'), ))
files = remove_none(dict(file=params.get('file')))
body_params = None
accepts = ['application/json', 'application/xml']
@ -424,3 +375,10 @@ class PetApi(object):

View File

@ -19,17 +19,20 @@ Copyright 2015 Reverb Technologies, Inc.
NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
"""
from __future__ import absolute_import
import sys
import os
# python 2 and python 3 compatibility library
from six import iteritems
from ..util import remove_none
class StoreApi(object):
def __init__(self, api_client):
self.api_client = api_client
self.api_client = api_client
def get_inventory(self, **kwargs):
"""
@ -37,7 +40,6 @@ class StoreApi(object):
Returns a map of status codes to quantities
:return: map(String, int)
"""
@ -53,16 +55,11 @@ class StoreApi(object):
resource_path = '/store/inventory'.replace('{format}', 'json')
method = 'GET'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -77,15 +74,12 @@ class StoreApi(object):
return response
def place_order(self, **kwargs):
"""
Place an order for a pet
:param Order body: order placed for purchasing the pet (required)
:param Order body: order placed for purchasing the pet
:return: Order
"""
@ -102,16 +96,11 @@ class StoreApi(object):
resource_path = '/store/order'.replace('{format}', 'json')
method = 'POST'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = params.get('body')
accepts = ['application/json', 'application/xml']
@ -126,19 +115,20 @@ class StoreApi(object):
return response
def get_order_by_id(self, **kwargs):
def get_order_by_id(self, order_id, **kwargs):
"""
Find purchase order by ID
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
:param str order_id: ID of pet that needs to be fetched (required)
:return: Order
"""
# verify the required parameter 'order_id' is set
if order_id is None:
raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`")
all_params = ['order_id']
params = locals()
@ -151,16 +141,11 @@ class StoreApi(object):
resource_path = '/store/order/{orderId}'.replace('{format}', 'json')
method = 'GET'
path_params = dict(orderId=params.get('order_id'))
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict(orderId=params.get('order_id')))
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -175,19 +160,20 @@ class StoreApi(object):
return response
def delete_order(self, **kwargs):
def delete_order(self, order_id, **kwargs):
"""
Delete purchase order by ID
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
:param str order_id: ID of the order that needs to be deleted (required)
:return: None
"""
# verify the required parameter 'order_id' is set
if order_id is None:
raise ValueError("Missing the required parameter `order_id` when calling `delete_order`")
all_params = ['order_id']
params = locals()
@ -200,16 +186,11 @@ class StoreApi(object):
resource_path = '/store/order/{orderId}'.replace('{format}', 'json')
method = 'DELETE'
path_params = dict(orderId=params.get('order_id'))
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict(orderId=params.get('order_id')))
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -224,3 +205,10 @@ class StoreApi(object):

View File

@ -19,26 +19,27 @@ Copyright 2015 Reverb Technologies, Inc.
NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
"""
from __future__ import absolute_import
import sys
import os
# python 2 and python 3 compatibility library
from six import iteritems
from ..util import remove_none
class UserApi(object):
def __init__(self, api_client):
self.api_client = api_client
self.api_client = api_client
def create_user(self, **kwargs):
"""
Create user
This can only be done by the logged in user.
:param User body: Created user object (required)
:param User body: Created user object
:return: None
"""
@ -55,16 +56,11 @@ class UserApi(object):
resource_path = '/user'.replace('{format}', 'json')
method = 'POST'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = params.get('body')
accepts = ['application/json', 'application/xml']
@ -77,15 +73,12 @@ class UserApi(object):
body=body_params, post_params=form_params, files=files,
response=None)
def create_users_with_array_input(self, **kwargs):
"""
Creates list of users with given input array
:param list[User] body: List of user object (required)
:param list[User] body: List of user object
:return: None
"""
@ -102,16 +95,11 @@ class UserApi(object):
resource_path = '/user/createWithArray'.replace('{format}', 'json')
method = 'POST'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = params.get('body')
accepts = ['application/json', 'application/xml']
@ -124,15 +112,12 @@ class UserApi(object):
body=body_params, post_params=form_params, files=files,
response=None)
def create_users_with_list_input(self, **kwargs):
"""
Creates list of users with given input array
:param list[User] body: List of user object (required)
:param list[User] body: List of user object
:return: None
"""
@ -149,16 +134,11 @@ class UserApi(object):
resource_path = '/user/createWithList'.replace('{format}', 'json')
method = 'POST'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = params.get('body')
accepts = ['application/json', 'application/xml']
@ -171,17 +151,13 @@ class UserApi(object):
body=body_params, post_params=form_params, files=files,
response=None)
def login_user(self, **kwargs):
"""
Logs user into the system
:param str username: The user name for login (required)
:param str password: The password for login in clear text (required)
:param str username: The user name for login
:param str password: The password for login in clear text
:return: str
"""
@ -198,16 +174,11 @@ class UserApi(object):
resource_path = '/user/login'.replace('{format}', 'json')
method = 'GET'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict(username=params.get('username'), password=params.get('password'))
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict(username=params.get('username'), password=params.get('password')))
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -222,14 +193,12 @@ class UserApi(object):
return response
def logout_user(self, **kwargs):
"""
Logs out current logged in user session
:return: None
"""
@ -245,16 +214,11 @@ class UserApi(object):
resource_path = '/user/logout'.replace('{format}', 'json')
method = 'GET'
path_params = dict()
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict())
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -267,19 +231,20 @@ class UserApi(object):
body=body_params, post_params=form_params, files=files,
response=None)
def get_user_by_name(self, **kwargs):
def get_user_by_name(self, username, **kwargs):
"""
Get user by user name
:param str username: The name that needs to be fetched. Use user1 for testing. (required)
:return: User
"""
# verify the required parameter 'username' is set
if username is None:
raise ValueError("Missing the required parameter `username` when calling `get_user_by_name`")
all_params = ['username']
params = locals()
@ -292,16 +257,11 @@ class UserApi(object):
resource_path = '/user/{username}'.replace('{format}', 'json')
method = 'GET'
path_params = dict(username=params.get('username'))
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict(username=params.get('username')))
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -316,21 +276,21 @@ class UserApi(object):
return response
def update_user(self, **kwargs):
def update_user(self, username, **kwargs):
"""
Updated user
This can only be done by the logged in user.
:param str username: name that need to be deleted (required)
:param User body: Updated user object (required)
:param User body: Updated user object
:return: None
"""
# verify the required parameter 'username' is set
if username is None:
raise ValueError("Missing the required parameter `username` when calling `update_user`")
all_params = ['username', 'body']
params = locals()
@ -343,16 +303,11 @@ class UserApi(object):
resource_path = '/user/{username}'.replace('{format}', 'json')
method = 'PUT'
path_params = dict(username=params.get('username'))
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict(username=params.get('username')))
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = params.get('body')
accepts = ['application/json', 'application/xml']
@ -365,19 +320,20 @@ class UserApi(object):
body=body_params, post_params=form_params, files=files,
response=None)
def delete_user(self, **kwargs):
def delete_user(self, username, **kwargs):
"""
Delete user
This can only be done by the logged in user.
:param str username: The name that needs to be deleted (required)
:return: None
"""
# verify the required parameter 'username' is set
if username is None:
raise ValueError("Missing the required parameter `username` when calling `delete_user`")
all_params = ['username']
params = locals()
@ -390,16 +346,11 @@ class UserApi(object):
resource_path = '/user/{username}'.replace('{format}', 'json')
method = 'DELETE'
path_params = dict(username=params.get('username'))
path_params = {k: v for k, v in iteritems(path_params) if v}
query_params = dict()
query_params = {k: v for k, v in iteritems(query_params) if v}
header_params = dict()
header_params = {k: v for k, v in iteritems(header_params) if v}
form_params = dict()
form_params = {k: v for k, v in iteritems(form_params) if v}
files = dict()
files = {k: v for k, v in iteritems(files) if v}
path_params = remove_none(dict(username=params.get('username')))
query_params = remove_none(dict())
header_params = remove_none(dict())
form_params = remove_none(dict())
files = remove_none(dict())
body_params = None
accepts = ['application/json', 'application/xml']
@ -414,3 +365,10 @@ class UserApi(object):

View File

@ -1,23 +1,9 @@
#!/usr/bin/env python
"""Add all of the modules in the current directory to __all__"""
from __future__ import absolute_import
import os
# import models into model package
from .user import User
from .category import Category
from .pet import Pet
from .tag import Tag
from .order import Order
__all__ = []
for module in os.listdir(os.path.dirname(__file__)):
if module != '__init__.py' and module[-3:] == '.py':
__all__.append(module[:-3])

View File

@ -23,7 +23,6 @@ class Category(object):
Do not edit the class manually.
"""
def __init__(self):
"""
Swagger model
@ -32,26 +31,20 @@ class Category(object):
:param dict attributeMap: The key is attribute name and the value is json key in definition.
"""
self.swagger_types = {
'id': 'int',
'name': 'str'
}
self.attribute_map = {
'id': 'id',
'name': 'name'
}
self.id = None # int
self.id = None # int
self.name = None # str
self.name = None # str

View File

@ -23,7 +23,6 @@ class Order(object):
Do not edit the class manually.
"""
def __init__(self):
"""
Swagger model
@ -32,59 +31,40 @@ class Order(object):
:param dict attributeMap: The key is attribute name and the value is json key in definition.
"""
self.swagger_types = {
'id': 'int',
'pet_id': 'int',
'quantity': 'int',
'ship_date': 'DateTime',
'status': 'str',
'complete': 'bool'
}
self.attribute_map = {
'id': 'id',
'pet_id': 'petId',
'quantity': 'quantity',
'ship_date': 'shipDate',
'status': 'status',
'complete': 'complete'
}
self.id = None # int
self.id = None # int
self.pet_id = None # int
self.pet_id = None # int
self.quantity = None # int
self.quantity = None # int
self.ship_date = None # DateTime
self.ship_date = None # DateTime
#Order Status
self.status = None # str
# Order Status
self.status = None # str
self.complete = None # bool
self.complete = None # bool

View File

@ -23,7 +23,6 @@ class Pet(object):
Do not edit the class manually.
"""
def __init__(self):
"""
Swagger model
@ -32,59 +31,40 @@ class Pet(object):
:param dict attributeMap: The key is attribute name and the value is json key in definition.
"""
self.swagger_types = {
'id': 'int',
'category': 'Category',
'name': 'str',
'photo_urls': 'list[str]',
'tags': 'list[Tag]',
'status': 'str'
}
self.attribute_map = {
'id': 'id',
'category': 'category',
'name': 'name',
'photo_urls': 'photoUrls',
'tags': 'tags',
'status': 'status'
}
self.id = None # int
self.id = None # int
self.category = None # Category
self.category = None # Category
self.name = None # str
self.name = None # str
self.photo_urls = None # list[str]
self.photo_urls = None # list[str]
self.tags = None # list[Tag]
self.tags = None # list[Tag]
# pet status in the store
self.status = None # str
#pet status in the store
self.status = None # str

View File

@ -23,7 +23,6 @@ class Tag(object):
Do not edit the class manually.
"""
def __init__(self):
"""
Swagger model
@ -32,26 +31,20 @@ class Tag(object):
:param dict attributeMap: The key is attribute name and the value is json key in definition.
"""
self.swagger_types = {
'id': 'int',
'name': 'str'
}
self.attribute_map = {
'id': 'id',
'name': 'name'
}
self.id = None # int
self.id = None # int
self.name = None # str
self.name = None # str

View File

@ -23,7 +23,6 @@ class User(object):
Do not edit the class manually.
"""
def __init__(self):
"""
Swagger model
@ -32,75 +31,50 @@ class User(object):
:param dict attributeMap: The key is attribute name and the value is json key in definition.
"""
self.swagger_types = {
'id': 'int',
'username': 'str',
'first_name': 'str',
'last_name': 'str',
'email': 'str',
'password': 'str',
'phone': 'str',
'user_status': 'int'
}
self.attribute_map = {
'id': 'id',
'username': 'username',
'first_name': 'firstName',
'last_name': 'lastName',
'email': 'email',
'password': 'password',
'phone': 'phone',
'user_status': 'userStatus'
}
self.id = None # int
self.id = None # int
self.username = None # str
self.username = None # str
self.first_name = None # str
self.first_name = None # str
self.last_name = None # str
self.last_name = None # str
self.email = None # str
self.email = None # str
self.password = None # str
self.password = None # str
self.phone = None # str
self.phone = None # str
# User Status
self.user_status = None # int
#User Status
self.user_status = None # int

View File

@ -0,0 +1,17 @@
from six import iteritems
def remove_none(obj):
if isinstance(obj, (list, tuple, set)):
return type(obj)(remove_none(x) for x in obj if x is not None)
elif isinstance(obj, dict):
return type(obj)((remove_none(k), remove_none(v))
for k, v in iteritems(obj) if k is not None and v is not None)
else:
return obj
def inspect_vars(obj):
if not hasattr(obj, '__dict__'):
return obj
else:
return {k: inspect_vars(getattr(obj, k)) for k in dir(obj)}

View File

@ -0,0 +1,4 @@
nose
tox
coverage
randomize

View File

@ -26,21 +26,6 @@
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>nose-install</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>pip</executable>
<arguments>
<argument>install</argument>
<argument>nose</argument>
<argument>--user</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>nose-test</id>
<phase>integration-test</phase>
@ -48,9 +33,9 @@
<goal>exec</goal>
</goals>
<configuration>
<executable>nosetests</executable>
<executable>make</executable>
<arguments>
<argument>-v</argument>
<argument>test-all</argument>
</arguments>
</configuration>
</execution>

View File

@ -0,0 +1,10 @@
[nosetests]
logging-clear-handlers=true
verbosity=2
randomize=true
with-coverage=true
cover-package=SwaggerPetstore
cover-erase=true
[flake8]
max-line-length=99

View File

@ -30,3 +30,11 @@ setup(
)

View File

@ -31,15 +31,15 @@ class PetApiTests(unittest.TestCase):
def setUpModels(self):
self.category = SwaggerPetstore.Category()
self.category.id = 1010
self.category.id = int(time.time())
self.category.name = "dog"
self.tag = SwaggerPetstore.Tag()
self.tag.id = 1010
self.tag.id = int(time.time())
self.tag.name = "blank"
self.pet = SwaggerPetstore.Pet()
self.pet.id = 1010
self.pet.id = int(time.time())
self.pet.name = "hello kity"
self.pet.photo_urls = ["sample urls"]
self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"]
self.pet.status = "sold"
self.pet.category = self.category
self.pet.tags = [self.tag]
@ -49,48 +49,55 @@ class PetApiTests(unittest.TestCase):
self.test_file_dir = os.path.realpath(self.test_file_dir)
self.foo = os.path.join(self.test_file_dir, "foo.png")
def test_1_add_pet(self):
try:
self.pet_api.add_pet(body=self.pet)
except ErrorResponse as e:
self.fail("add_pet() raised {0} unexpectedly".format(type(e)))
def test_add_pet_and_get_pet_by_id(self):
self.pet_api.add_pet(body=self.pet)
def test_2_get_pet_by_id(self):
self.assertEqual(
dir(self.pet_api.get_pet_by_id(pet_id=self.pet.id)),
dir(self.pet)
)
fetched = self.pet_api.get_pet_by_id(pet_id=self.pet.id)
self.assertIsNotNone(fetched)
self.assertEqual(self.pet.id, fetched.id)
self.assertIsNotNone(fetched.category)
self.assertEqual(self.pet.category.name, fetched.category.name)
def test_3_update_pet(self):
try:
self.pet.name = "hello kity with updated"
self.pet_api.update_pet(body=self.pet)
except ErrorResponse as e:
self.fail("update_pet() raised {0} unexpectedly".format(type(e)))
def test_update_pet(self):
self.pet.name = "hello kity with updated"
self.pet_api.update_pet(body=self.pet)
fetched = self.pet_api.get_pet_by_id(pet_id=self.pet.id)
self.assertIsNotNone(fetched)
self.assertEqual(self.pet.id, fetched.id)
self.assertEqual(self.pet.name, fetched.name)
self.assertIsNotNone(fetched.category)
self.assertEqual(fetched.category.name, self.pet.category.name)
def test_find_pets_by_status(self):
self.pet_api.add_pet(body=self.pet)
def test_4_find_pets_by_status(self):
self.assertIn(
dir(self.pet),
list(map(dir, self.pet_api.find_pets_by_status(status=["sold"])))
self.pet.id,
list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_status(status=[self.pet.status])))
)
def test_5_find_pets_by_tags(self):
def test_find_pets_by_tags(self):
self.pet_api.add_pet(body=self.pet)
self.assertIn(
dir(self.pet),
list(map(dir, self.pet_api.find_pets_by_tags(tags=["blank"])))
self.pet.id,
list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_tags(tags=[self.tag.name])))
)
def test_6_update_pet_with_form(self):
try:
name = "hello kity with form updated"
status = "pending"
self.pet_api.update_pet_with_form(
pet_id=self.pet.id, name=name, status=status
)
except ErrorResponse as e:
self.fail("update_pet_with_form() raised {0} unexpectedly".format(type(e)))
def test_update_pet_with_form(self):
self.pet_api.add_pet(body=self.pet)
def test_7_upload_file(self):
name = "hello kity with form updated"
status = "pending"
self.pet_api.update_pet_with_form(pet_id=self.pet.id, name=name, status=status)
fetched = self.pet_api.get_pet_by_id(pet_id=self.pet.id)
self.assertEqual(self.pet.id, fetched.id)
self.assertEqual(self.pet.name, fetched.name)
self.assertEqual(self.pet.status, fetched.status)
def test_upload_file(self):
try:
additional_metadata = "special"
self.pet_api.upload_file(
@ -101,13 +108,20 @@ class PetApiTests(unittest.TestCase):
except ErrorResponse as e:
self.fail("upload_file() raised {0} unexpectedly".format(type(e)))
def test_8_delete_pet(self):
try:
api_key = "special-key"
self.pet_api.delete_pet(pet_id=self.pet.id, api_key=api_key)
except ErrorResponse as e:
self.fail("delete_pet() 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"
except ErrorResponse as e:
self.assertEqual(404, e.status)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,10 @@
[tox]
envlist = py27, py34
[testenv]
deps= -r{toxinidir}/dev-requirements.txt
commands=
nosetests \
[]
setenv =
PYTHONWARNINGS=always::DeprecationWarning