Issue #2276 Auto generated test stubs

This commit is contained in:
Scott Williams 2016-04-27 20:53:48 +01:00
parent 67b6c3f3d3
commit f59c43dffb
25 changed files with 1156 additions and 164 deletions

View File

@ -20,6 +20,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
protected String packageVersion;
protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/";
private String testFolder;
public PythonClientCodegen() {
super();
@ -27,12 +29,19 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
modelPackage = "models";
apiPackage = "api";
outputFolder = "generated-code" + File.separatorChar + "python";
modelTemplateFiles.put("model.mustache", ".py");
apiTemplateFiles.put("api.mustache", ".py");
modelTestTemplateFiles.put("model_test.mustache", ".py");
apiTestTemplateFiles.put("api_test.mustache", ".py");
embeddedTemplateDir = templateDir = "python";
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");
testFolder = "tests";
languageSpecificPrimitives.clear();
languageSpecificPrimitives.add("int");
@ -126,6 +135,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
supportingFiles.add(new SupportingFile("__init__package.mustache", swaggerFolder, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__api.mustache", apiPackage, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__test.mustache", testFolder, "__init__.py"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
}
@ -184,6 +194,16 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
public String modelFileFolder() {
return outputFolder + File.separatorChar + modelPackage().replace('.', File.separatorChar);
}
@Override
public String apiTestFileFolder() {
return outputFolder + File.separatorChar + testFolder;
}
@Override
public String modelTestFileFolder() {
return outputFolder + File.separatorChar + testFolder;
}
@Override
public String getTypeDeclaration(Property p) {
@ -310,6 +330,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
// PhoneNumber => phone_number
return underscore(dropDots(name));
}
@Override
public String toModelTestFilename(String name) {
return "test_" + toModelFilename(name);
};
@Override
public String toApiFilename(String name) {
@ -319,6 +344,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
// e.g. PhoneNumberApi.rb => phone_number_api.rb
return underscore(name) + "_api";
}
@Override
public String toApiTestFilename(String name) {
return "test_" + toApiFilename(name);
}
@Override
public String toApiName(String name) {

View File

@ -0,0 +1,43 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.apis.{{classVarName}} import {{classname}}
class {{#operations}}{{classname}}Test(unittest.TestCase):
def setUp(self):
self.api = swagger_client.apis.{{classVarName}}.{{classname}}()
def tearDown(self):
pass
{{#operation}}
def test_{{operationId}}(self):
pass
{{/operation}}
{{/operations}}

View File

@ -0,0 +1,48 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
{{#models}}
{{#model}}
import swagger_client
from swagger_client.models.{{classFilename}} import {{classname}}
class {{classname}}Test(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test {{classname}}
"""
def test{{classname}}(self):
self.model = swagger_client.models.{{classFilename}}.{{classname}}()
{{/model}}
{{/models}}

View File

@ -5,7 +5,7 @@ This Python package is automatically generated by the [Swagger Codegen](https://
- API version: 1.0.0
- Package version: 1.0.0
- Build date: 2016-04-27T17:36:32.266+08:00
- Build date: 2016-04-27T20:52:27.297+01:00
- Build package: class io.swagger.codegen.languages.PythonClientCodegen
## Requirements.

View File

@ -0,0 +1,77 @@
# swagger_client.FakeApi
All URIs are relative to *http://petstore.swagger.io/v2*
Method | HTTP request | Description
------------- | ------------- | -------------
[**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters
# **test_endpoint_parameters**
> test_endpoint_parameters(number, double, string, byte, integer=integer, int32=int32, int64=int64, float=float, binary=binary, date=date, date_time=date_time, password=password)
Fake endpoint for testing various parameters
Fake endpoint for testing various parameters
### Example
```python
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
# create an instance of the API class
api_instance = swagger_client.FakeApi()
number = 3.4 # float | None
double = 1.2 # float | None
string = 'string_example' # str | None
byte = 'B' # str | None
integer = 56 # int | None (optional)
int32 = 56 # int | None (optional)
int64 = 789 # int | None (optional)
float = 3.4 # float | None (optional)
binary = 'B' # str | None (optional)
date = '2013-10-20' # date | None (optional)
date_time = '2013-10-20T19:20:30+01:00' # datetime | None (optional)
password = 'password_example' # str | None (optional)
try:
# Fake endpoint for testing various parameters
api_instance.test_endpoint_parameters(number, double, string, byte, integer=integer, int32=int32, int64=int64, float=float, binary=binary, date=date, date_time=date_time, password=password)
except ApiException as e:
print "Exception when calling FakeApi->test_endpoint_parameters: %s\n" % e
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**number** | **float**| None |
**double** | **float**| None |
**string** | **str**| None |
**byte** | **str**| None |
**integer** | **int**| None | [optional]
**int32** | **int**| None | [optional]
**int64** | **int**| None | [optional]
**float** | **float**| None | [optional]
**binary** | **str**| None | [optional]
**date** | **date**| None | [optional]
**date_time** | **datetime**| None | [optional]
**password** | **str**| None | [optional]
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/xml, application/json
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

View File

@ -0,0 +1,165 @@
# coding: utf-8
"""
FakeApi.py
Copyright 2016 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.
"""
from __future__ import absolute_import
import sys
import os
# python 2 and python 3 compatibility library
from six import iteritems
from ..configuration import Configuration
from ..api_client import ApiClient
class FakeApi(object):
"""
NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
Ref: https://github.com/swagger-api/swagger-codegen
"""
def __init__(self, api_client=None):
config = Configuration()
if api_client:
self.api_client = api_client
else:
if not config.api_client:
config.api_client = ApiClient()
self.api_client = config.api_client
def test_endpoint_parameters(self, number, double, string, byte, **kwargs):
"""
Fake endpoint for testing various parameters
Fake endpoint for testing various parameters
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
>>> def callback_function(response):
>>> pprint(response)
>>>
>>> thread = api.test_endpoint_parameters(number, double, string, byte, callback=callback_function)
:param callback function: The callback function
for asynchronous request. (optional)
:param float number: None (required)
:param float double: None (required)
:param str string: None (required)
:param str byte: None (required)
:param int integer: None
:param int int32: None
:param int int64: None
:param float float: None
:param str binary: None
:param date date: None
:param datetime date_time: None
:param str password: None
:return: None
If the method is called asynchronously,
returns the request thread.
"""
all_params = ['number', 'double', 'string', 'byte', 'integer', 'int32', 'int64', 'float', 'binary', 'date', 'date_time', 'password']
all_params.append('callback')
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 test_endpoint_parameters" % key
)
params[key] = val
del params['kwargs']
# verify the required parameter 'number' is set
if ('number' not in params) or (params['number'] is None):
raise ValueError("Missing the required parameter `number` when calling `test_endpoint_parameters`")
# verify the required parameter 'double' is set
if ('double' not in params) or (params['double'] is None):
raise ValueError("Missing the required parameter `double` when calling `test_endpoint_parameters`")
# verify the required parameter 'string' is set
if ('string' not in params) or (params['string'] is None):
raise ValueError("Missing the required parameter `string` when calling `test_endpoint_parameters`")
# verify the required parameter 'byte' is set
if ('byte' not in params) or (params['byte'] is None):
raise ValueError("Missing the required parameter `byte` when calling `test_endpoint_parameters`")
resource_path = '/fake'.replace('{format}', 'json')
path_params = {}
query_params = {}
header_params = {}
form_params = []
local_var_files = {}
if 'integer' in params:
form_params.append(('integer', params['integer']))
if 'int32' in params:
form_params.append(('int32', params['int32']))
if 'int64' in params:
form_params.append(('int64', params['int64']))
if 'number' in params:
form_params.append(('number', params['number']))
if 'float' in params:
form_params.append(('float', params['float']))
if 'double' in params:
form_params.append(('double', params['double']))
if 'string' in params:
form_params.append(('string', params['string']))
if 'byte' in params:
form_params.append(('byte', params['byte']))
if 'binary' in params:
form_params.append(('binary', params['binary']))
if 'date' in params:
form_params.append(('date', params['date']))
if 'date_time' in params:
form_params.append(('dateTime', params['date_time']))
if 'password' in params:
form_params.append(('password', params['password']))
body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.\
select_header_accept(['application/xml', 'application/json'])
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, 'POST',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type=None,
auth_settings=auth_settings,
callback=params.get('callback'))
return response

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.animal import Animal
class AnimalTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test Animal
"""
def testAnimal(self):
self.model = swagger_client.models.animal.Animal()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.api_response import ApiResponse
class ApiResponseTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test ApiResponse
"""
def testApiResponse(self):
self.model = swagger_client.models.api_response.ApiResponse()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.cat import Cat
class CatTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test Cat
"""
def testCat(self):
self.model = swagger_client.models.cat.Cat()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.category import Category
class CategoryTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test Category
"""
def testCategory(self):
self.model = swagger_client.models.category.Category()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.dog import Dog
class DogTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test Dog
"""
def testDog(self):
self.model = swagger_client.models.dog.Dog()

View File

@ -0,0 +1,40 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.apis.fake_api import FakeApi
class FakeApiTest(unittest.TestCase):
def setUp(self):
self.api = swagger_client.apis.fake_api.FakeApi()
def tearDown(self):
pass
def test_test_endpoint_parameters(self):
pass

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.format_test import FormatTest
class FormatTestTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test FormatTest
"""
def testFormatTest(self):
self.model = swagger_client.models.format_test.FormatTest()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.model_200_response import Model200Response
class Model200ResponseTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test Model200Response
"""
def testModel200Response(self):
self.model = swagger_client.models.model_200_response.Model200Response()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.model_return import ModelReturn
class ModelReturnTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test ModelReturn
"""
def testModelReturn(self):
self.model = swagger_client.models.model_return.ModelReturn()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.name import Name
class NameTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test Name
"""
def testName(self):
self.model = swagger_client.models.name.Name()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.order import Order
class OrderTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test Order
"""
def testOrder(self):
self.model = swagger_client.models.order.Order()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.pet import Pet
class PetTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test Pet
"""
def testPet(self):
self.model = swagger_client.models.pet.Pet()

View File

@ -1,168 +1,61 @@
# coding: utf-8
"""
Run the tests.
$ pip install nose (optional)
$ cd swagger_client-python
$ nosetests -v
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import time
import sys
import unittest
import swagger_client
from swagger_client.rest import ApiException
from swagger_client.apis.pet_api import PetApi
HOST = 'http://petstore.swagger.io/v2'
class PetApiTests(unittest.TestCase):
class PetApiTest(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()
self.api = swagger_client.apis.pet_api.PetApi()
def tearDown(self):
# sleep 1 sec between two every 2 tests
time.sleep(1)
pass
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 = "swagger-codegen-python-pet-tag"
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_async_request(self):
self.pet_api.add_pet(body=self.pet)
def callback_function(data):
self.assertIsNotNone(data)
self.assertEqual(data.id, self.pet.id)
self.assertEqual(data.name, self.pet.name)
self.assertIsNotNone(data.category)
self.assertEqual(data.category.id, self.pet.category.id)
self.assertEqual(data.category.name, self.pet.category.name)
self.assertTrue(isinstance(data.tags, list))
self.assertEqual(data.tags[0].id, self.pet.tags[0].id)
self.assertEqual(data.tags[0].name, self.pet.tags[0].name)
thread = self.pet_api.get_pet_by_id(pet_id=self.pet.id, callback=callback_function)
thread.join(10)
if thread.isAlive():
self.fail("Request timeout")
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):
# upload file with form parameter
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)))
# upload only file
try:
self.pet_api.upload_file(pet_id=self.pet.id, file=self.foo)
except ApiException as e:
self.fail("upload_file() raised {0} unexpectedly".format(type(e)))
def test_add_pet(self):
pass
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")
pass
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)
def test_find_pets_by_status(self):
pass
def test_find_pets_by_tags(self):
pass
def test_get_pet_by_id(self):
pass
def test_update_pet(self):
pass
def test_update_pet_with_form(self):
pass
def test_upload_file(self):
pass
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.special_model_name import SpecialModelName
class SpecialModelNameTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test SpecialModelName
"""
def testSpecialModelName(self):
self.model = swagger_client.models.special_model_name.SpecialModelName()

View File

@ -1,30 +1,49 @@
# coding: utf-8
"""
Run the tests.
$ pip install nose (optional)
$ cd SwaggerPetstore-python
$ nosetests -v
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import time
import sys
import unittest
import swagger_client
from swagger_client.rest import ApiException
from swagger_client.apis.store_api import StoreApi
class StoreApiTests(unittest.TestCase):
class StoreApiTest(unittest.TestCase):
def setUp(self):
self.store_api = swagger_client.StoreApi()
self.api = swagger_client.apis.store_api.StoreApi()
def tearDown(self):
# sleep 1 sec between two every 2 tests
time.sleep(1)
pass
def test_delete_order(self):
pass
def test_get_inventory(self):
data = self.store_api.get_inventory()
self.assertIsNotNone(data)
self.assertTrue(isinstance(data, dict))
pass
def test_get_order_by_id(self):
pass
def test_place_order(self):
pass

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.tag import Tag
class TagTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test Tag
"""
def testTag(self):
self.model = swagger_client.models.tag.Tag()

View File

@ -0,0 +1,44 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.models.user import User
class UserTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
"""
Test User
"""
def testUser(self):
self.model = swagger_client.models.user.User()

View File

@ -0,0 +1,61 @@
# coding: utf-8
"""
Copyright 2016 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.
ref: https://github.com/swagger-api/swagger-codegen
"""
from __future__ import absolute_import
import os
import sys
import unittest
import swagger_client
from swagger_client.apis.user_api import UserApi
class UserApiTest(unittest.TestCase):
def setUp(self):
self.api = swagger_client.apis.user_api.UserApi()
def tearDown(self):
pass
def test_create_user(self):
pass
def test_create_users_with_array_input(self):
pass
def test_create_users_with_list_input(self):
pass
def test_delete_user(self):
pass
def test_get_user_by_name(self):
pass
def test_login_user(self):
pass
def test_logout_user(self):
pass
def test_update_user(self):
pass