forked from loafle/openapi-generator-original
moved to client folder
This commit is contained in:
parent
2f93e37645
commit
236a9697ad
@ -1,16 +0,0 @@
|
||||
import com.wordnik.swagger.codegen.BasicPythonGenerator
|
||||
|
||||
import com.wordnik.swagger.core._
|
||||
|
||||
import java.io.File
|
||||
|
||||
object PythonPetstoreCodegen extends BasicPythonGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
|
||||
override def destinationDir = "samples/petstore/python"
|
||||
|
||||
override def supportingFiles = List(
|
||||
("__init__.mustache", destinationDir, "__init__.py"),
|
||||
("swagger.mustache", destinationDir + File.separator + apiPackage.get, "swagger.py"),
|
||||
("__init__.mustache", destinationDir + File.separator + modelPackage.get, "__init__.py"))
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# Sample Petstore Python application
|
||||
|
||||
Here's a Python 2.7 [Swagger](http://swagger.wordnik.com/) client with unit
|
||||
tests for the Petstore sample application. See the interactive Swagger
|
||||
documentation at http://petstore.swagger.wordnik.com/ for more information on
|
||||
this demonstration API.
|
||||
|
||||
The client contained in ```petstore``` was generated using this
|
||||
```swagger-codegen``` project, with the following command:
|
||||
|
||||
./bin/runscala.sh com.wordnik.swagger.codegen.BasicPythonGenerator http://petstore.swagger.wordnik.com/api/resources.json special-key
|
||||
|
||||
To run the tests, issue the following command:
|
||||
|
||||
python tests/BaseApiTest.py
|
@ -1,217 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
WordAPI.py
|
||||
Copyright 2012 Wordnik, Inc.
|
||||
|
||||
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.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
from models import *
|
||||
|
||||
|
||||
class PetApi(object):
|
||||
|
||||
def __init__(self, apiClient):
|
||||
self.apiClient = apiClient
|
||||
|
||||
|
||||
def getPetById(self, petId, **kwargs):
|
||||
"""Find pet by ID
|
||||
|
||||
Args:
|
||||
petId, str: ID of pet that needs to be fetched (required)
|
||||
|
||||
Returns: Pet
|
||||
"""
|
||||
|
||||
allParams = ['petId']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method getPetById" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/pet.{format}/{petId}'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
if ('petId' in params):
|
||||
replacement = str(self.apiClient.toPathValue(params['petId']))
|
||||
resourcePath = resourcePath.replace('{' + 'petId' + '}',
|
||||
replacement)
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
|
||||
responseObject = self.apiClient.deserialize(response, 'Pet')
|
||||
return responseObject
|
||||
|
||||
|
||||
def addPet(self, body, **kwargs):
|
||||
"""Add a new pet to the store
|
||||
|
||||
Args:
|
||||
body, Pet: Pet object that needs to be added to the store (required)
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['body']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method addPet" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/pet.{format}'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
def updatePet(self, body, **kwargs):
|
||||
"""Update an existing pet
|
||||
|
||||
Args:
|
||||
body, Pet: Pet object that needs to be updated in the store (required)
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['body']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method updatePet" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/pet.{format}'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'PUT'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
def findPetsByStatus(self, status, **kwargs):
|
||||
"""Finds Pets by status
|
||||
|
||||
Args:
|
||||
status, str: Status values that need to be considered for filter (required)
|
||||
|
||||
Returns: list[Pet]
|
||||
"""
|
||||
|
||||
allParams = ['status']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method findPetsByStatus" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/pet.{format}/findByStatus'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
if ('status' in params):
|
||||
queryParams['status'] = self.apiClient.toPathValue(params['status'])
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
|
||||
responseObject = self.apiClient.deserialize(response, 'list[Pet]')
|
||||
return responseObject
|
||||
|
||||
|
||||
def findPetsByTags(self, tags, **kwargs):
|
||||
"""Finds Pets by tags
|
||||
|
||||
Args:
|
||||
tags, str: Tags to filter by (required)
|
||||
|
||||
Returns: list[Pet]
|
||||
"""
|
||||
|
||||
allParams = ['tags']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method findPetsByTags" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/pet.{format}/findByTags'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
if ('tags' in params):
|
||||
queryParams['tags'] = self.apiClient.toPathValue(params['tags'])
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
|
||||
responseObject = self.apiClient.deserialize(response, 'list[Pet]')
|
||||
return responseObject
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,143 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
WordAPI.py
|
||||
Copyright 2012 Wordnik, Inc.
|
||||
|
||||
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.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
from models import *
|
||||
|
||||
|
||||
class StoreApi(object):
|
||||
|
||||
def __init__(self, apiClient):
|
||||
self.apiClient = apiClient
|
||||
|
||||
|
||||
def getOrderById(self, orderId, **kwargs):
|
||||
"""Find purchase order by ID
|
||||
|
||||
Args:
|
||||
orderId, str: ID of pet that needs to be fetched (required)
|
||||
|
||||
Returns: Order
|
||||
"""
|
||||
|
||||
allParams = ['orderId']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method getOrderById" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/store.{format}/order/{orderId}'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
if ('orderId' in params):
|
||||
replacement = str(self.apiClient.toPathValue(params['orderId']))
|
||||
resourcePath = resourcePath.replace('{' + 'orderId' + '}',
|
||||
replacement)
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
|
||||
responseObject = self.apiClient.deserialize(response, 'Order')
|
||||
return responseObject
|
||||
|
||||
|
||||
def deleteOrder(self, orderId, **kwargs):
|
||||
"""Delete purchase order by ID
|
||||
|
||||
Args:
|
||||
orderId, str: ID of the order that needs to be deleted (required)
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['orderId']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method deleteOrder" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/store.{format}/order/{orderId}'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'DELETE'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
if ('orderId' in params):
|
||||
replacement = str(self.apiClient.toPathValue(params['orderId']))
|
||||
resourcePath = resourcePath.replace('{' + 'orderId' + '}',
|
||||
replacement)
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
def placeOrder(self, body, **kwargs):
|
||||
"""Place an order for a pet
|
||||
|
||||
Args:
|
||||
body, Order: order placed for purchasing the pet (required)
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['body']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method placeOrder" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/store.{format}/order'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,317 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
WordAPI.py
|
||||
Copyright 2012 Wordnik, Inc.
|
||||
|
||||
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.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
from models import *
|
||||
|
||||
|
||||
class UserApi(object):
|
||||
|
||||
def __init__(self, apiClient):
|
||||
self.apiClient = apiClient
|
||||
|
||||
|
||||
def createUsersWithArrayInput(self, body, **kwargs):
|
||||
"""Creates list of users with given input array
|
||||
|
||||
Args:
|
||||
body, list[User]: List of user object (required)
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['body']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method createUsersWithArrayInput" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/user.{format}/createWithArray'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
def createUser(self, body, **kwargs):
|
||||
"""Create user
|
||||
|
||||
Args:
|
||||
body, User: Created user object (required)
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['body']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method createUser" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/user.{format}'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
def createUsersWithListInput(self, body, **kwargs):
|
||||
"""Creates list of users with given list input
|
||||
|
||||
Args:
|
||||
body, List[User]: List of user object (required)
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['body']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method createUsersWithListInput" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/user.{format}/createWithList'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'POST'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
def updateUser(self, username, body, **kwargs):
|
||||
"""Updated user
|
||||
|
||||
Args:
|
||||
username, str: name that need to be deleted (required)
|
||||
body, User: Updated user object (required)
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['username', 'body']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method updateUser" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/user.{format}/{username}'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'PUT'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
if ('username' in params):
|
||||
replacement = str(self.apiClient.toPathValue(params['username']))
|
||||
resourcePath = resourcePath.replace('{' + 'username' + '}',
|
||||
replacement)
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
def deleteUser(self, username, **kwargs):
|
||||
"""Delete user
|
||||
|
||||
Args:
|
||||
username, str: The name that needs to be deleted (required)
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['username']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method deleteUser" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/user.{format}/{username}'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'DELETE'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
if ('username' in params):
|
||||
replacement = str(self.apiClient.toPathValue(params['username']))
|
||||
resourcePath = resourcePath.replace('{' + 'username' + '}',
|
||||
replacement)
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
def getUserByName(self, username, **kwargs):
|
||||
"""Get user by user name
|
||||
|
||||
Args:
|
||||
username, str: The name that needs to be fetched. Use user1 for testing. (required)
|
||||
|
||||
Returns: User
|
||||
"""
|
||||
|
||||
allParams = ['username']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method getUserByName" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/user.{format}/{username}'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
if ('username' in params):
|
||||
replacement = str(self.apiClient.toPathValue(params['username']))
|
||||
resourcePath = resourcePath.replace('{' + 'username' + '}',
|
||||
replacement)
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
|
||||
responseObject = self.apiClient.deserialize(response, 'User')
|
||||
return responseObject
|
||||
|
||||
|
||||
def loginUser(self, username, password, **kwargs):
|
||||
"""Logs user into the system
|
||||
|
||||
Args:
|
||||
username, str: The user name for login (required)
|
||||
password, str: The password for login in clear text (required)
|
||||
|
||||
Returns: str
|
||||
"""
|
||||
|
||||
allParams = ['username', 'password']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method loginUser" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/user.{format}/login'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
if ('username' in params):
|
||||
queryParams['username'] = self.apiClient.toPathValue(params['username'])
|
||||
if ('password' in params):
|
||||
queryParams['password'] = self.apiClient.toPathValue(params['password'])
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
|
||||
responseObject = self.apiClient.deserialize(response, 'str')
|
||||
return responseObject
|
||||
|
||||
|
||||
def logoutUser(self, **kwargs):
|
||||
"""Logs out current logged in user session
|
||||
|
||||
Args:
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = []
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
if key not in allParams:
|
||||
raise TypeError("Got an unexpected keyword argument '%s' to method logoutUser" % key)
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
resourcePath = '/user.{format}/logout'
|
||||
resourcePath = resourcePath.replace('{format}', 'json')
|
||||
method = 'GET'
|
||||
|
||||
queryParams = {}
|
||||
headerParams = {}
|
||||
|
||||
postData = (params['body'] if 'body' in params else None)
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""Add all of the modules in the current directory to __all__"""
|
||||
import os
|
||||
|
||||
__all__ = []
|
||||
|
||||
for module in os.listdir(os.path.dirname(__file__)):
|
||||
if module != '__init__.py' and module[-3:] == '.py':
|
||||
__all__.append(module[:-3])
|
||||
|
@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Copyright 2012 Wordnik, Inc.
|
||||
|
||||
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:
|
||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually."""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.swaggerTypes = {
|
||||
'id': 'long',
|
||||
'name': 'str'
|
||||
|
||||
}
|
||||
|
||||
|
||||
self.id = None # long
|
||||
self.name = None # str
|
||||
|
@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Copyright 2012 Wordnik, Inc.
|
||||
|
||||
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:
|
||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually."""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.swaggerTypes = {
|
||||
'id': 'long',
|
||||
'petId': 'long',
|
||||
'status': 'str',
|
||||
'quantity': 'int',
|
||||
'shipDate': 'datetime'
|
||||
|
||||
}
|
||||
|
||||
|
||||
self.id = None # long
|
||||
self.petId = None # long
|
||||
#Order Status
|
||||
self.status = None # str
|
||||
self.quantity = None # int
|
||||
self.shipDate = None # datetime
|
||||
|
@ -1,41 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Copyright 2012 Wordnik, Inc.
|
||||
|
||||
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:
|
||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually."""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.swaggerTypes = {
|
||||
'id': 'long',
|
||||
'tags': 'list[Tag]',
|
||||
'category': 'Category',
|
||||
'status': 'str',
|
||||
'name': 'str',
|
||||
'photoUrls': 'list[str]'
|
||||
|
||||
}
|
||||
|
||||
|
||||
self.id = None # long
|
||||
self.tags = None # list[Tag]
|
||||
self.category = None # Category
|
||||
#pet status in the store
|
||||
self.status = None # str
|
||||
self.name = None # str
|
||||
self.photoUrls = None # list[str]
|
||||
|
@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Copyright 2012 Wordnik, Inc.
|
||||
|
||||
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:
|
||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually."""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.swaggerTypes = {
|
||||
'id': 'long',
|
||||
'name': 'str'
|
||||
|
||||
}
|
||||
|
||||
|
||||
self.id = None # long
|
||||
self.name = None # str
|
||||
|
@ -1,45 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Copyright 2012 Wordnik, Inc.
|
||||
|
||||
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:
|
||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually."""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.swaggerTypes = {
|
||||
'id': 'long',
|
||||
'lastName': 'str',
|
||||
'username': 'str',
|
||||
'phone': 'str',
|
||||
'email': 'str',
|
||||
'userStatus': 'int',
|
||||
'firstName': 'str',
|
||||
'password': 'str'
|
||||
|
||||
}
|
||||
|
||||
|
||||
self.id = None # long
|
||||
self.lastName = None # str
|
||||
self.username = None # str
|
||||
self.phone = None # str
|
||||
self.email = None # str
|
||||
#User Status
|
||||
self.userStatus = None # int
|
||||
self.firstName = None # str
|
||||
self.password = None # str
|
||||
|
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""Add all of the modules in the current directory to __all__"""
|
||||
import os
|
||||
|
||||
__all__ = []
|
||||
|
||||
for module in os.listdir(os.path.dirname(__file__)):
|
||||
if module != '__init__.py' and module[-3:] == '.py':
|
||||
__all__.append(module[:-3])
|
||||
|
@ -1,200 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""Wordnik.com's 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."""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import urllib
|
||||
import urllib2
|
||||
import httplib
|
||||
import json
|
||||
import datetime
|
||||
|
||||
from models import *
|
||||
|
||||
|
||||
class ApiClient:
|
||||
"""Generic API client for Swagger client library builds"""
|
||||
|
||||
def __init__(self, apiKey=None, apiServer=None):
|
||||
if apiKey == None:
|
||||
raise Exception('You must pass an apiKey when instantiating the '
|
||||
'APIClient')
|
||||
self.apiKey = apiKey
|
||||
self.apiServer = apiServer
|
||||
self.cookie = None
|
||||
|
||||
def callAPI(self, resourcePath, method, queryParams, postData,
|
||||
headerParams=None):
|
||||
|
||||
url = self.apiServer + resourcePath
|
||||
headers = {}
|
||||
if headerParams:
|
||||
for param, value in headerParams.iteritems():
|
||||
headers[param] = value
|
||||
|
||||
headers['Content-type'] = 'application/json'
|
||||
headers['api_key'] = self.apiKey
|
||||
|
||||
if self.cookie:
|
||||
headers['Cookie'] = self.cookie
|
||||
|
||||
data = None
|
||||
|
||||
if method == 'GET':
|
||||
|
||||
if queryParams:
|
||||
# Need to remove None values, these should not be sent
|
||||
sentQueryParams = {}
|
||||
for param, value in queryParams.items():
|
||||
if value != None:
|
||||
sentQueryParams[param] = value
|
||||
url = url + '?' + urllib.urlencode(sentQueryParams)
|
||||
|
||||
elif method in ['POST', 'PUT', 'DELETE']:
|
||||
|
||||
if postData:
|
||||
headers['Content-type'] = 'application/json'
|
||||
data = self.sanitizeForSerialization(postData)
|
||||
data = json.dumps(data)
|
||||
|
||||
else:
|
||||
raise Exception('Method ' + method + ' is not recognized.')
|
||||
|
||||
request = MethodRequest(method=method, url=url, headers=headers,
|
||||
data=data)
|
||||
|
||||
# Make the request
|
||||
response = urllib2.urlopen(request)
|
||||
if 'Set-Cookie' in response.headers:
|
||||
self.cookie = response.headers['Set-Cookie']
|
||||
string = response.read()
|
||||
|
||||
try:
|
||||
data = json.loads(string)
|
||||
except ValueError: # PUT requests don't return anything
|
||||
data = None
|
||||
|
||||
return data
|
||||
|
||||
def toPathValue(self, obj):
|
||||
"""Serialize a list to a CSV string, if necessary.
|
||||
Args:
|
||||
obj -- data object to be serialized
|
||||
Returns:
|
||||
string -- json serialization of object
|
||||
"""
|
||||
if type(obj) == list:
|
||||
return ','.join(obj)
|
||||
else:
|
||||
return obj
|
||||
|
||||
def sanitizeForSerialization(self, obj):
|
||||
"""Dump an object into JSON for POSTing."""
|
||||
|
||||
if not obj:
|
||||
return None
|
||||
elif type(obj) in [str, int, long, float, bool]:
|
||||
return obj
|
||||
elif type(obj) == list:
|
||||
return [self.sanitizeForSerialization(subObj) for subObj in obj]
|
||||
elif type(obj) == datetime.datetime:
|
||||
return obj.isoformat()
|
||||
else:
|
||||
if type(obj) == dict:
|
||||
objDict = obj
|
||||
else:
|
||||
objDict = obj.__dict__
|
||||
return {key: self.sanitizeForSerialization(val)
|
||||
for (key, val) in objDict.iteritems()
|
||||
if key != 'swaggerTypes'}
|
||||
|
||||
if type(postData) == list:
|
||||
# Could be a list of objects
|
||||
if type(postData[0]) in safeToDump:
|
||||
data = json.dumps(postData)
|
||||
else:
|
||||
data = json.dumps([datum.__dict__ for datum in postData])
|
||||
elif type(postData) not in safeToDump:
|
||||
data = json.dumps(postData.__dict__)
|
||||
|
||||
def deserialize(self, obj, objClass):
|
||||
"""Derialize a JSON string into an object.
|
||||
|
||||
Args:
|
||||
obj -- string or object to be deserialized
|
||||
objClass -- class literal for deserialzied object, or string
|
||||
of class name
|
||||
Returns:
|
||||
object -- deserialized object"""
|
||||
|
||||
# Have to accept objClass as string or actual type. Type could be a
|
||||
# native Python type, or one of the model classes.
|
||||
if type(objClass) == str:
|
||||
if 'list[' in objClass:
|
||||
match = re.match('list\[(.*)\]', objClass)
|
||||
subClass = match.group(1)
|
||||
return [self.deserialize(subObj, subClass) for subObj in obj]
|
||||
|
||||
if (objClass in ['int', 'float', 'long', 'dict', 'list', 'str']):
|
||||
objClass = eval(objClass)
|
||||
else: # not a native type, must be model class
|
||||
objClass = eval(objClass + '.' + objClass)
|
||||
|
||||
if objClass in [str, int, long, float, bool]:
|
||||
return objClass(obj)
|
||||
elif objClass == datetime:
|
||||
# Server will always return a time stamp in UTC, but with
|
||||
# trailing +0000 indicating no offset from UTC. So don't process
|
||||
# last 5 characters.
|
||||
return datetime.datetime.strptime(obj[:-5],
|
||||
"%Y-%m-%dT%H:%M:%S.%f")
|
||||
|
||||
instance = objClass()
|
||||
|
||||
for attr, attrType in instance.swaggerTypes.iteritems():
|
||||
if attr in obj:
|
||||
value = obj[attr]
|
||||
if attrType in ['str', 'int', 'long', 'float', 'bool']:
|
||||
attrType = eval(attrType)
|
||||
try:
|
||||
value = attrType(value)
|
||||
except UnicodeEncodeError:
|
||||
value = unicode(value)
|
||||
setattr(instance, attr, value)
|
||||
elif 'list[' in attrType:
|
||||
match = re.match('list\[(.*)\]', attrType)
|
||||
subClass = match.group(1)
|
||||
subValues = []
|
||||
if not value:
|
||||
setattr(instance, attr, None)
|
||||
else:
|
||||
for subValue in value:
|
||||
subValues.append(self.deserialize(subValue,
|
||||
subClass))
|
||||
setattr(instance, attr, subValues)
|
||||
else:
|
||||
setattr(instance, attr, self.deserialize(value,
|
||||
objClass))
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
class MethodRequest(urllib2.Request):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Construct a MethodRequest. Usage is the same as for
|
||||
`urllib2.Request` except it also takes an optional `method`
|
||||
keyword argument. If supplied, `method` will be used instead of
|
||||
the default."""
|
||||
|
||||
if 'method' in kwargs:
|
||||
self.method = kwargs.pop('method')
|
||||
return urllib2.Request.__init__(self, *args, **kwargs)
|
||||
|
||||
def get_method(self):
|
||||
return getattr(self, 'method', urllib2.Request.get_method(self))
|
||||
|
@ -1,37 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""Unit tests for SwaggerPython Petstore sample app API client.
|
||||
|
||||
Run all tests:
|
||||
|
||||
python BaseApiTest.py
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
|
||||
sys.path = ['./'] + sys.path
|
||||
from petstore import *
|
||||
|
||||
|
||||
class BaseApiTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.apiKey = 'special-key'
|
||||
self.apiUrl = 'http://petstore.swagger.wordnik.com/api'
|
||||
self.username = 'test'
|
||||
self.password = 'test'
|
||||
|
||||
client = swagger.ApiClient(self.apiKey, self.apiUrl)
|
||||
self.petApi = PetApi.PetApi(client)
|
||||
self.storeApi = StoreApi.StoreApi(client)
|
||||
self.userApi = UserApi.UserApi(client)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
from PetApiTest import PetApiTest
|
||||
from StoreApiTest import StoreApiTest
|
||||
from UserApiTest import UserApiTest
|
||||
|
||||
unittest.main()
|
@ -1,176 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
import urllib2
|
||||
import json
|
||||
import random
|
||||
|
||||
from BaseApiTest import BaseApiTest
|
||||
|
||||
sys.path = ['./'] + sys.path
|
||||
from petstore import *
|
||||
from petstore.models import *
|
||||
|
||||
|
||||
class PetApiTest(BaseApiTest):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# super(PetApiTest, self).setUp()
|
||||
cls.randomId = long(int(90000 * random.random()) + 10000)
|
||||
|
||||
def testPetApis(self):
|
||||
response = urllib2.urlopen(self.apiUrl + '/pet.json')
|
||||
doc = json.loads(response.read())
|
||||
assert len(doc['apis']) == 3, 'there should be 3 pet apis'
|
||||
|
||||
def testPetApisAuthenticated(self):
|
||||
response = urllib2.urlopen(self.apiUrl + '/pet.json?' +
|
||||
'api_key=special-key')
|
||||
doc = json.loads(response.read())
|
||||
assert len(doc['apis']) == 4, 'there should be 4 pet apis when' + \
|
||||
'authenticated'
|
||||
|
||||
def testGetPetById(self):
|
||||
res = self.petApi.getPetById(1)
|
||||
assert res, 'null getWord result'
|
||||
assert res.id == 1, 'pet id should be 1'
|
||||
|
||||
def testAddPet(self):
|
||||
pet = Pet.Pet()
|
||||
|
||||
pet.id = self.randomId
|
||||
tag1 = Tag.Tag()
|
||||
tag1.name = "tag1"
|
||||
tag2 = Tag.Tag()
|
||||
tag2.name = "some tag"
|
||||
pet.tags = [tag1, tag2]
|
||||
category = Category.Category()
|
||||
category.name = "Cats"
|
||||
pet.category = category
|
||||
pet.status = "sold"
|
||||
pet.name = "Shermie"
|
||||
pet.photoUrls = ["http://foo.com/1.jpg", "http://foo.com/1.jpg"]
|
||||
self.petApi.addPet(pet)
|
||||
|
||||
new_pet = self.petApi.getPetById(pet.id)
|
||||
|
||||
assert new_pet.id == pet.id, 'ids should match'
|
||||
assert new_pet.name == pet.name, 'names should match'
|
||||
assert(set([tag.name for tag in new_pet.tags]) ==
|
||||
set([tag.name for tag in pet.tags])), 'tags should match'
|
||||
assert new_pet.status == pet.status, 'status should match'
|
||||
assert new_pet.category.name == pet.category.name, 'category should match'
|
||||
assert new_pet.photoUrls == pet.photoUrls, 'photoUrls should match'
|
||||
|
||||
def testUpdatePet(self):
|
||||
alpahbet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
||||
|
||||
pet = Pet.Pet()
|
||||
pet.id = self.randomId
|
||||
|
||||
tag1 = Tag.Tag()
|
||||
tag1.name = "special-tag"
|
||||
tag2 = Tag.Tag()
|
||||
random.shuffle(alpahbet)
|
||||
tag2.name = ''.join(alpahbet)
|
||||
pet.tags = [tag1, tag2]
|
||||
category = Category.Category()
|
||||
random.shuffle(alpahbet)
|
||||
category.name = ''.join(alpahbet)
|
||||
pet.category = category
|
||||
pet.status = "sold"
|
||||
random.shuffle(alpahbet)
|
||||
pet.name = ''.join(alpahbet)
|
||||
pet.photoUrls = ["http://foo.com/22.jpg", "http://foo.com/55.jpg"]
|
||||
self.petApi.updatePet(pet)
|
||||
|
||||
updated_pet = self.petApi.getPetById(pet.id)
|
||||
|
||||
assert updated_pet.id == pet.id, 'ids should match'
|
||||
assert updated_pet.name == pet.name, 'names should match'
|
||||
assert(set([tag.name for tag in updated_pet.tags]) ==
|
||||
set([tag.name for tag in pet.tags])), 'tags should match'
|
||||
assert updated_pet.status == pet.status, 'status should match'
|
||||
assert updated_pet.category.name == pet.category.name, 'category should match'
|
||||
assert updated_pet.photoUrls == pet.photoUrls, 'photoUrls should match'
|
||||
|
||||
def testFindPetsByTags(self):
|
||||
pet = Pet.Pet()
|
||||
pet.id = self.randomId
|
||||
|
||||
tag1 = Tag.Tag()
|
||||
tag1.name = "special-tag"
|
||||
pet.tags = [tag1]
|
||||
self.petApi.updatePet(pet)
|
||||
|
||||
res = self.petApi.findPetsByTags("special-tag")
|
||||
assert self.randomId in [pet.id for pet in res], 'must find by tag'
|
||||
|
||||
def testFindPetsByStatus(self):
|
||||
pet = Pet.Pet()
|
||||
pet.id = self.randomId
|
||||
|
||||
tag1 = Tag.Tag()
|
||||
tag1.name = "special-tag"
|
||||
pet.status = "sold"
|
||||
self.petApi.updatePet(pet)
|
||||
|
||||
res = self.petApi.findPetsByStatus("sold")
|
||||
assert self.randomId in [pet.id for pet in res], 'must find by status'
|
||||
|
||||
# def testGetWordWithCanonicalForm(self):
|
||||
# res = self.wordApi.getWord('cAt', useCanonical=True)
|
||||
# assert res, 'null getWord result'
|
||||
# assert res.word == 'cat', 'word should be "cAt"'
|
||||
|
||||
# def testGetDefinitions(self):
|
||||
# res = self.wordApi.getDefinitions('cat', limit=10)
|
||||
# assert res, 'null getDefinitions result'
|
||||
# assert len(res) == 10, 'should have 10 definitions'
|
||||
|
||||
# def testGetExamples(self):
|
||||
# res = self.wordApi.getExamples('cat', limit=5)
|
||||
# assert res, 'null getExamples result'
|
||||
# assert len(res.examples) == 5, 'should have 5 definitions'
|
||||
|
||||
# def testGetTopExample(self):
|
||||
# res = self.wordApi.getTopExample('cat')
|
||||
# assert res, 'null getTopExample result'
|
||||
# assert res.word == 'cat', 'word should be "cat"'
|
||||
|
||||
# # def testGetTextPronunciations(self):
|
||||
# # res = self.wordApi.getTextPronunciations('cat')
|
||||
# # assert res, 'null getTextPronunciations result'
|
||||
# # assert len(res) == 2, 'should have 2 prons for "cat"'
|
||||
|
||||
# def testGetHyphenation(self):
|
||||
# res = self.wordApi.getHyphenation('catalog', limit=1)
|
||||
# assert res, 'null getHyphenation result'
|
||||
# assert len(res) == 1, 'hypenation length should be 1'
|
||||
|
||||
# def testGetWordFrequency(self):
|
||||
# res = self.wordApi.getWordFrequency('cat')
|
||||
# assert res, 'null getWordFrequency result'
|
||||
# assert res.totalCount != 0, 'total count should not be 0'
|
||||
|
||||
# def testGetPhrases(self):
|
||||
# res = self.wordApi.getPhrases('money')
|
||||
# assert res, 'null getPhrases result'
|
||||
# assert len(res) != 0, 'getPhrases length should not be 0'
|
||||
|
||||
# def testGetRelatedWords(self):
|
||||
# res = self.wordApi.getRelatedWords('cat')
|
||||
# assert res, 'null getRelatedWords result'
|
||||
# for related in res:
|
||||
# assert len(related.words) <= 10, 'should have <= 10 related words'
|
||||
|
||||
# def testGetAudio(self):
|
||||
# res = self.wordApi.getAudio('cat', useCanonical=True, limit=2)
|
||||
# assert res, 'null getAudio result'
|
||||
# assert len(res) == 2, 'getAudio size should be 2'
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,36 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
import datetime
|
||||
|
||||
from BaseApiTest import BaseApiTest
|
||||
|
||||
sys.path = ['./'] + sys.path
|
||||
from petstore import *
|
||||
from petstore.models import *
|
||||
|
||||
|
||||
class StoreApiTest(BaseApiTest):
|
||||
|
||||
def testGetOrderById(self):
|
||||
res = self.storeApi.getOrderById(1)
|
||||
assert res, 'null getOrderById result'
|
||||
assert long(1) == res.id, 'order id should be long(1)'
|
||||
|
||||
def testDeleteOrder(self):
|
||||
self.storeApi.deleteOrder(3)
|
||||
self.storeApi.deleteOrder("foo")
|
||||
|
||||
def testPlaceOrder(self):
|
||||
order = Order.Order()
|
||||
order.petId = 1
|
||||
order.status = 'ordered'
|
||||
order.quantity = 10
|
||||
order.shipDate = datetime.datetime.strptime("2011-01-09T13:55:07.123",
|
||||
"%Y-%m-%dT%H:%M:%S.%f")
|
||||
self.storeApi.placeOrder(order)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -1,225 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
import unittest
|
||||
import random
|
||||
import urllib2
|
||||
|
||||
from BaseApiTest import BaseApiTest
|
||||
|
||||
sys.path = ['./'] + sys.path
|
||||
from petstore import *
|
||||
from petstore.models import *
|
||||
|
||||
|
||||
def randomString():
|
||||
return str(int(random.random() * 100000))
|
||||
|
||||
|
||||
class UserApiTest(BaseApiTest):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
alpahbet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
||||
random.shuffle(alpahbet)
|
||||
cls.randomUsername1 = ''.join(alpahbet)
|
||||
random.shuffle(alpahbet)
|
||||
cls.randomUsername2 = ''.join(alpahbet)
|
||||
random.shuffle(alpahbet)
|
||||
cls.randomUsername3 = ''.join(alpahbet)
|
||||
random.shuffle(alpahbet)
|
||||
cls.randomUsername4 = ''.join(alpahbet)
|
||||
random.shuffle(alpahbet)
|
||||
cls.randomUsername5 = ''.join(alpahbet)
|
||||
|
||||
def testCreateUsersWithArrayInput(self):
|
||||
|
||||
user = User.User()
|
||||
|
||||
user.id = long(randomString())
|
||||
user.lastName = randomString()
|
||||
user.username = self.randomUsername1
|
||||
user.phone = randomString()
|
||||
user.email = randomString()
|
||||
user.userStatus = int(randomString())
|
||||
user.firstName = randomString()
|
||||
user.password = randomString()
|
||||
|
||||
otherUser = User.User()
|
||||
|
||||
otherUser.id = long(randomString())
|
||||
otherUser.lastName = randomString()
|
||||
otherUser.username = self.randomUsername2
|
||||
otherUser.phone = randomString()
|
||||
otherUser.email = randomString()
|
||||
otherUser.userStatus = int(randomString())
|
||||
otherUser.firstName = randomString()
|
||||
otherUser.password = randomString()
|
||||
|
||||
users = [user, otherUser]
|
||||
self.userApi.createUsersWithArrayInput(users)
|
||||
|
||||
newUser = self.userApi.getUserByName(self.randomUsername1)
|
||||
|
||||
assert newUser.id == user.id, 'id matches user'
|
||||
assert newUser.lastName == user.lastName, 'lastName matches user'
|
||||
assert newUser.username == user.username, 'username matches user'
|
||||
assert newUser.phone == user.phone, 'phone matches user'
|
||||
assert newUser.email == user.email, 'email matches user'
|
||||
assert newUser.userStatus == user.userStatus, 'status matches user'
|
||||
assert newUser.firstName == user.firstName, 'firstName matches user'
|
||||
assert newUser.password == user.password, 'password matches user'
|
||||
|
||||
newUser = self.userApi.getUserByName(self.randomUsername2)
|
||||
|
||||
assert newUser.id == otherUser.id, 'id matches user'
|
||||
assert newUser.lastName == otherUser.lastName, 'lastName matches user'
|
||||
assert newUser.username == otherUser.username, 'username matches user'
|
||||
assert newUser.phone == otherUser.phone, 'phone matches user'
|
||||
assert newUser.email == otherUser.email, 'email matches user'
|
||||
assert newUser.userStatus == otherUser.userStatus, 'status matches user'
|
||||
assert newUser.firstName == otherUser.firstName, 'firstName matches user'
|
||||
assert newUser.password == otherUser.password, 'password matches user'
|
||||
|
||||
def testCreateUsersWithListInput(self):
|
||||
|
||||
user = User.User()
|
||||
|
||||
user.id = long(randomString())
|
||||
user.lastName = randomString()
|
||||
user.username = self.randomUsername3
|
||||
user.phone = randomString()
|
||||
user.email = randomString()
|
||||
user.userStatus = int(randomString())
|
||||
user.firstName = randomString()
|
||||
user.password = randomString()
|
||||
|
||||
otherUser = User.User()
|
||||
|
||||
otherUser.id = long(randomString())
|
||||
otherUser.lastName = randomString()
|
||||
otherUser.username = self.randomUsername4
|
||||
otherUser.phone = randomString()
|
||||
otherUser.email = randomString()
|
||||
otherUser.userStatus = int(randomString())
|
||||
otherUser.firstName = randomString()
|
||||
otherUser.password = randomString()
|
||||
|
||||
users = [user, otherUser]
|
||||
self.userApi.createUsersWithListInput(users)
|
||||
|
||||
newUser = self.userApi.getUserByName(self.randomUsername3)
|
||||
|
||||
assert newUser.id == user.id, 'id matches user'
|
||||
assert newUser.lastName == user.lastName, 'lastName matches user'
|
||||
assert newUser.username == user.username, 'username matches user'
|
||||
assert newUser.phone == user.phone, 'phone matches user'
|
||||
assert newUser.email == user.email, 'email matches user'
|
||||
assert newUser.userStatus == user.userStatus, 'status matches user'
|
||||
assert newUser.firstName == user.firstName, 'firstName matches user'
|
||||
assert newUser.password == user.password, 'password matches user'
|
||||
|
||||
newUser = self.userApi.getUserByName(self.randomUsername4)
|
||||
|
||||
assert newUser.id == otherUser.id, 'id matches user'
|
||||
assert newUser.lastName == otherUser.lastName, 'lastName matches user'
|
||||
assert newUser.username == otherUser.username, 'username matches user'
|
||||
assert newUser.phone == otherUser.phone, 'phone matches user'
|
||||
assert newUser.email == otherUser.email, 'email matches user'
|
||||
assert newUser.userStatus == otherUser.userStatus, 'status matches user'
|
||||
assert newUser.firstName == otherUser.firstName, 'firstName matches user'
|
||||
assert newUser.password == otherUser.password, 'password matches user'
|
||||
|
||||
def testCreateUser(self):
|
||||
|
||||
user = User.User()
|
||||
|
||||
user.id = long(randomString())
|
||||
user.lastName = randomString()
|
||||
user.username = self.randomUsername5
|
||||
user.phone = randomString()
|
||||
user.email = randomString()
|
||||
user.userStatus = int(randomString())
|
||||
user.firstName = randomString()
|
||||
user.password = randomString()
|
||||
|
||||
self.userApi.createUser(user)
|
||||
|
||||
newUser = self.userApi.getUserByName(self.randomUsername5)
|
||||
|
||||
assert newUser.id, user.id
|
||||
assert newUser.lastName, user.lastName
|
||||
assert newUser.username, user.username
|
||||
assert newUser.phone, user.phone
|
||||
assert newUser.email, user.email
|
||||
assert newUser.userStatus, user.userStatus
|
||||
assert newUser.firstName, user.firstName
|
||||
assert newUser.password, user.password
|
||||
|
||||
def testUpdateUser(self):
|
||||
|
||||
user = User.User()
|
||||
username = randomString()
|
||||
user.id = long(randomString())
|
||||
user.lastName = randomString()
|
||||
user.username = username
|
||||
user.phone = randomString()
|
||||
user.email = randomString()
|
||||
user.userStatus = int(randomString())
|
||||
user.firstName = randomString()
|
||||
user.password = randomString()
|
||||
|
||||
self.userApi.createUser(user)
|
||||
|
||||
user = self.userApi.getUserByName(username)
|
||||
|
||||
user.lastName = randomString()
|
||||
user.phone = randomString()
|
||||
user.email = randomString()
|
||||
user.userStatus = int(randomString())
|
||||
user.firstName = randomString()
|
||||
user.password = randomString()
|
||||
|
||||
self.userApi.updateUser(username, user)
|
||||
|
||||
updatedUser = self.userApi.getUserByName(username)
|
||||
|
||||
assert updatedUser.lastName == user.lastName, 'should match lastName'
|
||||
assert updatedUser.username == user.username, 'should match username'
|
||||
assert updatedUser.phone == user.phone, 'should match phone'
|
||||
assert updatedUser.email == user.email, 'should match email'
|
||||
assert updatedUser.userStatus == user.userStatus, 'should match status'
|
||||
assert updatedUser.firstName == user.firstName, 'should match firstName'
|
||||
assert updatedUser.password == user.password, 'should match password'
|
||||
|
||||
def testDeleteUser(self):
|
||||
|
||||
user = User.User()
|
||||
username = randomString()
|
||||
user.username = username
|
||||
|
||||
self.userApi.createUser(user)
|
||||
|
||||
self.userApi.deleteUser(username)
|
||||
|
||||
userGone = False
|
||||
|
||||
try:
|
||||
self.userApi.getUserByName(username)
|
||||
except urllib2.HTTPError:
|
||||
userGone = True
|
||||
|
||||
assert userGone, 'user should be deleted'
|
||||
|
||||
def testLoginUser(self):
|
||||
|
||||
res = self.userApi.loginUser("anyusername", "anypassword")
|
||||
|
||||
assert res[:23] == "logged in user session:", 'should get session'
|
||||
|
||||
def testLogoutUser(self):
|
||||
# We just want to make sure there are no errors in this test.
|
||||
self.userApi.logoutUser()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user