Skip to content

Add test cases for Python Client #2727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,28 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
protected String packageVersion;
protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/";

private String testFolder;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI. I'll make minor change to replace tab indentation with 4-space later.


public PythonClientCodegen() {
super();

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 = "test";

languageSpecificPrimitives.clear();
languageSpecificPrimitives.add("int");
Expand Down Expand Up @@ -126,6 +135,7 @@ public void processOpts() {
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"));
}
Expand Down Expand Up @@ -184,6 +194,16 @@ public String apiFileFolder() {
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) {
Expand Down Expand Up @@ -310,6 +330,11 @@ public String toModelFilename(String name) {
// PhoneNumber => phone_number
return underscore(dropDots(name));
}

@Override
public String toModelTestFilename(String name) {
return "test_" + toModelFilename(name);
};

@Override
public String toApiFilename(String name) {
Expand All @@ -319,6 +344,11 @@ public String toApiFilename(String name) {
// 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) {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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.{{classVarName}} import {{classname}}


class {{#operations}}Test{{classname}}(unittest.TestCase):
""" {{classname}} unit test stubs """

def setUp(self):
self.api = swagger_client.apis.{{classVarName}}.{{classname}}()

def tearDown(self):
pass

{{#operation}}
def test_{{operationId}}(self):
"""
Test case for {{{operationId}}}

{{{summary}}}
"""
pass

{{/operation}}
{{/operations}}

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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.rest import ApiException
from swagger_client.models.{{classFilename}} import {{classname}}


class Test{{classname}}(unittest.TestCase):
""" {{classname}} unit test stubs """

def setUp(self):
pass

def tearDown(self):
pass

def test{{classname}}(self):
"""
Test {{classname}}
"""
model = swagger_client.models.{{classFilename}}.{{classname}}()

{{/model}}
{{/models}}

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion samples/client/petstore/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-27T22:50:21.115+01:00
- Build package: class io.swagger.codegen.languages.PythonClientCodegen

## Requirements.
Expand Down
77 changes: 77 additions & 0 deletions samples/client/petstore/python/docs/FakeApi.md
Original file line number Diff line number Diff line change
@@ -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)

Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
swagger_client
test
tests
Loading