From f59c43dffb1ca37c9e499730eefd384307f1e114 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 27 Apr 2016 20:53:48 +0100 Subject: [PATCH 1/3] Issue #2276 Auto generated test stubs --- .../languages/PythonClientCodegen.java | 30 +++ .../resources/python/__init__test.mustache | 0 .../main/resources/python/api_test.mustache | 43 ++++ .../main/resources/python/model_test.mustache | 48 +++++ samples/client/petstore/python/README.md | 2 +- .../client/petstore/python/docs/FakeApi.md | 77 +++++++ .../python/swagger_client/apis/fake_api.py | 165 +++++++++++++++ .../petstore/python/tests/test_animal.py | 44 ++++ .../python/tests/test_api_response.py | 44 ++++ .../client/petstore/python/tests/test_cat.py | 44 ++++ .../petstore/python/tests/test_category.py | 44 ++++ .../client/petstore/python/tests/test_dog.py | 44 ++++ .../petstore/python/tests/test_fake_api.py | 40 ++++ .../petstore/python/tests/test_format_test.py | 44 ++++ .../python/tests/test_model_200_response.py | 44 ++++ .../python/tests/test_model_return.py | 44 ++++ .../client/petstore/python/tests/test_name.py | 44 ++++ .../petstore/python/tests/test_order.py | 44 ++++ .../client/petstore/python/tests/test_pet.py | 44 ++++ .../petstore/python/tests/test_pet_api.py | 191 ++++-------------- .../python/tests/test_special_model_name.py | 44 ++++ .../petstore/python/tests/test_store_api.py | 47 +++-- .../client/petstore/python/tests/test_tag.py | 44 ++++ .../client/petstore/python/tests/test_user.py | 44 ++++ .../petstore/python/tests/test_user_api.py | 61 ++++++ 25 files changed, 1156 insertions(+), 164 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/python/__init__test.mustache create mode 100644 modules/swagger-codegen/src/main/resources/python/api_test.mustache create mode 100644 modules/swagger-codegen/src/main/resources/python/model_test.mustache create mode 100644 samples/client/petstore/python/docs/FakeApi.md create mode 100644 samples/client/petstore/python/swagger_client/apis/fake_api.py create mode 100644 samples/client/petstore/python/tests/test_animal.py create mode 100644 samples/client/petstore/python/tests/test_api_response.py create mode 100644 samples/client/petstore/python/tests/test_cat.py create mode 100644 samples/client/petstore/python/tests/test_category.py create mode 100644 samples/client/petstore/python/tests/test_dog.py create mode 100644 samples/client/petstore/python/tests/test_fake_api.py create mode 100644 samples/client/petstore/python/tests/test_format_test.py create mode 100644 samples/client/petstore/python/tests/test_model_200_response.py create mode 100644 samples/client/petstore/python/tests/test_model_return.py create mode 100644 samples/client/petstore/python/tests/test_name.py create mode 100644 samples/client/petstore/python/tests/test_order.py create mode 100644 samples/client/petstore/python/tests/test_pet.py create mode 100644 samples/client/petstore/python/tests/test_special_model_name.py create mode 100644 samples/client/petstore/python/tests/test_tag.py create mode 100644 samples/client/petstore/python/tests/test_user.py create mode 100644 samples/client/petstore/python/tests/test_user_api.py diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java index 7cb4dc703db..08d63c42676 100755 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java @@ -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) { diff --git a/modules/swagger-codegen/src/main/resources/python/__init__test.mustache b/modules/swagger-codegen/src/main/resources/python/__init__test.mustache new file mode 100644 index 00000000000..e69de29bb2d diff --git a/modules/swagger-codegen/src/main/resources/python/api_test.mustache b/modules/swagger-codegen/src/main/resources/python/api_test.mustache new file mode 100644 index 00000000000..78bd2062443 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/python/api_test.mustache @@ -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}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/python/model_test.mustache b/modules/swagger-codegen/src/main/resources/python/model_test.mustache new file mode 100644 index 00000000000..af4601de696 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/python/model_test.mustache @@ -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}} diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index 851c5458cb1..d29b88be8d5 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -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. diff --git a/samples/client/petstore/python/docs/FakeApi.md b/samples/client/petstore/python/docs/FakeApi.md new file mode 100644 index 00000000000..66d9a04434a --- /dev/null +++ b/samples/client/petstore/python/docs/FakeApi.md @@ -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) + diff --git a/samples/client/petstore/python/swagger_client/apis/fake_api.py b/samples/client/petstore/python/swagger_client/apis/fake_api.py new file mode 100644 index 00000000000..2b183794ef1 --- /dev/null +++ b/samples/client/petstore/python/swagger_client/apis/fake_api.py @@ -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 diff --git a/samples/client/petstore/python/tests/test_animal.py b/samples/client/petstore/python/tests/test_animal.py new file mode 100644 index 00000000000..337bbec0f1b --- /dev/null +++ b/samples/client/petstore/python/tests/test_animal.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_api_response.py b/samples/client/petstore/python/tests/test_api_response.py new file mode 100644 index 00000000000..d81daae1e9a --- /dev/null +++ b/samples/client/petstore/python/tests/test_api_response.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_cat.py b/samples/client/petstore/python/tests/test_cat.py new file mode 100644 index 00000000000..f72e4fd3209 --- /dev/null +++ b/samples/client/petstore/python/tests/test_cat.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_category.py b/samples/client/petstore/python/tests/test_category.py new file mode 100644 index 00000000000..1f7b1bda4d6 --- /dev/null +++ b/samples/client/petstore/python/tests/test_category.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_dog.py b/samples/client/petstore/python/tests/test_dog.py new file mode 100644 index 00000000000..d2b5b38048b --- /dev/null +++ b/samples/client/petstore/python/tests/test_dog.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_fake_api.py b/samples/client/petstore/python/tests/test_fake_api.py new file mode 100644 index 00000000000..a529e2c9b97 --- /dev/null +++ b/samples/client/petstore/python/tests/test_fake_api.py @@ -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 + diff --git a/samples/client/petstore/python/tests/test_format_test.py b/samples/client/petstore/python/tests/test_format_test.py new file mode 100644 index 00000000000..07aeac49b9a --- /dev/null +++ b/samples/client/petstore/python/tests/test_format_test.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_model_200_response.py b/samples/client/petstore/python/tests/test_model_200_response.py new file mode 100644 index 00000000000..cdae133c22b --- /dev/null +++ b/samples/client/petstore/python/tests/test_model_200_response.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_model_return.py b/samples/client/petstore/python/tests/test_model_return.py new file mode 100644 index 00000000000..60bda8fd99e --- /dev/null +++ b/samples/client/petstore/python/tests/test_model_return.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_name.py b/samples/client/petstore/python/tests/test_name.py new file mode 100644 index 00000000000..2e409620e48 --- /dev/null +++ b/samples/client/petstore/python/tests/test_name.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_order.py b/samples/client/petstore/python/tests/test_order.py new file mode 100644 index 00000000000..4a956567d1c --- /dev/null +++ b/samples/client/petstore/python/tests/test_order.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_pet.py b/samples/client/petstore/python/tests/test_pet.py new file mode 100644 index 00000000000..e44ce644c88 --- /dev/null +++ b/samples/client/petstore/python/tests/test_pet.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index 300a7bee783..e56fa6461ad 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -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() diff --git a/samples/client/petstore/python/tests/test_special_model_name.py b/samples/client/petstore/python/tests/test_special_model_name.py new file mode 100644 index 00000000000..1dd49228ead --- /dev/null +++ b/samples/client/petstore/python/tests/test_special_model_name.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_store_api.py b/samples/client/petstore/python/tests/test_store_api.py index 42b92d0879c..c22a3dc7134 100644 --- a/samples/client/petstore/python/tests/test_store_api.py +++ b/samples/client/petstore/python/tests/test_store_api.py @@ -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 + diff --git a/samples/client/petstore/python/tests/test_tag.py b/samples/client/petstore/python/tests/test_tag.py new file mode 100644 index 00000000000..e3b74cf0962 --- /dev/null +++ b/samples/client/petstore/python/tests/test_tag.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_user.py b/samples/client/petstore/python/tests/test_user.py new file mode 100644 index 00000000000..9fe3a9cb5ec --- /dev/null +++ b/samples/client/petstore/python/tests/test_user.py @@ -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() + diff --git a/samples/client/petstore/python/tests/test_user_api.py b/samples/client/petstore/python/tests/test_user_api.py new file mode 100644 index 00000000000..1d8b2f1fbd2 --- /dev/null +++ b/samples/client/petstore/python/tests/test_user_api.py @@ -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 + From 066baf3c1675ff000a0ee2efc5433ec5276d52f7 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 27 Apr 2016 22:02:48 +0100 Subject: [PATCH 2/3] Update comments in generated unit test stubs --- .../main/resources/python/api_test.mustache | 15 +++++- .../main/resources/python/model_test.mustache | 15 ++++-- samples/client/petstore/python/README.md | 2 +- .../petstore/python/tests/test_animal.py | 15 ++++-- .../python/tests/test_api_response.py | 15 ++++-- .../client/petstore/python/tests/test_cat.py | 15 ++++-- .../petstore/python/tests/test_category.py | 15 ++++-- .../client/petstore/python/tests/test_dog.py | 15 ++++-- .../petstore/python/tests/test_fake_api.py | 13 ++++- .../petstore/python/tests/test_format_test.py | 15 ++++-- .../python/tests/test_model_200_response.py | 15 ++++-- .../python/tests/test_model_return.py | 15 ++++-- .../client/petstore/python/tests/test_name.py | 15 ++++-- .../petstore/python/tests/test_order.py | 15 ++++-- .../client/petstore/python/tests/test_pet.py | 15 ++++-- .../petstore/python/tests/test_pet_api.py | 48 ++++++++++++++++++- .../python/tests/test_special_model_name.py | 15 ++++-- .../petstore/python/tests/test_store_api.py | 28 ++++++++++- .../client/petstore/python/tests/test_tag.py | 15 ++++-- .../client/petstore/python/tests/test_user.py | 15 ++++-- .../petstore/python/tests/test_user_api.py | 48 ++++++++++++++++++- 21 files changed, 297 insertions(+), 82 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/api_test.mustache b/modules/swagger-codegen/src/main/resources/python/api_test.mustache index 78bd2062443..5f0b0ab6ecb 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_test.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_test.mustache @@ -25,9 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.apis.{{classVarName}} import {{classname}} -class {{#operations}}{{classname}}Test(unittest.TestCase): + +class {{#operations}}Test{{classname}}(unittest.TestCase): + """ {{classname}} unit test stubs """ def setUp(self): self.api = swagger_client.apis.{{classVarName}}.{{classname}}() @@ -37,7 +40,15 @@ class {{#operations}}{{classname}}Test(unittest.TestCase): {{#operation}} def test_{{operationId}}(self): + """ + Test case for {{{operationId}}} + + {{{summary}}} + """ pass {{/operation}} -{{/operations}} \ No newline at end of file +{{/operations}} + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/python/model_test.mustache b/modules/swagger-codegen/src/main/resources/python/model_test.mustache index af4601de696..c00a10a9b51 100644 --- a/modules/swagger-codegen/src/main/resources/python/model_test.mustache +++ b/modules/swagger-codegen/src/main/resources/python/model_test.mustache @@ -27,10 +27,12 @@ import unittest {{#models}} {{#model}} import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.{{classFilename}} import {{classname}} -class {{classname}}Test(unittest.TestCase): +class Test{{classname}}(unittest.TestCase): + """ {{classname}} unit test stubs """ def setUp(self): pass @@ -38,11 +40,14 @@ class {{classname}}Test(unittest.TestCase): def tearDown(self): pass - """ - Test {{classname}} - """ def test{{classname}}(self): - self.model = swagger_client.models.{{classFilename}}.{{classname}}() + """ + Test {{classname}} + """ + model = swagger_client.models.{{classFilename}}.{{classname}}() {{/model}} {{/models}} + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index d29b88be8d5..df5514aac39 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -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-27T20:52:27.297+01:00 +- Build date: 2016-04-27T22:01:43.565+01:00 - Build package: class io.swagger.codegen.languages.PythonClientCodegen ## Requirements. diff --git a/samples/client/petstore/python/tests/test_animal.py b/samples/client/petstore/python/tests/test_animal.py index 337bbec0f1b..279ed1850dd 100644 --- a/samples/client/petstore/python/tests/test_animal.py +++ b/samples/client/petstore/python/tests/test_animal.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.animal import Animal -class AnimalTest(unittest.TestCase): +class TestAnimal(unittest.TestCase): + """ Animal unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class AnimalTest(unittest.TestCase): def tearDown(self): pass - """ - Test Animal - """ def testAnimal(self): - self.model = swagger_client.models.animal.Animal() + """ + Test Animal + """ + model = swagger_client.models.animal.Animal() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_api_response.py b/samples/client/petstore/python/tests/test_api_response.py index d81daae1e9a..be73dbf373d 100644 --- a/samples/client/petstore/python/tests/test_api_response.py +++ b/samples/client/petstore/python/tests/test_api_response.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.api_response import ApiResponse -class ApiResponseTest(unittest.TestCase): +class TestApiResponse(unittest.TestCase): + """ ApiResponse unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class ApiResponseTest(unittest.TestCase): def tearDown(self): pass - """ - Test ApiResponse - """ def testApiResponse(self): - self.model = swagger_client.models.api_response.ApiResponse() + """ + Test ApiResponse + """ + model = swagger_client.models.api_response.ApiResponse() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_cat.py b/samples/client/petstore/python/tests/test_cat.py index f72e4fd3209..728a824fa5b 100644 --- a/samples/client/petstore/python/tests/test_cat.py +++ b/samples/client/petstore/python/tests/test_cat.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.cat import Cat -class CatTest(unittest.TestCase): +class TestCat(unittest.TestCase): + """ Cat unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class CatTest(unittest.TestCase): def tearDown(self): pass - """ - Test Cat - """ def testCat(self): - self.model = swagger_client.models.cat.Cat() + """ + Test Cat + """ + model = swagger_client.models.cat.Cat() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_category.py b/samples/client/petstore/python/tests/test_category.py index 1f7b1bda4d6..793fbdf41b0 100644 --- a/samples/client/petstore/python/tests/test_category.py +++ b/samples/client/petstore/python/tests/test_category.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.category import Category -class CategoryTest(unittest.TestCase): +class TestCategory(unittest.TestCase): + """ Category unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class CategoryTest(unittest.TestCase): def tearDown(self): pass - """ - Test Category - """ def testCategory(self): - self.model = swagger_client.models.category.Category() + """ + Test Category + """ + model = swagger_client.models.category.Category() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_dog.py b/samples/client/petstore/python/tests/test_dog.py index d2b5b38048b..044dc5be51f 100644 --- a/samples/client/petstore/python/tests/test_dog.py +++ b/samples/client/petstore/python/tests/test_dog.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.dog import Dog -class DogTest(unittest.TestCase): +class TestDog(unittest.TestCase): + """ Dog unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class DogTest(unittest.TestCase): def tearDown(self): pass - """ - Test Dog - """ def testDog(self): - self.model = swagger_client.models.dog.Dog() + """ + Test Dog + """ + model = swagger_client.models.dog.Dog() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_fake_api.py b/samples/client/petstore/python/tests/test_fake_api.py index a529e2c9b97..29b71bdf81a 100644 --- a/samples/client/petstore/python/tests/test_fake_api.py +++ b/samples/client/petstore/python/tests/test_fake_api.py @@ -25,9 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.apis.fake_api import FakeApi -class FakeApiTest(unittest.TestCase): + +class TestFakeApi(unittest.TestCase): + """ FakeApi unit test stubs """ def setUp(self): self.api = swagger_client.apis.fake_api.FakeApi() @@ -36,5 +39,13 @@ class FakeApiTest(unittest.TestCase): pass def test_test_endpoint_parameters(self): + """ + Test case for test_endpoint_parameters + + Fake endpoint for testing various parameters + """ pass + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_format_test.py b/samples/client/petstore/python/tests/test_format_test.py index 07aeac49b9a..11101ad52da 100644 --- a/samples/client/petstore/python/tests/test_format_test.py +++ b/samples/client/petstore/python/tests/test_format_test.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.format_test import FormatTest -class FormatTestTest(unittest.TestCase): +class TestFormatTest(unittest.TestCase): + """ FormatTest unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class FormatTestTest(unittest.TestCase): def tearDown(self): pass - """ - Test FormatTest - """ def testFormatTest(self): - self.model = swagger_client.models.format_test.FormatTest() + """ + Test FormatTest + """ + model = swagger_client.models.format_test.FormatTest() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_model_200_response.py b/samples/client/petstore/python/tests/test_model_200_response.py index cdae133c22b..8328d2b9757 100644 --- a/samples/client/petstore/python/tests/test_model_200_response.py +++ b/samples/client/petstore/python/tests/test_model_200_response.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.model_200_response import Model200Response -class Model200ResponseTest(unittest.TestCase): +class TestModel200Response(unittest.TestCase): + """ Model200Response unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class Model200ResponseTest(unittest.TestCase): def tearDown(self): pass - """ - Test Model200Response - """ def testModel200Response(self): - self.model = swagger_client.models.model_200_response.Model200Response() + """ + Test Model200Response + """ + model = swagger_client.models.model_200_response.Model200Response() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_model_return.py b/samples/client/petstore/python/tests/test_model_return.py index 60bda8fd99e..4ff3f38b2eb 100644 --- a/samples/client/petstore/python/tests/test_model_return.py +++ b/samples/client/petstore/python/tests/test_model_return.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.model_return import ModelReturn -class ModelReturnTest(unittest.TestCase): +class TestModelReturn(unittest.TestCase): + """ ModelReturn unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class ModelReturnTest(unittest.TestCase): def tearDown(self): pass - """ - Test ModelReturn - """ def testModelReturn(self): - self.model = swagger_client.models.model_return.ModelReturn() + """ + Test ModelReturn + """ + model = swagger_client.models.model_return.ModelReturn() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_name.py b/samples/client/petstore/python/tests/test_name.py index 2e409620e48..c3b27897eb1 100644 --- a/samples/client/petstore/python/tests/test_name.py +++ b/samples/client/petstore/python/tests/test_name.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.name import Name -class NameTest(unittest.TestCase): +class TestName(unittest.TestCase): + """ Name unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class NameTest(unittest.TestCase): def tearDown(self): pass - """ - Test Name - """ def testName(self): - self.model = swagger_client.models.name.Name() + """ + Test Name + """ + model = swagger_client.models.name.Name() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_order.py b/samples/client/petstore/python/tests/test_order.py index 4a956567d1c..23beefe346c 100644 --- a/samples/client/petstore/python/tests/test_order.py +++ b/samples/client/petstore/python/tests/test_order.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.order import Order -class OrderTest(unittest.TestCase): +class TestOrder(unittest.TestCase): + """ Order unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class OrderTest(unittest.TestCase): def tearDown(self): pass - """ - Test Order - """ def testOrder(self): - self.model = swagger_client.models.order.Order() + """ + Test Order + """ + model = swagger_client.models.order.Order() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_pet.py b/samples/client/petstore/python/tests/test_pet.py index e44ce644c88..471b7b4f67c 100644 --- a/samples/client/petstore/python/tests/test_pet.py +++ b/samples/client/petstore/python/tests/test_pet.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.pet import Pet -class PetTest(unittest.TestCase): +class TestPet(unittest.TestCase): + """ Pet unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class PetTest(unittest.TestCase): def tearDown(self): pass - """ - Test Pet - """ def testPet(self): - self.model = swagger_client.models.pet.Pet() + """ + Test Pet + """ + model = swagger_client.models.pet.Pet() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index e56fa6461ad..81ee6c76e9c 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -25,9 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.apis.pet_api import PetApi -class PetApiTest(unittest.TestCase): + +class TestPetApi(unittest.TestCase): + """ PetApi unit test stubs """ def setUp(self): self.api = swagger_client.apis.pet_api.PetApi() @@ -36,26 +39,69 @@ class PetApiTest(unittest.TestCase): pass def test_add_pet(self): + """ + Test case for add_pet + + Add a new pet to the store + """ pass def test_delete_pet(self): + """ + Test case for delete_pet + + Deletes a pet + """ pass def test_find_pets_by_status(self): + """ + Test case for find_pets_by_status + + Finds Pets by status + """ pass def test_find_pets_by_tags(self): + """ + Test case for find_pets_by_tags + + Finds Pets by tags + """ pass def test_get_pet_by_id(self): + """ + Test case for get_pet_by_id + + Find pet by ID + """ pass def test_update_pet(self): + """ + Test case for update_pet + + Update an existing pet + """ pass def test_update_pet_with_form(self): + """ + Test case for update_pet_with_form + + Updates a pet in the store with form data + """ pass def test_upload_file(self): + """ + Test case for upload_file + + uploads an image + """ pass + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_special_model_name.py b/samples/client/petstore/python/tests/test_special_model_name.py index 1dd49228ead..17c12655031 100644 --- a/samples/client/petstore/python/tests/test_special_model_name.py +++ b/samples/client/petstore/python/tests/test_special_model_name.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.special_model_name import SpecialModelName -class SpecialModelNameTest(unittest.TestCase): +class TestSpecialModelName(unittest.TestCase): + """ SpecialModelName unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class SpecialModelNameTest(unittest.TestCase): def tearDown(self): pass - """ - Test SpecialModelName - """ def testSpecialModelName(self): - self.model = swagger_client.models.special_model_name.SpecialModelName() + """ + Test SpecialModelName + """ + model = swagger_client.models.special_model_name.SpecialModelName() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_store_api.py b/samples/client/petstore/python/tests/test_store_api.py index c22a3dc7134..e8dc0a64b1c 100644 --- a/samples/client/petstore/python/tests/test_store_api.py +++ b/samples/client/petstore/python/tests/test_store_api.py @@ -25,9 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.apis.store_api import StoreApi -class StoreApiTest(unittest.TestCase): + +class TestStoreApi(unittest.TestCase): + """ StoreApi unit test stubs """ def setUp(self): self.api = swagger_client.apis.store_api.StoreApi() @@ -36,14 +39,37 @@ class StoreApiTest(unittest.TestCase): pass def test_delete_order(self): + """ + Test case for delete_order + + Delete purchase order by ID + """ pass def test_get_inventory(self): + """ + Test case for get_inventory + + Returns pet inventories by status + """ pass def test_get_order_by_id(self): + """ + Test case for get_order_by_id + + Find purchase order by ID + """ pass def test_place_order(self): + """ + Test case for place_order + + Place an order for a pet + """ pass + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_tag.py b/samples/client/petstore/python/tests/test_tag.py index e3b74cf0962..35b51e4d7d2 100644 --- a/samples/client/petstore/python/tests/test_tag.py +++ b/samples/client/petstore/python/tests/test_tag.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.tag import Tag -class TagTest(unittest.TestCase): +class TestTag(unittest.TestCase): + """ Tag unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class TagTest(unittest.TestCase): def tearDown(self): pass - """ - Test Tag - """ def testTag(self): - self.model = swagger_client.models.tag.Tag() + """ + Test Tag + """ + model = swagger_client.models.tag.Tag() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_user.py b/samples/client/petstore/python/tests/test_user.py index 9fe3a9cb5ec..1aad154cbf8 100644 --- a/samples/client/petstore/python/tests/test_user.py +++ b/samples/client/petstore/python/tests/test_user.py @@ -25,10 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.models.user import User -class UserTest(unittest.TestCase): +class TestUser(unittest.TestCase): + """ User unit test stubs """ def setUp(self): pass @@ -36,9 +38,12 @@ class UserTest(unittest.TestCase): def tearDown(self): pass - """ - Test User - """ def testUser(self): - self.model = swagger_client.models.user.User() + """ + Test User + """ + model = swagger_client.models.user.User() + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_user_api.py b/samples/client/petstore/python/tests/test_user_api.py index 1d8b2f1fbd2..0205fe7383a 100644 --- a/samples/client/petstore/python/tests/test_user_api.py +++ b/samples/client/petstore/python/tests/test_user_api.py @@ -25,9 +25,12 @@ import sys import unittest import swagger_client +from swagger_client.rest import ApiException from swagger_client.apis.user_api import UserApi -class UserApiTest(unittest.TestCase): + +class TestUserApi(unittest.TestCase): + """ UserApi unit test stubs """ def setUp(self): self.api = swagger_client.apis.user_api.UserApi() @@ -36,26 +39,69 @@ class UserApiTest(unittest.TestCase): pass def test_create_user(self): + """ + Test case for create_user + + Create user + """ pass def test_create_users_with_array_input(self): + """ + Test case for create_users_with_array_input + + Creates list of users with given input array + """ pass def test_create_users_with_list_input(self): + """ + Test case for create_users_with_list_input + + Creates list of users with given input array + """ pass def test_delete_user(self): + """ + Test case for delete_user + + Delete user + """ pass def test_get_user_by_name(self): + """ + Test case for get_user_by_name + + Get user by user name + """ pass def test_login_user(self): + """ + Test case for login_user + + Logs user into the system + """ pass def test_logout_user(self): + """ + Test case for logout_user + + Logs out current logged in user session + """ pass def test_update_user(self): + """ + Test case for update_user + + Updated user + """ pass + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 1674ec3799a9478231f5f7d5948e4f324e38b800 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 27 Apr 2016 22:53:22 +0100 Subject: [PATCH 3/3] Fix generated test directory name conflicting with sample test directory name --- .../languages/PythonClientCodegen.java | 2 +- samples/client/petstore/python/README.md | 2 +- .../swagger_client.egg-info/top_level.txt | 1 + .../client/petstore/python/test/__init__.py | 0 .../python/{tests => test}/test_animal.py | 0 .../{tests => test}/test_api_response.py | 0 .../python/{tests => test}/test_cat.py | 0 .../python/{tests => test}/test_category.py | 0 .../python/{tests => test}/test_dog.py | 0 .../python/{tests => test}/test_fake_api.py | 0 .../{tests => test}/test_format_test.py | 0 .../test_model_200_response.py | 0 .../{tests => test}/test_model_return.py | 0 .../python/{tests => test}/test_name.py | 0 .../python/{tests => test}/test_order.py | 0 .../python/{tests => test}/test_pet.py | 0 .../petstore/python/test/test_pet_api.py | 107 ++++++++++ .../test_special_model_name.py | 0 .../petstore/python/test/test_store_api.py | 75 +++++++ .../python/{tests => test}/test_tag.py | 0 .../python/{tests => test}/test_user.py | 0 .../python/{tests => test}/test_user_api.py | 0 .../petstore/python/tests/test_pet_api.py | 201 ++++++++++++------ .../petstore/python/tests/test_store_api.py | 69 ++---- 24 files changed, 328 insertions(+), 129 deletions(-) create mode 100644 samples/client/petstore/python/test/__init__.py rename samples/client/petstore/python/{tests => test}/test_animal.py (100%) rename samples/client/petstore/python/{tests => test}/test_api_response.py (100%) rename samples/client/petstore/python/{tests => test}/test_cat.py (100%) rename samples/client/petstore/python/{tests => test}/test_category.py (100%) rename samples/client/petstore/python/{tests => test}/test_dog.py (100%) rename samples/client/petstore/python/{tests => test}/test_fake_api.py (100%) rename samples/client/petstore/python/{tests => test}/test_format_test.py (100%) rename samples/client/petstore/python/{tests => test}/test_model_200_response.py (100%) rename samples/client/petstore/python/{tests => test}/test_model_return.py (100%) rename samples/client/petstore/python/{tests => test}/test_name.py (100%) rename samples/client/petstore/python/{tests => test}/test_order.py (100%) rename samples/client/petstore/python/{tests => test}/test_pet.py (100%) create mode 100644 samples/client/petstore/python/test/test_pet_api.py rename samples/client/petstore/python/{tests => test}/test_special_model_name.py (100%) create mode 100644 samples/client/petstore/python/test/test_store_api.py rename samples/client/petstore/python/{tests => test}/test_tag.py (100%) rename samples/client/petstore/python/{tests => test}/test_user.py (100%) rename samples/client/petstore/python/{tests => test}/test_user_api.py (100%) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java index 08d63c42676..1bc95cfdd67 100755 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java @@ -41,7 +41,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig modelDocTemplateFiles.put("model_doc.mustache", ".md"); apiDocTemplateFiles.put("api_doc.mustache", ".md"); - testFolder = "tests"; + testFolder = "test"; languageSpecificPrimitives.clear(); languageSpecificPrimitives.add("int"); diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index df5514aac39..6640785fae9 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -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-27T22:01:43.565+01:00 +- Build date: 2016-04-27T22:50:21.115+01:00 - Build package: class io.swagger.codegen.languages.PythonClientCodegen ## Requirements. diff --git a/samples/client/petstore/python/swagger_client.egg-info/top_level.txt b/samples/client/petstore/python/swagger_client.egg-info/top_level.txt index 9a02a75c058..01f6691e7ca 100644 --- a/samples/client/petstore/python/swagger_client.egg-info/top_level.txt +++ b/samples/client/petstore/python/swagger_client.egg-info/top_level.txt @@ -1,2 +1,3 @@ swagger_client +test tests diff --git a/samples/client/petstore/python/test/__init__.py b/samples/client/petstore/python/test/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/client/petstore/python/tests/test_animal.py b/samples/client/petstore/python/test/test_animal.py similarity index 100% rename from samples/client/petstore/python/tests/test_animal.py rename to samples/client/petstore/python/test/test_animal.py diff --git a/samples/client/petstore/python/tests/test_api_response.py b/samples/client/petstore/python/test/test_api_response.py similarity index 100% rename from samples/client/petstore/python/tests/test_api_response.py rename to samples/client/petstore/python/test/test_api_response.py diff --git a/samples/client/petstore/python/tests/test_cat.py b/samples/client/petstore/python/test/test_cat.py similarity index 100% rename from samples/client/petstore/python/tests/test_cat.py rename to samples/client/petstore/python/test/test_cat.py diff --git a/samples/client/petstore/python/tests/test_category.py b/samples/client/petstore/python/test/test_category.py similarity index 100% rename from samples/client/petstore/python/tests/test_category.py rename to samples/client/petstore/python/test/test_category.py diff --git a/samples/client/petstore/python/tests/test_dog.py b/samples/client/petstore/python/test/test_dog.py similarity index 100% rename from samples/client/petstore/python/tests/test_dog.py rename to samples/client/petstore/python/test/test_dog.py diff --git a/samples/client/petstore/python/tests/test_fake_api.py b/samples/client/petstore/python/test/test_fake_api.py similarity index 100% rename from samples/client/petstore/python/tests/test_fake_api.py rename to samples/client/petstore/python/test/test_fake_api.py diff --git a/samples/client/petstore/python/tests/test_format_test.py b/samples/client/petstore/python/test/test_format_test.py similarity index 100% rename from samples/client/petstore/python/tests/test_format_test.py rename to samples/client/petstore/python/test/test_format_test.py diff --git a/samples/client/petstore/python/tests/test_model_200_response.py b/samples/client/petstore/python/test/test_model_200_response.py similarity index 100% rename from samples/client/petstore/python/tests/test_model_200_response.py rename to samples/client/petstore/python/test/test_model_200_response.py diff --git a/samples/client/petstore/python/tests/test_model_return.py b/samples/client/petstore/python/test/test_model_return.py similarity index 100% rename from samples/client/petstore/python/tests/test_model_return.py rename to samples/client/petstore/python/test/test_model_return.py diff --git a/samples/client/petstore/python/tests/test_name.py b/samples/client/petstore/python/test/test_name.py similarity index 100% rename from samples/client/petstore/python/tests/test_name.py rename to samples/client/petstore/python/test/test_name.py diff --git a/samples/client/petstore/python/tests/test_order.py b/samples/client/petstore/python/test/test_order.py similarity index 100% rename from samples/client/petstore/python/tests/test_order.py rename to samples/client/petstore/python/test/test_order.py diff --git a/samples/client/petstore/python/tests/test_pet.py b/samples/client/petstore/python/test/test_pet.py similarity index 100% rename from samples/client/petstore/python/tests/test_pet.py rename to samples/client/petstore/python/test/test_pet.py diff --git a/samples/client/petstore/python/test/test_pet_api.py b/samples/client/petstore/python/test/test_pet_api.py new file mode 100644 index 00000000000..81ee6c76e9c --- /dev/null +++ b/samples/client/petstore/python/test/test_pet_api.py @@ -0,0 +1,107 @@ +# 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.rest import ApiException +from swagger_client.apis.pet_api import PetApi + + +class TestPetApi(unittest.TestCase): + """ PetApi unit test stubs """ + + def setUp(self): + self.api = swagger_client.apis.pet_api.PetApi() + + def tearDown(self): + pass + + def test_add_pet(self): + """ + Test case for add_pet + + Add a new pet to the store + """ + pass + + def test_delete_pet(self): + """ + Test case for delete_pet + + Deletes a pet + """ + pass + + def test_find_pets_by_status(self): + """ + Test case for find_pets_by_status + + Finds Pets by status + """ + pass + + def test_find_pets_by_tags(self): + """ + Test case for find_pets_by_tags + + Finds Pets by tags + """ + pass + + def test_get_pet_by_id(self): + """ + Test case for get_pet_by_id + + Find pet by ID + """ + pass + + def test_update_pet(self): + """ + Test case for update_pet + + Update an existing pet + """ + pass + + def test_update_pet_with_form(self): + """ + Test case for update_pet_with_form + + Updates a pet in the store with form data + """ + pass + + def test_upload_file(self): + """ + Test case for upload_file + + uploads an image + """ + pass + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_special_model_name.py b/samples/client/petstore/python/test/test_special_model_name.py similarity index 100% rename from samples/client/petstore/python/tests/test_special_model_name.py rename to samples/client/petstore/python/test/test_special_model_name.py diff --git a/samples/client/petstore/python/test/test_store_api.py b/samples/client/petstore/python/test/test_store_api.py new file mode 100644 index 00000000000..e8dc0a64b1c --- /dev/null +++ b/samples/client/petstore/python/test/test_store_api.py @@ -0,0 +1,75 @@ +# 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.rest import ApiException +from swagger_client.apis.store_api import StoreApi + + +class TestStoreApi(unittest.TestCase): + """ StoreApi unit test stubs """ + + def setUp(self): + self.api = swagger_client.apis.store_api.StoreApi() + + def tearDown(self): + pass + + def test_delete_order(self): + """ + Test case for delete_order + + Delete purchase order by ID + """ + pass + + def test_get_inventory(self): + """ + Test case for get_inventory + + Returns pet inventories by status + """ + pass + + def test_get_order_by_id(self): + """ + Test case for get_order_by_id + + Find purchase order by ID + """ + pass + + def test_place_order(self): + """ + Test case for place_order + + Place an order for a pet + """ + pass + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/samples/client/petstore/python/tests/test_tag.py b/samples/client/petstore/python/test/test_tag.py similarity index 100% rename from samples/client/petstore/python/tests/test_tag.py rename to samples/client/petstore/python/test/test_tag.py diff --git a/samples/client/petstore/python/tests/test_user.py b/samples/client/petstore/python/test/test_user.py similarity index 100% rename from samples/client/petstore/python/tests/test_user.py rename to samples/client/petstore/python/test/test_user.py diff --git a/samples/client/petstore/python/tests/test_user_api.py b/samples/client/petstore/python/test/test_user_api.py similarity index 100% rename from samples/client/petstore/python/tests/test_user_api.py rename to samples/client/petstore/python/test/test_user_api.py diff --git a/samples/client/petstore/python/tests/test_pet_api.py b/samples/client/petstore/python/tests/test_pet_api.py index 81ee6c76e9c..300a7bee783 100644 --- a/samples/client/petstore/python/tests/test_pet_api.py +++ b/samples/client/petstore/python/tests/test_pet_api.py @@ -1,107 +1,168 @@ # 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 +Run the tests. +$ pip install nose (optional) +$ cd swagger_client-python +$ nosetests -v """ -from __future__ import absolute_import - import os -import sys +import time 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 TestPetApi(unittest.TestCase): - """ PetApi unit test stubs """ +class PetApiTests(unittest.TestCase): def setUp(self): - self.api = swagger_client.apis.pet_api.PetApi() + self.api_client = swagger_client.ApiClient(HOST) + self.pet_api = swagger_client.PetApi(self.api_client) + self.setUpModels() + self.setUpFiles() def tearDown(self): - pass + # sleep 1 sec between two every 2 tests + time.sleep(1) - def test_add_pet(self): - """ - Test case for add_pet + 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] - Add a new pet to the store - """ - pass + 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_delete_pet(self): - """ - Test case for delete_pet + 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) - Deletes a pet - """ - pass + # 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_find_pets_by_status(self): - """ - Test case for find_pets_by_status + def test_async_request(self): + self.pet_api.add_pet(body=self.pet) - Finds Pets by status - """ - pass + 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) - def test_find_pets_by_tags(self): - """ - Test case for find_pets_by_tags + 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") - Finds Pets by tags - """ - pass + def test_add_pet_and_get_pet_by_id(self): + self.pet_api.add_pet(body=self.pet) - def test_get_pet_by_id(self): - """ - Test case for get_pet_by_id - - Find pet by ID - """ - pass + 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): - """ - Test case for update_pet + self.pet.name = "hello kity with updated" + self.pet_api.update_pet(body=self.pet) - Update an existing pet - """ - pass + 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): - """ - Test case for update_pet_with_form + self.pet_api.add_pet(body=self.pet) - Updates a pet in the store with form data - """ - pass + 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): - """ - Test case for upload_file + # 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))) - uploads an image - """ - pass + # 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_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() \ No newline at end of file + unittest.main() diff --git a/samples/client/petstore/python/tests/test_store_api.py b/samples/client/petstore/python/tests/test_store_api.py index e8dc0a64b1c..42b92d0879c 100644 --- a/samples/client/petstore/python/tests/test_store_api.py +++ b/samples/client/petstore/python/tests/test_store_api.py @@ -1,75 +1,30 @@ # 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 +Run the tests. +$ pip install nose (optional) +$ cd SwaggerPetstore-python +$ nosetests -v """ -from __future__ import absolute_import - import os -import sys +import time import unittest import swagger_client from swagger_client.rest import ApiException -from swagger_client.apis.store_api import StoreApi -class TestStoreApi(unittest.TestCase): - """ StoreApi unit test stubs """ +class StoreApiTests(unittest.TestCase): def setUp(self): - self.api = swagger_client.apis.store_api.StoreApi() + self.store_api = swagger_client.StoreApi() def tearDown(self): - pass - - def test_delete_order(self): - """ - Test case for delete_order - - Delete purchase order by ID - """ - pass + # sleep 1 sec between two every 2 tests + time.sleep(1) def test_get_inventory(self): - """ - Test case for get_inventory - - Returns pet inventories by status - """ - pass - - def test_get_order_by_id(self): - """ - Test case for get_order_by_id - - Find purchase order by ID - """ - pass - - def test_place_order(self): - """ - Test case for place_order - - Place an order for a pet - """ - pass - - -if __name__ == '__main__': - unittest.main() \ No newline at end of file + data = self.store_api.get_inventory() + self.assertIsNotNone(data) + self.assertTrue(isinstance(data, dict))