forked from loafle/openapi-generator-original
Enable cli config options for python generator
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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:
|
||||
rm -rf $(REQUIREMENTS_OUT)
|
||||
rm -rf $(SETUP_OUT)
|
||||
rm -rf .tox
|
||||
rm -rf .coverage
|
||||
find . -name "*.py[oc]" -delete
|
||||
find . -name "__pycache__" -delete
|
||||
|
||||
requirements: setup $(REQUIREMENTS_OUT)
|
||||
|
||||
test: clean requirements
|
||||
nosetests
|
||||
|
||||
test-all: clean requirements
|
||||
tox
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
## Requirements.
|
||||
Python 2.7 and later.
|
||||
|
||||
## Setuptools
|
||||
You can install the bindings via [Setuptools](http://pypi.python.org/pypi/setuptools).
|
||||
|
||||
```sh
|
||||
python setup.py install
|
||||
```
|
||||
|
||||
Or you can install from Github via pip:
|
||||
|
||||
```sh
|
||||
pip install git+https://github.com/geekerzp/SwaggerPetstore-python.git
|
||||
```
|
||||
|
||||
To use the bindings, import the pacakge:
|
||||
|
||||
```python
|
||||
import SwaggerPetstore
|
||||
```
|
||||
|
||||
## Manual Installation
|
||||
If you do not wish to use setuptools, you can download the latest release.
|
||||
Then, to use the bindings, import the package:
|
||||
|
||||
```python
|
||||
import path.to.SwaggerPetstore-python.SwaggerPetstore
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
|
||||
TODO
|
||||
|
||||
## Documentation
|
||||
|
||||
TODO
|
||||
|
||||
## Tests
|
||||
|
||||
(Make sure you are running it inside of a [virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/))
|
||||
|
||||
You can run the tests in the current python platform:
|
||||
|
||||
```sh
|
||||
$ make test
|
||||
[... magically installs dependencies and runs tests on your virtualenv]
|
||||
Ran 7 tests in 19.289s
|
||||
|
||||
OK
|
||||
```
|
||||
or
|
||||
|
||||
```
|
||||
$ mvn integration-test -rf :PythonPetstoreClientTests
|
||||
Using 2195432783 as seed
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] BUILD SUCCESS
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Total time: 37.594 s
|
||||
[INFO] Finished at: 2015-05-16T18:00:35+08:00
|
||||
[INFO] Final Memory: 11M/156M
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
```
|
||||
If you want to run the tests in all the python platforms:
|
||||
|
||||
```sh
|
||||
$ make test-all
|
||||
[... tox creates a virtualenv for every platform and runs tests inside of each]
|
||||
py27: commands succeeded
|
||||
py34: commands succeeded
|
||||
congratulations :)
|
||||
```
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
nose
|
||||
tox
|
||||
coverage
|
||||
randomize
|
||||
57
samples/client/petstore/python/swagger_client_python/pom.xml
Normal file
57
samples/client/petstore/python/swagger_client_python/pom.xml
Normal file
@@ -0,0 +1,57 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>PythonPetstoreClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Python Swagger Petstore Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>nose-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>make</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
[nosetests]
|
||||
logging-clear-handlers=true
|
||||
verbosity=2
|
||||
randomize=true
|
||||
exe=true
|
||||
with-coverage=true
|
||||
cover-package=SwaggerPetstore
|
||||
cover-erase=true
|
||||
|
||||
[flake8]
|
||||
max-line-length=99
|
||||
@@ -0,0 +1,43 @@
|
||||
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
|
||||
# file by typing:
|
||||
#
|
||||
# python setup.py install
|
||||
#
|
||||
# You need to have the setuptools module installed.
|
||||
# Try reading the setuptools documentation:
|
||||
# http://pypi.python.org/pypi/setuptools
|
||||
|
||||
REQUIRES = ["urllib3 >= 1.10", "six >= 1.9", "certifi"]
|
||||
|
||||
setup(
|
||||
name=NAME,
|
||||
version=VERSION,
|
||||
description="Swagger Petstore",
|
||||
author_email="apiteam@swagger.io",
|
||||
url="",
|
||||
keywords=["Swagger", "Swagger Petstore"],
|
||||
install_requires=REQUIRES,
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
long_description="""\
|
||||
This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
# 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 sdk package
|
||||
from .apis.user_api import UserApi
|
||||
from .apis.pet_api import PetApi
|
||||
from .apis.store_api import StoreApi
|
||||
|
||||
# import ApiClient
|
||||
from .api_client import ApiClient
|
||||
@@ -0,0 +1,310 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""Swagger generic API client. This client handles the client-
|
||||
server communication, and is invariant across implementations. Specifics of
|
||||
the methods and models for each application are generated from the Swagger
|
||||
templates."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from . import models
|
||||
from .rest import RESTClient
|
||||
|
||||
import os
|
||||
import re
|
||||
import urllib
|
||||
import json
|
||||
import datetime
|
||||
import mimetypes
|
||||
import random
|
||||
|
||||
# python 2 and python 3 compatibility library
|
||||
from six import iteritems
|
||||
|
||||
try:
|
||||
# for python3
|
||||
from urllib.parse import quote
|
||||
except ImportError:
|
||||
# for python2
|
||||
from urllib import quote
|
||||
|
||||
from . import configuration
|
||||
|
||||
class ApiClient(object):
|
||||
"""
|
||||
Generic API client for Swagger client library builds
|
||||
|
||||
:param host: The base path for the server to call
|
||||
:param header_name: a header to pass when making calls to the API
|
||||
:param header_value: a header value to pass when making calls to the API
|
||||
"""
|
||||
def __init__(self, host=configuration.host, header_name=None, header_value=None):
|
||||
self.default_headers = {}
|
||||
if header_name is not None:
|
||||
self.default_headers[header_name] = header_value
|
||||
self.host = host
|
||||
self.cookie = None
|
||||
# Set default User-Agent.
|
||||
self.user_agent = 'Python-Swagger'
|
||||
|
||||
@property
|
||||
def user_agent(self):
|
||||
return self.default_headers['User-Agent']
|
||||
|
||||
@user_agent.setter
|
||||
def user_agent(self, value):
|
||||
self.default_headers['User-Agent'] = value
|
||||
|
||||
def set_default_header(self, header_name, header_value):
|
||||
self.default_headers[header_name] = header_value
|
||||
|
||||
def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None,
|
||||
body=None, post_params=None, files=None, response=None, auth_settings=None):
|
||||
|
||||
# headers parameters
|
||||
header_params = header_params or {}
|
||||
header_params.update(self.default_headers)
|
||||
if self.cookie:
|
||||
header_params['Cookie'] = self.cookie
|
||||
if header_params:
|
||||
header_params = self.sanitize_for_serialization(header_params)
|
||||
|
||||
# path parameters
|
||||
if path_params:
|
||||
path_params = self.sanitize_for_serialization(path_params)
|
||||
for k, v in iteritems(path_params):
|
||||
replacement = quote(str(self.to_path_value(v)))
|
||||
resource_path = resource_path.replace('{' + k + '}', replacement)
|
||||
|
||||
# query parameters
|
||||
if query_params:
|
||||
query_params = self.sanitize_for_serialization(query_params)
|
||||
query_params = {k: self.to_path_value(v) for k, v in iteritems(query_params)}
|
||||
|
||||
# post parameters
|
||||
if post_params:
|
||||
post_params = self.prepare_post_parameters(post_params, files)
|
||||
post_params = self.sanitize_for_serialization(post_params)
|
||||
|
||||
# auth setting
|
||||
self.update_params_for_auth(header_params, query_params, auth_settings)
|
||||
|
||||
# body
|
||||
if body:
|
||||
body = self.sanitize_for_serialization(body)
|
||||
|
||||
# request url
|
||||
url = self.host + resource_path
|
||||
|
||||
# perform request and return response
|
||||
response_data = self.request(method, url, query_params=query_params, headers=header_params,
|
||||
post_params=post_params, body=body)
|
||||
|
||||
# deserialize response data
|
||||
if response:
|
||||
return self.deserialize(response_data, response)
|
||||
else:
|
||||
return None
|
||||
|
||||
def to_path_value(self, obj):
|
||||
"""
|
||||
Convert a string or object to a path-friendly value
|
||||
|
||||
:param obj: object or string value
|
||||
|
||||
:return string: quoted value
|
||||
"""
|
||||
if type(obj) == list:
|
||||
return ','.join(obj)
|
||||
else:
|
||||
return str(obj)
|
||||
|
||||
def sanitize_for_serialization(self, obj):
|
||||
"""
|
||||
Sanitize an object for Request.
|
||||
|
||||
If obj is None, return None.
|
||||
If obj is str, int, float, bool, return directly.
|
||||
If obj is datetime.datetime, datetime.date convert to string in iso8601 format.
|
||||
If obj is list, santize each element in the list.
|
||||
If obj is dict, return the dict.
|
||||
If obj is swagger model, return the properties dict.
|
||||
"""
|
||||
if isinstance(obj, type(None)):
|
||||
return None
|
||||
elif isinstance(obj, (str, int, float, bool, tuple)):
|
||||
return obj
|
||||
elif isinstance(obj, list):
|
||||
return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj]
|
||||
elif isinstance(obj, (datetime.datetime, datetime.date)):
|
||||
return obj.isoformat()
|
||||
else:
|
||||
if isinstance(obj, dict):
|
||||
obj_dict = obj
|
||||
else:
|
||||
# Convert model obj to dict except attributes `swagger_types`, `attribute_map`
|
||||
# and attributes which value is not None.
|
||||
# Convert attribute name to json key in model definition for request.
|
||||
obj_dict = {obj.attribute_map[key]: val
|
||||
for key, val in iteritems(obj.__dict__)
|
||||
if key != 'swagger_types' and key != 'attribute_map' and val is not None}
|
||||
return {key: self.sanitize_for_serialization(val)
|
||||
for key, val in iteritems(obj_dict)}
|
||||
|
||||
def deserialize(self, obj, obj_class):
|
||||
"""
|
||||
Derialize a JSON string into an object.
|
||||
|
||||
:param obj: string or object to be deserialized
|
||||
:param obj_class: class literal for deserialzied object, or string of class name
|
||||
|
||||
:return object: deserialized object
|
||||
"""
|
||||
# Have to accept obj_class as string or actual type. Type could be a
|
||||
# native Python type, or one of the model classes.
|
||||
if type(obj_class) == str:
|
||||
if 'list[' in obj_class:
|
||||
match = re.match('list\[(.*)\]', obj_class)
|
||||
sub_class = match.group(1)
|
||||
return [self.deserialize(sub_obj, sub_class) for sub_obj in obj]
|
||||
|
||||
if 'dict(' in obj_class:
|
||||
match = re.match('dict\((.*), (.*)\)', obj_class)
|
||||
sub_class = match.group(2)
|
||||
return {k: self.deserialize(v, sub_class) for k, v in iteritems(obj)}
|
||||
|
||||
if obj_class in ['int', 'float', 'dict', 'list', 'str', 'bool', 'datetime', "object"]:
|
||||
obj_class = eval(obj_class)
|
||||
else: # not a native type, must be model class
|
||||
obj_class = eval('models.' + obj_class)
|
||||
|
||||
if obj_class in [int, float, dict, list, str, bool]:
|
||||
return obj_class(obj)
|
||||
elif obj_class == object:
|
||||
return object()
|
||||
elif obj_class == datetime:
|
||||
return self.__parse_string_to_datetime(obj)
|
||||
|
||||
instance = obj_class()
|
||||
|
||||
for attr, attr_type in iteritems(instance.swagger_types):
|
||||
if obj is not None and instance.attribute_map[attr] in obj and type(obj) in [list, dict]:
|
||||
value = obj[instance.attribute_map[attr]]
|
||||
if attr_type in ['str', 'int', 'float', 'bool']:
|
||||
attr_type = eval(attr_type)
|
||||
try:
|
||||
value = attr_type(value)
|
||||
except UnicodeEncodeError:
|
||||
value = unicode(value)
|
||||
except TypeError:
|
||||
value = value
|
||||
setattr(instance, attr, value)
|
||||
elif attr_type == 'datetime':
|
||||
setattr(instance, attr, self.__parse_string_to_datetime(value))
|
||||
elif 'list[' in attr_type:
|
||||
match = re.match('list\[(.*)\]', attr_type)
|
||||
sub_class = match.group(1)
|
||||
sub_values = []
|
||||
if not value:
|
||||
setattr(instance, attr, None)
|
||||
else:
|
||||
for sub_value in value:
|
||||
sub_values.append(self.deserialize(sub_value, sub_class))
|
||||
setattr(instance, attr, sub_values)
|
||||
else:
|
||||
setattr(instance, attr, self.deserialize(value, attr_type))
|
||||
|
||||
return instance
|
||||
|
||||
def __parse_string_to_datetime(self, string):
|
||||
"""
|
||||
Parse datetime in string to datetime.
|
||||
|
||||
The string should be in iso8601 datetime format.
|
||||
"""
|
||||
try:
|
||||
from dateutil.parser import parse
|
||||
return parse(string)
|
||||
except ImportError:
|
||||
return string
|
||||
|
||||
def request(self, method, url, query_params=None, headers=None, post_params=None, body=None):
|
||||
"""
|
||||
Perform http request using RESTClient.
|
||||
"""
|
||||
if method == "GET":
|
||||
return RESTClient.GET(url, query_params=query_params, headers=headers)
|
||||
elif method == "HEAD":
|
||||
return RESTClient.HEAD(url, query_params=query_params, headers=headers)
|
||||
elif method == "POST":
|
||||
return RESTClient.POST(url, headers=headers, post_params=post_params, body=body)
|
||||
elif method == "PUT":
|
||||
return RESTClient.PUT(url, headers=headers, post_params=post_params, body=body)
|
||||
elif method == "PATCH":
|
||||
return RESTClient.PATCH(url, headers=headers, post_params=post_params, body=body)
|
||||
elif method == "DELETE":
|
||||
return RESTClient.DELETE(url, query_params=query_params, headers=headers)
|
||||
else:
|
||||
raise ValueError("http method must be `GET`, `HEAD`, `POST`, `PATCH`, `PUT` or `DELETE`")
|
||||
|
||||
def prepare_post_parameters(self, post_params=None, files=None):
|
||||
params = {}
|
||||
|
||||
if post_params:
|
||||
params.update(post_params)
|
||||
|
||||
if files:
|
||||
for k, v in iteritems(files):
|
||||
if v:
|
||||
with open(v, 'rb') as f:
|
||||
filename = os.path.basename(f.name)
|
||||
filedata = f.read()
|
||||
mimetype = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
|
||||
params[k] = tuple([filename, filedata, mimetype])
|
||||
|
||||
return params
|
||||
|
||||
def select_header_accept(self, accepts):
|
||||
"""
|
||||
Return `Accept` based on an array of accepts provided
|
||||
"""
|
||||
if not accepts:
|
||||
return
|
||||
|
||||
accepts = list(map(lambda x: x.lower(), accepts))
|
||||
|
||||
if 'application/json' in accepts:
|
||||
return 'application/json'
|
||||
else:
|
||||
return ', '.join(accepts)
|
||||
|
||||
def select_header_content_type(self, content_types):
|
||||
"""
|
||||
Return `Content-Type` baseed on an array of content_types provided
|
||||
"""
|
||||
if not content_types:
|
||||
return 'application/json'
|
||||
|
||||
content_types = list(map(lambda x: x.lower(), content_types))
|
||||
|
||||
if 'application/json' in content_types:
|
||||
return 'application/json'
|
||||
else:
|
||||
return content_types[0]
|
||||
|
||||
def update_params_for_auth(self, headers, querys, auth_settings):
|
||||
"""
|
||||
Update header and query params based on authentication setting
|
||||
"""
|
||||
if not auth_settings:
|
||||
return
|
||||
|
||||
for auth in auth_settings:
|
||||
auth_setting = configuration.auth_settings().get(auth)
|
||||
if auth_setting:
|
||||
if auth_setting['in'] == 'header':
|
||||
headers[auth_setting['key']] = auth_setting['value']
|
||||
elif auth_setting['in'] == 'query':
|
||||
querys[auth_setting['key']] = auth_setting['value']
|
||||
else:
|
||||
raise ValueError('Authentication token must be in `query` or `header`')
|
||||
@@ -0,0 +1,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
# import apis into api package
|
||||
from .user_api import UserApi
|
||||
from .pet_api import PetApi
|
||||
from .store_api import StoreApi
|
||||
|
||||
@@ -0,0 +1,502 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
PetApi.py
|
||||
Copyright 2015 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
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 .. import configuration
|
||||
from ..api_client import ApiClient
|
||||
|
||||
class PetApi(object):
|
||||
|
||||
def __init__(self, api_client=None):
|
||||
if api_client:
|
||||
self.api_client = api_client
|
||||
else:
|
||||
if not configuration.api_client:
|
||||
configuration.api_client = ApiClient('http://petstore.swagger.io/v2')
|
||||
self.api_client = configuration.api_client
|
||||
|
||||
|
||||
def update_pet(self, **kwargs):
|
||||
"""
|
||||
Update an existing pet
|
||||
|
||||
|
||||
:param Pet body: Pet object that needs to be added to the store
|
||||
|
||||
:return: None
|
||||
"""
|
||||
|
||||
all_params = ['body']
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method update_pet" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/pet'.replace('{format}', 'json')
|
||||
method = 'PUT'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
if 'body' in params:
|
||||
body_params = params['body']
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type(['application/json', 'application/xml'])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['petstore_auth']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
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
|
||||
|
||||
:return: None
|
||||
"""
|
||||
|
||||
all_params = ['body']
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method add_pet" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/pet'.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
if 'body' in params:
|
||||
body_params = params['body']
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type(['application/json', 'application/xml'])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['petstore_auth']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
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
|
||||
|
||||
:return: list[Pet]
|
||||
"""
|
||||
|
||||
all_params = ['status']
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method find_pets_by_status" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/pet/findByStatus'.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
if 'status' in params:
|
||||
query_params['status'] = params['status']
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['petstore_auth']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response='list[Pet]', auth_settings=auth_settings)
|
||||
|
||||
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
|
||||
|
||||
:return: list[Pet]
|
||||
"""
|
||||
|
||||
all_params = ['tags']
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method find_pets_by_tags" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/pet/findByTags'.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
if 'tags' in params:
|
||||
query_params['tags'] = params['tags']
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['petstore_auth']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response='list[Pet]', auth_settings=auth_settings)
|
||||
|
||||
return response
|
||||
|
||||
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()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method get_pet_by_id" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/pet/{petId}'.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
path_params = {}
|
||||
|
||||
if 'pet_id' in params:
|
||||
path_params['petId'] = params['pet_id']
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['api_key', 'petstore_auth']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response='Pet', auth_settings=auth_settings)
|
||||
|
||||
return response
|
||||
|
||||
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
|
||||
: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()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method update_pet_with_form" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/pet/{petId}'.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
path_params = {}
|
||||
|
||||
if 'pet_id' in params:
|
||||
path_params['petId'] = params['pet_id']
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
if 'name' in params:
|
||||
form_params['name'] = params['name']
|
||||
|
||||
if 'status' in params:
|
||||
form_params['status'] = params['status']
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type(['application/x-www-form-urlencoded'])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['petstore_auth']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
def delete_pet(self, pet_id, **kwargs):
|
||||
"""
|
||||
Deletes a pet
|
||||
|
||||
|
||||
: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()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method delete_pet" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/pet/{petId}'.replace('{format}', 'json')
|
||||
method = 'DELETE'
|
||||
|
||||
path_params = {}
|
||||
|
||||
if 'pet_id' in params:
|
||||
path_params['petId'] = params['pet_id']
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
if 'api_key' in params:
|
||||
header_params['api_key'] = params['api_key']
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['petstore_auth']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
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
|
||||
: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()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method upload_file" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/pet/{petId}/uploadImage'.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
path_params = {}
|
||||
|
||||
if 'pet_id' in params:
|
||||
path_params['petId'] = params['pet_id']
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
if 'additional_metadata' in params:
|
||||
form_params['additionalMetadata'] = params['additional_metadata']
|
||||
|
||||
if 'file' in params:
|
||||
files['file'] = params['file']
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type(['multipart/form-data'])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['petstore_auth']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
StoreApi.py
|
||||
Copyright 2015 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
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 .. import configuration
|
||||
from ..api_client import ApiClient
|
||||
|
||||
class StoreApi(object):
|
||||
|
||||
def __init__(self, api_client=None):
|
||||
if api_client:
|
||||
self.api_client = api_client
|
||||
else:
|
||||
if not configuration.api_client:
|
||||
configuration.api_client = ApiClient('http://petstore.swagger.io/v2')
|
||||
self.api_client = configuration.api_client
|
||||
|
||||
|
||||
def get_inventory(self, **kwargs):
|
||||
"""
|
||||
Returns pet inventories by status
|
||||
Returns a map of status codes to quantities
|
||||
|
||||
|
||||
:return: dict(str, int)
|
||||
"""
|
||||
|
||||
all_params = []
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method get_inventory" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/store/inventory'.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['api_key']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response='dict(str, int)', auth_settings=auth_settings)
|
||||
|
||||
return response
|
||||
|
||||
def place_order(self, **kwargs):
|
||||
"""
|
||||
Place an order for a pet
|
||||
|
||||
|
||||
:param Order body: order placed for purchasing the pet
|
||||
|
||||
:return: Order
|
||||
"""
|
||||
|
||||
all_params = ['body']
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method place_order" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/store/order'.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
if 'body' in params:
|
||||
body_params = params['body']
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response='Order', auth_settings=auth_settings)
|
||||
|
||||
return response
|
||||
|
||||
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()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method get_order_by_id" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/store/order/{orderId}'.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
path_params = {}
|
||||
|
||||
if 'order_id' in params:
|
||||
path_params['orderId'] = params['order_id']
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response='Order', auth_settings=auth_settings)
|
||||
|
||||
return response
|
||||
|
||||
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()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method delete_order" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/store/order/{orderId}'.replace('{format}', 'json')
|
||||
method = 'DELETE'
|
||||
|
||||
path_params = {}
|
||||
|
||||
if 'order_id' in params:
|
||||
path_params['orderId'] = params['order_id']
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,480 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
UserApi.py
|
||||
Copyright 2015 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
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 .. import configuration
|
||||
from ..api_client import ApiClient
|
||||
|
||||
class UserApi(object):
|
||||
|
||||
def __init__(self, api_client=None):
|
||||
if api_client:
|
||||
self.api_client = api_client
|
||||
else:
|
||||
if not configuration.api_client:
|
||||
configuration.api_client = ApiClient('http://petstore.swagger.io/v2')
|
||||
self.api_client = configuration.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
|
||||
|
||||
:return: None
|
||||
"""
|
||||
|
||||
all_params = ['body']
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method create_user" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/user'.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
if 'body' in params:
|
||||
body_params = params['body']
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
def create_users_with_array_input(self, **kwargs):
|
||||
"""
|
||||
Creates list of users with given input array
|
||||
|
||||
|
||||
:param list[User] body: List of user object
|
||||
|
||||
:return: None
|
||||
"""
|
||||
|
||||
all_params = ['body']
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method create_users_with_array_input" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/user/createWithArray'.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
if 'body' in params:
|
||||
body_params = params['body']
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
def create_users_with_list_input(self, **kwargs):
|
||||
"""
|
||||
Creates list of users with given input array
|
||||
|
||||
|
||||
:param list[User] body: List of user object
|
||||
|
||||
:return: None
|
||||
"""
|
||||
|
||||
all_params = ['body']
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method create_users_with_list_input" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/user/createWithList'.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
if 'body' in params:
|
||||
body_params = params['body']
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
def login_user(self, **kwargs):
|
||||
"""
|
||||
Logs user into the system
|
||||
|
||||
|
||||
:param str username: The user name for login
|
||||
:param str password: The password for login in clear text
|
||||
|
||||
:return: str
|
||||
"""
|
||||
|
||||
all_params = ['username', 'password']
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method login_user" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/user/login'.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
if 'username' in params:
|
||||
query_params['username'] = params['username']
|
||||
|
||||
if 'password' in params:
|
||||
query_params['password'] = params['password']
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response='str', auth_settings=auth_settings)
|
||||
|
||||
return response
|
||||
|
||||
def logout_user(self, **kwargs):
|
||||
"""
|
||||
Logs out current logged in user session
|
||||
|
||||
|
||||
|
||||
:return: None
|
||||
"""
|
||||
|
||||
all_params = []
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method logout_user" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/user/logout'.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
path_params = {}
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
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()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method get_user_by_name" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/user/{username}'.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
path_params = {}
|
||||
|
||||
if 'username' in params:
|
||||
path_params['username'] = params['username']
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response='User', auth_settings=auth_settings)
|
||||
|
||||
return response
|
||||
|
||||
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
|
||||
|
||||
: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()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method update_user" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/user/{username}'.replace('{format}', 'json')
|
||||
method = 'PUT'
|
||||
|
||||
path_params = {}
|
||||
|
||||
if 'username' in params:
|
||||
path_params['username'] = params['username']
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
if 'body' in params:
|
||||
body_params = params['body']
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
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()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
if key not in all_params:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method delete_user" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resource_path = '/user/{username}'.replace('{format}', 'json')
|
||||
method = 'DELETE'
|
||||
|
||||
path_params = {}
|
||||
|
||||
if 'username' in params:
|
||||
path_params['username'] = params['username']
|
||||
|
||||
query_params = {}
|
||||
|
||||
header_params = {}
|
||||
|
||||
form_params = {}
|
||||
files = {}
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = []
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
response=None, auth_settings=auth_settings)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
from __future__ import absolute_import
|
||||
import base64
|
||||
import urllib3
|
||||
|
||||
def get_api_key_with_prefix(key):
|
||||
global api_key
|
||||
global api_key_prefix
|
||||
|
||||
if api_key.get(key) and api_key_prefix.get(key):
|
||||
return api_key_prefix[key] + ' ' + api_key[key]
|
||||
elif api_key.get(key):
|
||||
return api_key[key]
|
||||
|
||||
def get_basic_auth_token():
|
||||
global username
|
||||
global password
|
||||
|
||||
return urllib3.util.make_headers(basic_auth=username + ':' + password).get('authorization')
|
||||
|
||||
def auth_settings():
|
||||
return {
|
||||
'api_key': {
|
||||
'type': 'api_key',
|
||||
'in': 'header',
|
||||
'key': 'api_key',
|
||||
'value': get_api_key_with_prefix('api_key')
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
# Default Base url
|
||||
host = "http://petstore.swagger.io/v2"
|
||||
|
||||
# Default api client
|
||||
api_client = None
|
||||
|
||||
# Authentication settings
|
||||
|
||||
api_key = {}
|
||||
api_key_prefix = {}
|
||||
username = ''
|
||||
password = ''
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
# 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
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Copyright 2015 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
class Category(object):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Swagger model
|
||||
|
||||
:param dict swaggerTypes: The key is attribute name and the value is attribute type.
|
||||
: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.name = None # str
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
properties = []
|
||||
for p in self.__dict__:
|
||||
if p != 'swaggerTypes' and p != 'attributeMap':
|
||||
properties.append('{prop}={val!r}'.format(prop=p, val=self.__dict__[p]))
|
||||
|
||||
return '<{name} {props}>'.format(name=__name__, props=' '.join(properties))
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Copyright 2015 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
class Order(object):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Swagger model
|
||||
|
||||
:param dict swaggerTypes: The key is attribute name and the value is attribute type.
|
||||
: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.pet_id = None # int
|
||||
|
||||
|
||||
self.quantity = None # int
|
||||
|
||||
|
||||
self.ship_date = None # DateTime
|
||||
|
||||
# Order Status
|
||||
self.status = None # str
|
||||
|
||||
|
||||
self.complete = None # bool
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
properties = []
|
||||
for p in self.__dict__:
|
||||
if p != 'swaggerTypes' and p != 'attributeMap':
|
||||
properties.append('{prop}={val!r}'.format(prop=p, val=self.__dict__[p]))
|
||||
|
||||
return '<{name} {props}>'.format(name=__name__, props=' '.join(properties))
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Copyright 2015 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
class Pet(object):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Swagger model
|
||||
|
||||
:param dict swaggerTypes: The key is attribute name and the value is attribute type.
|
||||
: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.category = None # Category
|
||||
|
||||
|
||||
self.name = None # str
|
||||
|
||||
|
||||
self.photo_urls = None # list[str]
|
||||
|
||||
|
||||
self.tags = None # list[Tag]
|
||||
|
||||
# pet status in the store
|
||||
self.status = None # str
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
properties = []
|
||||
for p in self.__dict__:
|
||||
if p != 'swaggerTypes' and p != 'attributeMap':
|
||||
properties.append('{prop}={val!r}'.format(prop=p, val=self.__dict__[p]))
|
||||
|
||||
return '<{name} {props}>'.format(name=__name__, props=' '.join(properties))
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Copyright 2015 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
class Tag(object):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Swagger model
|
||||
|
||||
:param dict swaggerTypes: The key is attribute name and the value is attribute type.
|
||||
: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.name = None # str
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
properties = []
|
||||
for p in self.__dict__:
|
||||
if p != 'swaggerTypes' and p != 'attributeMap':
|
||||
properties.append('{prop}={val!r}'.format(prop=p, val=self.__dict__[p]))
|
||||
|
||||
return '<{name} {props}>'.format(name=__name__, props=' '.join(properties))
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Copyright 2015 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
class User(object):
|
||||
"""
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Swagger model
|
||||
|
||||
:param dict swaggerTypes: The key is attribute name and the value is attribute type.
|
||||
: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.username = None # str
|
||||
|
||||
|
||||
self.first_name = None # str
|
||||
|
||||
|
||||
self.last_name = None # str
|
||||
|
||||
|
||||
self.email = None # str
|
||||
|
||||
|
||||
self.password = None # str
|
||||
|
||||
|
||||
self.phone = None # str
|
||||
|
||||
# User Status
|
||||
self.user_status = None # int
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
properties = []
|
||||
for p in self.__dict__:
|
||||
if p != 'swaggerTypes' and p != 'attributeMap':
|
||||
properties.append('{prop}={val!r}'.format(prop=p, val=self.__dict__[p]))
|
||||
|
||||
return '<{name} {props}>'.format(name=__name__, props=' '.join(properties))
|
||||
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Credit: this file (rest.py) is modified based on rest.py in Dropbox Python SDK:
|
||||
https://www.dropbox.com/developers/core/sdks/python
|
||||
"""
|
||||
|
||||
import sys
|
||||
import io
|
||||
import json
|
||||
import ssl
|
||||
import certifi
|
||||
|
||||
# python 2 and python 3 compatibility library
|
||||
from six import iteritems
|
||||
|
||||
try:
|
||||
import urllib3
|
||||
except ImportError:
|
||||
raise ImportError('Swagger python client requires urllib3.')
|
||||
|
||||
try:
|
||||
# for python3
|
||||
from urllib.parse import urlencode
|
||||
except ImportError:
|
||||
# for python2
|
||||
from urllib import urlencode
|
||||
|
||||
|
||||
class RESTResponse(io.IOBase):
|
||||
|
||||
def __init__(self, resp):
|
||||
self.urllib3_response = resp
|
||||
self.status = resp.status
|
||||
self.reason = resp.reason
|
||||
self.data = resp.data
|
||||
|
||||
def getheaders(self):
|
||||
"""
|
||||
Returns a dictionary of the response headers.
|
||||
"""
|
||||
return self.urllib3_response.getheaders()
|
||||
|
||||
def getheader(self, name, default=None):
|
||||
"""
|
||||
Returns a given response header.
|
||||
"""
|
||||
return self.urllib3_response.getheader(name, default)
|
||||
|
||||
class RESTClientObject(object):
|
||||
|
||||
def __init__(self, pools_size=4):
|
||||
# http pool manager
|
||||
self.pool_manager = urllib3.PoolManager(
|
||||
num_pools=pools_size
|
||||
)
|
||||
|
||||
# https pool manager
|
||||
# certificates validated using Mozilla’s root certificates
|
||||
self.ssl_pool_manager = urllib3.PoolManager(
|
||||
num_pools=pools_size,
|
||||
cert_reqs=ssl.CERT_REQUIRED,
|
||||
ca_certs=certifi.where()
|
||||
)
|
||||
|
||||
def agent(self, url):
|
||||
"""
|
||||
Return proper pool manager for the http\https schemes.
|
||||
"""
|
||||
url = urllib3.util.url.parse_url(url)
|
||||
scheme = url.scheme
|
||||
if scheme == 'https':
|
||||
return self.ssl_pool_manager
|
||||
else:
|
||||
return self.pool_manager
|
||||
|
||||
def request(self, method, url, query_params=None, headers=None,
|
||||
body=None, post_params=None):
|
||||
"""
|
||||
:param method: http request method
|
||||
:param url: http request url
|
||||
:param query_params: query parameters in the url
|
||||
:param headers: http request headers
|
||||
:param body: request json body, for `application/json`
|
||||
:param post_params: request post parameters, `application/x-www-form-urlencode`
|
||||
and `multipart/form-data`
|
||||
"""
|
||||
method = method.upper()
|
||||
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH']
|
||||
|
||||
if post_params and body:
|
||||
raise ValueError("body parameter cannot be used with post_params parameter.")
|
||||
|
||||
post_params = post_params or {}
|
||||
headers = headers or {}
|
||||
|
||||
if 'Content-Type' not in headers:
|
||||
headers['Content-Type'] = 'application/json'
|
||||
|
||||
# For `POST`, `PUT`, `PATCH`
|
||||
if method in ['POST', 'PUT', 'PATCH']:
|
||||
if query_params:
|
||||
url += '?' + urlencode(query_params)
|
||||
if headers['Content-Type'] == 'application/json':
|
||||
r = self.agent(url).request(method, url,
|
||||
body=json.dumps(body),
|
||||
headers=headers)
|
||||
if headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
||||
r = self.agent(url).request(method, url,
|
||||
fields=post_params,
|
||||
encode_multipart=False,
|
||||
headers=headers)
|
||||
if headers['Content-Type'] == 'multipart/form-data':
|
||||
# must del headers['Content-Type'], or the correct Content-Type
|
||||
# which generated by urllib3 will be overwritten.
|
||||
del headers['Content-Type']
|
||||
r = self.agent(url).request(method, url,
|
||||
fields=post_params,
|
||||
encode_multipart=True,
|
||||
headers=headers)
|
||||
# For `GET`, `HEAD`, `DELETE`
|
||||
else:
|
||||
r = self.agent(url).request(method, url,
|
||||
fields=query_params,
|
||||
headers=headers)
|
||||
r = RESTResponse(r)
|
||||
|
||||
if r.status not in range(200, 206):
|
||||
raise ApiException(r)
|
||||
|
||||
return self.process_response(r)
|
||||
|
||||
def process_response(self, response):
|
||||
# In the python 3, the response.data is bytes.
|
||||
# we need to decode it to string.
|
||||
if sys.version_info > (3,):
|
||||
data = response.data.decode('utf8')
|
||||
else:
|
||||
data = response.data
|
||||
try:
|
||||
resp = json.loads(data)
|
||||
except ValueError:
|
||||
resp = data
|
||||
|
||||
return resp
|
||||
|
||||
def GET(self, url, headers=None, query_params=None):
|
||||
return self.request("GET", url, headers=headers, query_params=query_params)
|
||||
|
||||
def HEAD(self, url, headers=None, query_params=None):
|
||||
return self.request("HEAD", url, headers=headers, query_params=query_params)
|
||||
|
||||
def DELETE(self, url, headers=None, query_params=None):
|
||||
return self.request("DELETE", url, headers=headers, query_params=query_params)
|
||||
|
||||
def POST(self, url, headers=None, post_params=None, body=None):
|
||||
return self.request("POST", url, headers=headers, post_params=post_params, body=body)
|
||||
|
||||
def PUT(self, url, headers=None, post_params=None, body=None):
|
||||
return self.request("PUT", url, headers=headers, post_params=post_params, body=body)
|
||||
|
||||
def PATCH(self, url, headers=None, post_params=None, body=None):
|
||||
return self.request("PATCH", url, headers=headers, post_params=post_params, body=body)
|
||||
|
||||
|
||||
class ApiException(Exception):
|
||||
"""
|
||||
Non-2xx HTTP response
|
||||
"""
|
||||
|
||||
def __init__(self, http_resp):
|
||||
self.status = http_resp.status
|
||||
self.reason = http_resp.reason
|
||||
self.body = http_resp.data
|
||||
self.headers = http_resp.getheaders()
|
||||
|
||||
# In the python 3, the self.body is bytes.
|
||||
# we need to decode it to string.
|
||||
if sys.version_info > (3,):
|
||||
data = self.body.decode('utf8')
|
||||
else:
|
||||
data = self.body
|
||||
|
||||
try:
|
||||
self.body = json.loads(data)
|
||||
except ValueError:
|
||||
self.body = data
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
Custom error response messages
|
||||
"""
|
||||
return "({0})\n"\
|
||||
"Reason: {1}\n"\
|
||||
"HTTP response headers: {2}\n"\
|
||||
"HTTP response body: {3}\n".\
|
||||
format(self.status, self.reason, self.headers, self.body)
|
||||
|
||||
class RESTClient(object):
|
||||
"""
|
||||
A class with all class methods to perform JSON requests.
|
||||
"""
|
||||
|
||||
IMPL = RESTClientObject()
|
||||
|
||||
@classmethod
|
||||
def request(cls, *n, **kw):
|
||||
"""
|
||||
Perform a REST request and parse the response.
|
||||
"""
|
||||
return cls.IMPL.request(*n, **kw)
|
||||
|
||||
@classmethod
|
||||
def GET(cls, *n, **kw):
|
||||
"""
|
||||
Perform a GET request using `RESTClient.request()`.
|
||||
"""
|
||||
return cls.IMPL.GET(*n, **kw)
|
||||
|
||||
@classmethod
|
||||
def HEAD(cls, *n, **kw):
|
||||
"""
|
||||
Perform a HEAD request using `RESTClient.request()`.
|
||||
"""
|
||||
return cls.IMPL.GET(*n, **kw)
|
||||
|
||||
@classmethod
|
||||
def POST(cls, *n, **kw):
|
||||
"""
|
||||
Perform a POST request using `RESTClient.request()`
|
||||
"""
|
||||
return cls.IMPL.POST(*n, **kw)
|
||||
|
||||
@classmethod
|
||||
def PUT(cls, *n, **kw):
|
||||
"""
|
||||
Perform a PUT request using `RESTClient.request()`
|
||||
"""
|
||||
return cls.IMPL.PUT(*n, **kw)
|
||||
|
||||
@classmethod
|
||||
def PATCH(cls, *n, **kw):
|
||||
"""
|
||||
Perform a PATCH request using `RESTClient.request()`
|
||||
"""
|
||||
return cls.IMPL.PATCH(*n, **kw)
|
||||
|
||||
@classmethod
|
||||
def DELETE(cls, *n, **kw):
|
||||
"""
|
||||
Perform a DELETE request using `RESTClient.request()`
|
||||
"""
|
||||
return cls.IMPL.DELETE(*n, **kw)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
@@ -0,0 +1,133 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Run the tests.
|
||||
$ pip install nose (optional)
|
||||
$ cd SwaggerPetstore-python
|
||||
$ nosetests -v
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import swagger_client
|
||||
import swagger_client.configuration
|
||||
|
||||
HOST = 'http://petstore.swagger.io/v2'
|
||||
|
||||
|
||||
class ApiClientTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.api_client = swagger_client.ApiClient(HOST)
|
||||
|
||||
def test_configuration(self):
|
||||
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', 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)
|
||||
|
||||
# test api key auth
|
||||
self.assertEqual(header_params['test1'], 'value1')
|
||||
self.assertEqual(header_params['api_key'], 'PREFIX 123456')
|
||||
self.assertEqual(query_params['test2'], 'value2')
|
||||
|
||||
# test basic auth
|
||||
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']
|
||||
accept = self.api_client.select_header_accept(accepts)
|
||||
self.assertEqual(accept, 'application/json')
|
||||
|
||||
accepts = ['application/json', 'application/xml']
|
||||
accept = self.api_client.select_header_accept(accepts)
|
||||
self.assertEqual(accept, 'application/json')
|
||||
|
||||
accepts = ['application/xml', 'application/json']
|
||||
accept = self.api_client.select_header_accept(accepts)
|
||||
self.assertEqual(accept, 'application/json')
|
||||
|
||||
accepts = ['text/plain', 'application/xml']
|
||||
accept = self.api_client.select_header_accept(accepts)
|
||||
self.assertEqual(accept, 'text/plain, application/xml')
|
||||
|
||||
accepts = []
|
||||
accept = self.api_client.select_header_accept(accepts)
|
||||
self.assertEqual(accept, None)
|
||||
|
||||
def test_select_header_content_type(self):
|
||||
content_types = ['APPLICATION/JSON', 'APPLICATION/XML']
|
||||
content_type = self.api_client.select_header_content_type(content_types)
|
||||
self.assertEqual(content_type, 'application/json')
|
||||
|
||||
content_types = ['application/json', 'application/xml']
|
||||
content_type = self.api_client.select_header_content_type(content_types)
|
||||
self.assertEqual(content_type, 'application/json')
|
||||
|
||||
content_types = ['application/xml', 'application/json']
|
||||
content_type = self.api_client.select_header_content_type(content_types)
|
||||
self.assertEqual(content_type, 'application/json')
|
||||
|
||||
content_types = ['text/plain', 'application/xml']
|
||||
content_type = self.api_client.select_header_content_type(content_types)
|
||||
self.assertEqual(content_type, 'text/plain')
|
||||
|
||||
content_types = []
|
||||
content_type = self.api_client.select_header_content_type(content_types)
|
||||
self.assertEqual(content_type, 'application/json')
|
||||
|
||||
def test_deserialize_to_dict(self):
|
||||
# dict(str, Pet)
|
||||
json = {
|
||||
'pet': {
|
||||
"id": 0,
|
||||
"category": {
|
||||
"id": 0,
|
||||
"name": "string"
|
||||
},
|
||||
"name": "doggie",
|
||||
"photoUrls": [
|
||||
"string"
|
||||
],
|
||||
"tags": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "string"
|
||||
}
|
||||
],
|
||||
"status": "available"
|
||||
}
|
||||
}
|
||||
|
||||
data = self.api_client.deserialize(json, 'dict(str, Pet)')
|
||||
self.assertTrue(isinstance(data, dict))
|
||||
self.assertTrue(isinstance(data['pet'], SwaggerPetstore.Pet))
|
||||
|
||||
# dict(str, int)
|
||||
json = {
|
||||
'integer': 1
|
||||
}
|
||||
|
||||
data = self.api_client.deserialize(json, 'dict(str, int)')
|
||||
self.assertTrue(isinstance(data, dict))
|
||||
self.assertTrue(isinstance(data['integer'], int))
|
||||
|
||||
def test_deserialize_to_object(self):
|
||||
data = self.api_client.deserialize("", "object")
|
||||
self.assertTrue(type(data) == object)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Run the tests.
|
||||
$ pip install nose (optional)
|
||||
$ cd swagger_client-python
|
||||
$ nosetests -v
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import swagger_client
|
||||
from swagger_client.rest import ApiException
|
||||
|
||||
|
||||
class ApiExceptionTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.api_client = swagger_client.ApiClient()
|
||||
self.pet_api = swagger_client.PetApi(self.api_client)
|
||||
self.setUpModels()
|
||||
|
||||
def setUpModels(self):
|
||||
self.category = swagger_client.Category()
|
||||
self.category.id = int(time.time())
|
||||
self.category.name = "dog"
|
||||
self.tag = swagger_client.Tag()
|
||||
self.tag.id = int(time.time())
|
||||
self.tag.name = "blank"
|
||||
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"]
|
||||
self.pet.status = "sold"
|
||||
self.pet.category = self.category
|
||||
self.pet.tags = [self.tag]
|
||||
|
||||
def tearDown(self):
|
||||
time.sleep(1)
|
||||
|
||||
def test_404_error(self):
|
||||
self.pet_api.add_pet(body=self.pet)
|
||||
self.pet_api.delete_pet(pet_id=self.pet.id)
|
||||
|
||||
with self.assertRaisesRegexp(ApiException, "Pet not found"):
|
||||
self.pet_api.get_pet_by_id(pet_id=self.pet.id)
|
||||
|
||||
try:
|
||||
self.pet_api.get_pet_by_id(pet_id=self.pet.id)
|
||||
except ApiException as e:
|
||||
self.assertEqual(e.status, 404)
|
||||
self.assertEqual(e.reason, "Not Found")
|
||||
self.assertDictEqual(e.body, {'message': 'Pet not found', 'code': 1, 'type': 'error'})
|
||||
|
||||
def test_500_error(self):
|
||||
self.pet_api.add_pet(body=self.pet)
|
||||
|
||||
with self.assertRaisesRegexp(ApiException, "Internal Server Error"):
|
||||
self.pet_api.upload_file(
|
||||
pet_id=self.pet.id,
|
||||
additional_metadata="special",
|
||||
file=None
|
||||
)
|
||||
|
||||
try:
|
||||
self.pet_api.upload_file(
|
||||
pet_id=self.pet.id,
|
||||
additional_metadata="special",
|
||||
file=None
|
||||
)
|
||||
except ApiException as e:
|
||||
self.assertEqual(e.status, 500)
|
||||
self.assertEqual(e.reason, "Internal Server Error")
|
||||
self.assertRegexpMatches(e.body, "Error 500 Internal Server Error")
|
||||
@@ -0,0 +1,147 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
Run the tests.
|
||||
$ pip install nose (optional)
|
||||
$ cd swagger_client-python
|
||||
$ nosetests -v
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import swagger_client
|
||||
from swagger_client.rest import ApiException
|
||||
|
||||
HOST = 'http://petstore.swagger.io/v2'
|
||||
|
||||
|
||||
class PetApiTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.api_client = swagger_client.ApiClient(HOST)
|
||||
self.pet_api = swagger_client.PetApi(self.api_client)
|
||||
self.setUpModels()
|
||||
self.setUpFiles()
|
||||
|
||||
def tearDown(self):
|
||||
# sleep 1 sec between two every 2 tests
|
||||
time.sleep(1)
|
||||
|
||||
def setUpModels(self):
|
||||
self.category = swagger_client.Category()
|
||||
self.category.id = int(time.time())
|
||||
self.category.name = "dog"
|
||||
self.tag = swagger_client.Tag()
|
||||
self.tag.id = int(time.time())
|
||||
self.tag.name = "blank"
|
||||
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"]
|
||||
self.pet.status = "sold"
|
||||
self.pet.category = self.category
|
||||
self.pet.tags = [self.tag]
|
||||
|
||||
def setUpFiles(self):
|
||||
self.test_file_dir = os.path.join(os.path.dirname(__file__), "..", "testfiles")
|
||||
self.test_file_dir = os.path.realpath(self.test_file_dir)
|
||||
self.foo = os.path.join(self.test_file_dir, "foo.png")
|
||||
|
||||
def test_create_api_instance(self):
|
||||
pet_api = swagger_client.PetApi()
|
||||
pet_api2 = swagger_client.PetApi()
|
||||
api_client3 = swagger_client.ApiClient()
|
||||
api_client3.user_agent = 'api client 3'
|
||||
api_client4 = swagger_client.ApiClient()
|
||||
api_client4.user_agent = 'api client 4'
|
||||
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, 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, 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_add_pet_and_get_pet_by_id(self):
|
||||
self.pet_api.add_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.assertIsNotNone(fetched.category)
|
||||
self.assertEqual(self.pet.category.name, fetched.category.name)
|
||||
|
||||
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)
|
||||
|
||||
self.assertIn(
|
||||
self.pet.id,
|
||||
list(map(lambda x: getattr(x, 'id'), self.pet_api.find_pets_by_status(status=[self.pet.status])))
|
||||
)
|
||||
|
||||
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])))
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
fetched = self.pet_api.get_pet_by_id(pet_id=self.pet.id)
|
||||
self.assertEqual(self.pet.id, fetched.id)
|
||||
self.assertEqual(name, fetched.name)
|
||||
self.assertEqual(status, fetched.status)
|
||||
|
||||
def test_upload_file(self):
|
||||
try:
|
||||
additional_metadata = "special"
|
||||
self.pet_api.upload_file(
|
||||
pet_id=self.pet.id,
|
||||
additional_metadata=additional_metadata,
|
||||
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"
|
||||
except ApiException as e:
|
||||
self.assertEqual(404, e.status)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
10
samples/client/petstore/python/swagger_client_python/tox.ini
Normal file
10
samples/client/petstore/python/swagger_client_python/tox.ini
Normal file
@@ -0,0 +1,10 @@
|
||||
[tox]
|
||||
envlist = py27, py34
|
||||
|
||||
[testenv]
|
||||
deps= -r{toxinidir}/dev-requirements.txt
|
||||
commands=
|
||||
nosetests \
|
||||
[]
|
||||
setenv =
|
||||
PYTHONWARNINGS=always::DeprecationWarning
|
||||
Reference in New Issue
Block a user