diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 5ccc9b24945..8a9b8accd38 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -2392,6 +2392,31 @@ public class DefaultCodegen { p.paramName = toParamName(bp.getName()); } + // Issue #2561 (neilotoole) : Set the isParam flags. + // This code has been moved to here from #fromOperation + // because these values should be set before calling #postProcessParameter. + // See: https://github.com/swagger-api/swagger-codegen/issues/2561 + if (param instanceof QueryParameter) { + p.isQueryParam = true; + } else if (param instanceof PathParameter) { + p.required = true; + p.isPathParam = true; + } else if (param instanceof HeaderParameter) { + p.isHeaderParam = true; + } else if (param instanceof CookieParameter) { + p.isCookieParam = true; + } else if (param instanceof BodyParameter) { + p.isBodyParam = true; + p.isBinary = isDataTypeBinary(p.dataType); + } else if (param instanceof FormParameter) { + if ("file".equalsIgnoreCase(((FormParameter) param).getType()) || "file".equals(p.baseType)) { + p.isFile = true; + } else { + p.notFile = true; + } + p.isFormParam = true; + } + // set the example value // if not specified in x-example, generate a default value if (p.vendorExtensions.containsKey("x-example")) { @@ -2416,10 +2441,7 @@ public class DefaultCodegen { p.example = "2013-10-20"; } else if (Boolean.TRUE.equals(p.isDateTime)) { p.example = "2013-10-20T19:20:30+01:00"; - } else if (param instanceof FormParameter && - ("file".equalsIgnoreCase(((FormParameter) param).getType()) || - "file".equals(p.baseType))) { - p.isFile = true; + } else if (Boolean.TRUE.equals(p.isFile)) { p.example = "/path/to/file.txt"; } @@ -2427,33 +2449,6 @@ public class DefaultCodegen { // should be overridden by lang codegen setParameterExampleValue(p); - // Issue #2561 (neilotoole) : Set the isParam flags. - // This code has been moved to here from #fromOperation - // because these values should be set before calling #postProcessParameter. - // See: https://github.com/swagger-api/swagger-codegen/issues/2561 - if (param instanceof QueryParameter) { - p.isQueryParam = true; - } else if (param instanceof PathParameter) { - p.required = true; - p.isPathParam = true; - } else if (param instanceof HeaderParameter) { - p.isHeaderParam = true; - } else if (param instanceof CookieParameter) { - p.isCookieParam = true; - } else if (param instanceof BodyParameter) { - p.isBodyParam = true; - p.isBinary = isDataTypeBinary(p.dataType); - } else if (param instanceof FormParameter) { - if ("file".equalsIgnoreCase(((FormParameter) param).getType())) { - p.isFile = true; - } else if("file".equals(p.baseType)){ - p.isFile = true; - } else { - p.notFile = true; - } - p.isFormParam = true; - } - postProcessParameter(p); return p; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java index 0a9f9589c8f..28a87ae7f17 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java @@ -10,6 +10,8 @@ import io.swagger.models.HttpMethod; import io.swagger.models.Operation; import io.swagger.models.Path; import io.swagger.models.Swagger; +import io.swagger.models.parameters.BodyParameter; +import io.swagger.models.parameters.FormParameter; import io.swagger.models.properties.*; import io.swagger.util.Yaml; @@ -36,6 +38,8 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf public FlaskConnexionCodegen() { super(); + modelPackage = "models"; + testPackage = "test"; languageSpecificPrimitives.clear(); languageSpecificPrimitives.add("int"); @@ -68,6 +72,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf apiTemplateFiles.put("controller.mustache", ".py"); modelTemplateFiles.put("model.mustache", ".py"); + apiTestTemplateFiles().put("controller_test.mustache", ".py"); /* * Template Location. This is the location which templates will be read from. The generator @@ -167,6 +172,11 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf modelPackage, "base_model_.py") ); + + supportingFiles.add(new SupportingFile("__init__test.mustache", + testPackage, + "__init__.py") + ); } private static String dropDots(String str) { @@ -178,6 +188,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf return controllerPackage; } + /** * Configures the type of generator. * @@ -225,6 +236,11 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf return underscore(toApiName(name)); } + @Override + public String toApiTestFilename(String name) { + return "test_" + toApiFilename(name); + } + /** * Escapes a reserved word as defined in the `reservedWords` array. Handle escaping * those terms here. This logic is only called if a variable matches the reseved words @@ -275,7 +291,6 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf return type; } - @Override public void preprocessSwagger(Swagger swagger) { // need vendor extensions for x-swagger-router-controller @@ -513,6 +528,93 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf return null; } + @Override + public void setParameterExampleValue(CodegenParameter p) { + String example; + + if (p.defaultValue == null) { + example = p.example; + } else { + example = p.defaultValue; + } + + String type = p.baseType; + if (type == null) { + type = p.dataType; + } + + if ("String".equalsIgnoreCase(type) || "str".equalsIgnoreCase(type)) { + if (example == null) { + example = p.paramName + "_example"; + } + example = "'" + escapeText(example) + "'"; + } else if ("Integer".equals(type) || "int".equals(type)) { + if(p.minimum != null) { + example = "" + (p.minimum.intValue() + 1); + } + if(p.maximum != null) { + example = "" + p.maximum.intValue(); + } else if (example == null) { + example = "56"; + } + + } else if ("Long".equalsIgnoreCase(type)) { + if(p.minimum != null) { + example = "" + (p.minimum.longValue() + 1); + } + if(p.maximum != null) { + example = "" + p.maximum.longValue(); + } else if (example == null) { + example = "789"; + } + } else if ("Float".equalsIgnoreCase(type) || "Double".equalsIgnoreCase(type)) { + if(p.minimum != null) { + example = "" + p.minimum; + } else if(p.maximum != null) { + example = "" + p.maximum; + } else if (example == null) { + example = "3.4"; + } + } else if ("BOOLEAN".equalsIgnoreCase(type) || "bool".equalsIgnoreCase(type)) { + if (example == null) { + example = "True"; + } + } else if ("file".equalsIgnoreCase(type)) { + example = "(BytesIO(b'some file data'), 'file.txt')"; + } else if ("Date".equalsIgnoreCase(type)) { + if (example == null) { + example = "2013-10-20"; + } + example = "'" + escapeText(example) + "'"; + } else if ("DateTime".equalsIgnoreCase(type)) { + if (example == null) { + example = "2013-10-20T19:20:30+01:00"; + } + example = "'" + escapeText(example) + "'"; + } else if (!languageSpecificPrimitives.contains(type)) { + // type is a model class, e.g. User + example = type + "()"; + } else { + LOGGER.warn("Type " + type + " not handled properly in setParameterExampleValue"); + } + + if(p.items != null && p.items.defaultValue != null) { + example = p.items.defaultValue; + } + if (example == null) { + example = "None"; + } else if (Boolean.TRUE.equals(p.isListContainer)) { + if (Boolean.TRUE.equals(p.isBodyParam)) { + example = "[" + example + "]"; + } + } else if (Boolean.TRUE.equals(p.isMapContainer)) { + example = "{'key': " + example + "}"; + } + + p.example = example; + } + + @Override public String escapeQuotationMark(String input) { // remove ' to avoid code injection diff --git a/modules/swagger-codegen/src/main/resources/flaskConnexion/README.mustache b/modules/swagger-codegen/src/main/resources/flaskConnexion/README.mustache index e037cf1fe15..2d64ddbccf6 100644 --- a/modules/swagger-codegen/src/main/resources/flaskConnexion/README.mustache +++ b/modules/swagger-codegen/src/main/resources/flaskConnexion/README.mustache @@ -11,11 +11,11 @@ To run the server, please execute the following: ``` {{#supportPython2}} -sudo pip install -U connexion typing # install Connexion and Typing from PyPI +sudo pip install -U connexion flask_testing typing # install Connexion from PyPI python app.py {{/supportPython2}} {{^supportPython2}} -sudo pip3 install -U connexion # install Connexion from PyPI +sudo pip3 install -U connexion flask_testing # install Connexion from PyPI python3 app.py {{/supportPython2}} ``` diff --git a/modules/swagger-codegen/src/main/resources/flaskConnexion/__init__test.mustache b/modules/swagger-codegen/src/main/resources/flaskConnexion/__init__test.mustache new file mode 100644 index 00000000000..352991098f1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/flaskConnexion/__init__test.mustache @@ -0,0 +1,14 @@ +from flask_testing import TestCase +from app import JSONEncoder +import connexion +import logging + + +class BaseTestCase(TestCase): + + def create_app(self): + logging.getLogger('connexion.operation').setLevel('ERROR') + app = connexion.App(__name__, specification_dir='../swagger/') + app.app.json_encoder = JSONEncoder + app.add_api('swagger.yaml') + return app.app diff --git a/modules/swagger-codegen/src/main/resources/flaskConnexion/controller_test.mustache b/modules/swagger-codegen/src/main/resources/flaskConnexion/controller_test.mustache new file mode 100644 index 00000000000..92024849418 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/flaskConnexion/controller_test.mustache @@ -0,0 +1,49 @@ +# coding: utf-8 + +from __future__ import absolute_import + +{{#imports}}{{import}} +{{/imports}} +from . import BaseTestCase +from six import BytesIO +from flask import json + + +class {{#operations}}Test{{classname}}(BaseTestCase): + """ {{classname}} integration test stubs """ + + {{#operation}} + def test_{{operationId}}(self): + """ + Test case for {{{operationId}}} + + {{{summary}}} + """ + {{#bodyParam}} + {{paramName}} = {{{example}}} + {{/bodyParam}} + {{#queryParams}} + {{#-first}}query_string = [{{/-first}}{{^-first}} {{/-first}}('{{paramName}}', {{{example}}}){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}} + {{/queryParams}} + {{#headerParams}} + {{#-first}}headers = [{{/-first}}{{^-first}} {{/-first}}('{{paramName}}', {{{example}}}){{#hasMore}},{{/hasMore}}{{#-last}}]{{/-last}} + {{/headerParams}} + {{#formParams}} + {{#-first}}data = dict({{/-first}}{{^-first}} {{/-first}}{{paramName}}={{{example}}}{{#hasMore}},{{/hasMore}}{{#-last}}){{/-last}} + {{/formParams}} + response = self.client.open('{{#contextPath}}{{.}}{{/contextPath}}{{path}}'{{#pathParams}}{{#-first}}.format({{/-first}}{{paramName}}={{{example}}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/pathParams}}, + method='{{httpMethod}}'{{#bodyParam}}, + data=json.dumps({{paramName}}){{^consumes}}, + content_type='application/json'{{/consumes}}{{/bodyParam}}{{#headerParams}}{{#-first}}, + headers=headers{{/-first}}{{/headerParams}}{{#formParams}}{{#-first}}, + data=data{{/-first}}{{/formParams}}{{#consumes}}{{#-first}}, + content_type='{{{mediaType}}}'{{/-first}}{{/consumes}}{{#queryParams}}{{#-first}}, + query_string=query_string{{/-first}}{{/queryParams}}) + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + {{/operation}} +{{/operations}} + +if __name__ == '__main__': + import unittest + unittest.main() diff --git a/samples/server/petstore/flaskConnexion-python2/README.md b/samples/server/petstore/flaskConnexion-python2/README.md index da392f1dd02..b744fc39f9a 100644 --- a/samples/server/petstore/flaskConnexion-python2/README.md +++ b/samples/server/petstore/flaskConnexion-python2/README.md @@ -10,7 +10,7 @@ This example uses the [Connexion](https://github.com/zalando/connexion) library To run the server, please execute the following: ``` -sudo pip install -U connexion typing # install Connexion and Typing from PyPI +sudo pip install -U connexion flask_testing typing # install Connexion from PyPI python app.py ``` diff --git a/samples/server/petstore/flaskConnexion-python2/controllers/pet_controller.py b/samples/server/petstore/flaskConnexion-python2/controllers/pet_controller.py index 461f6163a63..bd37fffc4f5 100644 --- a/samples/server/petstore/flaskConnexion-python2/controllers/pet_controller.py +++ b/samples/server/petstore/flaskConnexion-python2/controllers/pet_controller.py @@ -1,6 +1,6 @@ import connexion -from models.pet import Pet from models.api_response import ApiResponse +from models.pet import Pet from datetime import date, datetime from typing import List, Dict from six import iteritems diff --git a/samples/server/petstore/flaskConnexion-python2/test/__init__.py b/samples/server/petstore/flaskConnexion-python2/test/__init__.py new file mode 100644 index 00000000000..352991098f1 --- /dev/null +++ b/samples/server/petstore/flaskConnexion-python2/test/__init__.py @@ -0,0 +1,14 @@ +from flask_testing import TestCase +from app import JSONEncoder +import connexion +import logging + + +class BaseTestCase(TestCase): + + def create_app(self): + logging.getLogger('connexion.operation').setLevel('ERROR') + app = connexion.App(__name__, specification_dir='../swagger/') + app.app.json_encoder = JSONEncoder + app.add_api('swagger.yaml') + return app.app diff --git a/samples/server/petstore/flaskConnexion-python2/test/test_pet_controller.py b/samples/server/petstore/flaskConnexion-python2/test/test_pet_controller.py new file mode 100644 index 00000000000..50f0b523246 --- /dev/null +++ b/samples/server/petstore/flaskConnexion-python2/test/test_pet_controller.py @@ -0,0 +1,118 @@ +# coding: utf-8 + +from __future__ import absolute_import + +from models.api_response import ApiResponse +from models.pet import Pet +from . import BaseTestCase +from six import BytesIO +from flask import json + + +class TestPetController(BaseTestCase): + """ PetController integration test stubs """ + + def test_add_pet(self): + """ + Test case for add_pet + + Add a new pet to the store + """ + body = Pet() + response = self.client.open('/v2/pet', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_delete_pet(self): + """ + Test case for delete_pet + + Deletes a pet + """ + headers = [('apiKey', 'apiKey_example')] + response = self.client.open('/v2/pet/{petId}'.format(petId=789), + method='DELETE', + headers=headers) + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_find_pets_by_status(self): + """ + Test case for find_pets_by_status + + Finds Pets by status + """ + query_string = [('status', 'available')] + response = self.client.open('/v2/pet/findByStatus', + method='GET', + query_string=query_string) + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_find_pets_by_tags(self): + """ + Test case for find_pets_by_tags + + Finds Pets by tags + """ + query_string = [('tags', 'tags_example')] + response = self.client.open('/v2/pet/findByTags', + method='GET', + query_string=query_string) + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_get_pet_by_id(self): + """ + Test case for get_pet_by_id + + Find pet by ID + """ + response = self.client.open('/v2/pet/{petId}'.format(petId=789), + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_update_pet(self): + """ + Test case for update_pet + + Update an existing pet + """ + body = Pet() + response = self.client.open('/v2/pet', + method='PUT', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_update_pet_with_form(self): + """ + Test case for update_pet_with_form + + Updates a pet in the store with form data + """ + data = dict(name='name_example', + status='status_example') + response = self.client.open('/v2/pet/{petId}'.format(petId=789), + method='POST', + data=data, + content_type='application/x-www-form-urlencoded') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_upload_file(self): + """ + Test case for upload_file + + uploads an image + """ + data = dict(additionalMetadata='additionalMetadata_example', + file=(BytesIO(b'some file data'), 'file.txt')) + response = self.client.open('/v2/pet/{petId}/uploadImage'.format(petId=789), + method='POST', + data=data, + content_type='multipart/form-data') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + +if __name__ == '__main__': + import unittest + unittest.main() diff --git a/samples/server/petstore/flaskConnexion-python2/test/test_store_controller.py b/samples/server/petstore/flaskConnexion-python2/test/test_store_controller.py new file mode 100644 index 00000000000..33a007ae195 --- /dev/null +++ b/samples/server/petstore/flaskConnexion-python2/test/test_store_controller.py @@ -0,0 +1,60 @@ +# coding: utf-8 + +from __future__ import absolute_import + +from models.order import Order +from . import BaseTestCase +from six import BytesIO +from flask import json + + +class TestStoreController(BaseTestCase): + """ StoreController integration test stubs """ + + def test_delete_order(self): + """ + Test case for delete_order + + Delete purchase order by ID + """ + response = self.client.open('/v2/store/order/{orderId}'.format(orderId='orderId_example'), + method='DELETE') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_get_inventory(self): + """ + Test case for get_inventory + + Returns pet inventories by status + """ + response = self.client.open('/v2/store/inventory', + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_get_order_by_id(self): + """ + Test case for get_order_by_id + + Find purchase order by ID + """ + response = self.client.open('/v2/store/order/{orderId}'.format(orderId=5), + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_place_order(self): + """ + Test case for place_order + + Place an order for a pet + """ + body = Order() + response = self.client.open('/v2/store/order', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + +if __name__ == '__main__': + import unittest + unittest.main() diff --git a/samples/server/petstore/flaskConnexion-python2/test/test_user_controller.py b/samples/server/petstore/flaskConnexion-python2/test/test_user_controller.py new file mode 100644 index 00000000000..52dacf3df32 --- /dev/null +++ b/samples/server/petstore/flaskConnexion-python2/test/test_user_controller.py @@ -0,0 +1,112 @@ +# coding: utf-8 + +from __future__ import absolute_import + +from models.user import User +from . import BaseTestCase +from six import BytesIO +from flask import json + + +class TestUserController(BaseTestCase): + """ UserController integration test stubs """ + + def test_create_user(self): + """ + Test case for create_user + + Create user + """ + body = User() + response = self.client.open('/v2/user', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_create_users_with_array_input(self): + """ + Test case for create_users_with_array_input + + Creates list of users with given input array + """ + body = [User()] + response = self.client.open('/v2/user/createWithArray', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_create_users_with_list_input(self): + """ + Test case for create_users_with_list_input + + Creates list of users with given input array + """ + body = [User()] + response = self.client.open('/v2/user/createWithList', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_delete_user(self): + """ + Test case for delete_user + + Delete user + """ + response = self.client.open('/v2/user/{username}'.format(username='username_example'), + method='DELETE') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_get_user_by_name(self): + """ + Test case for get_user_by_name + + Get user by user name + """ + response = self.client.open('/v2/user/{username}'.format(username='username_example'), + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_login_user(self): + """ + Test case for login_user + + Logs user into the system + """ + query_string = [('username', 'username_example'), + ('password', 'password_example')] + response = self.client.open('/v2/user/login', + method='GET', + query_string=query_string) + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_logout_user(self): + """ + Test case for logout_user + + Logs out current logged in user session + """ + response = self.client.open('/v2/user/logout', + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_update_user(self): + """ + Test case for update_user + + Updated user + """ + body = User() + response = self.client.open('/v2/user/{username}'.format(username='username_example'), + method='PUT', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + +if __name__ == '__main__': + import unittest + unittest.main() diff --git a/samples/server/petstore/flaskConnexion/README.md b/samples/server/petstore/flaskConnexion/README.md index 933d4ec2723..0ba312c48ac 100644 --- a/samples/server/petstore/flaskConnexion/README.md +++ b/samples/server/petstore/flaskConnexion/README.md @@ -10,7 +10,7 @@ This example uses the [Connexion](https://github.com/zalando/connexion) library To run the server, please execute the following: ``` -sudo pip3 install -U connexion # install Connexion from PyPI +sudo pip3 install -U connexion flask_testing # install Connexion from PyPI python3 app.py ``` diff --git a/samples/server/petstore/flaskConnexion/controllers/pet_controller.py b/samples/server/petstore/flaskConnexion/controllers/pet_controller.py index 461f6163a63..bd37fffc4f5 100644 --- a/samples/server/petstore/flaskConnexion/controllers/pet_controller.py +++ b/samples/server/petstore/flaskConnexion/controllers/pet_controller.py @@ -1,6 +1,6 @@ import connexion -from models.pet import Pet from models.api_response import ApiResponse +from models.pet import Pet from datetime import date, datetime from typing import List, Dict from six import iteritems diff --git a/samples/server/petstore/flaskConnexion/test/__init__.py b/samples/server/petstore/flaskConnexion/test/__init__.py new file mode 100644 index 00000000000..352991098f1 --- /dev/null +++ b/samples/server/petstore/flaskConnexion/test/__init__.py @@ -0,0 +1,14 @@ +from flask_testing import TestCase +from app import JSONEncoder +import connexion +import logging + + +class BaseTestCase(TestCase): + + def create_app(self): + logging.getLogger('connexion.operation').setLevel('ERROR') + app = connexion.App(__name__, specification_dir='../swagger/') + app.app.json_encoder = JSONEncoder + app.add_api('swagger.yaml') + return app.app diff --git a/samples/server/petstore/flaskConnexion/test/test_pet_controller.py b/samples/server/petstore/flaskConnexion/test/test_pet_controller.py new file mode 100644 index 00000000000..50f0b523246 --- /dev/null +++ b/samples/server/petstore/flaskConnexion/test/test_pet_controller.py @@ -0,0 +1,118 @@ +# coding: utf-8 + +from __future__ import absolute_import + +from models.api_response import ApiResponse +from models.pet import Pet +from . import BaseTestCase +from six import BytesIO +from flask import json + + +class TestPetController(BaseTestCase): + """ PetController integration test stubs """ + + def test_add_pet(self): + """ + Test case for add_pet + + Add a new pet to the store + """ + body = Pet() + response = self.client.open('/v2/pet', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_delete_pet(self): + """ + Test case for delete_pet + + Deletes a pet + """ + headers = [('apiKey', 'apiKey_example')] + response = self.client.open('/v2/pet/{petId}'.format(petId=789), + method='DELETE', + headers=headers) + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_find_pets_by_status(self): + """ + Test case for find_pets_by_status + + Finds Pets by status + """ + query_string = [('status', 'available')] + response = self.client.open('/v2/pet/findByStatus', + method='GET', + query_string=query_string) + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_find_pets_by_tags(self): + """ + Test case for find_pets_by_tags + + Finds Pets by tags + """ + query_string = [('tags', 'tags_example')] + response = self.client.open('/v2/pet/findByTags', + method='GET', + query_string=query_string) + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_get_pet_by_id(self): + """ + Test case for get_pet_by_id + + Find pet by ID + """ + response = self.client.open('/v2/pet/{petId}'.format(petId=789), + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_update_pet(self): + """ + Test case for update_pet + + Update an existing pet + """ + body = Pet() + response = self.client.open('/v2/pet', + method='PUT', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_update_pet_with_form(self): + """ + Test case for update_pet_with_form + + Updates a pet in the store with form data + """ + data = dict(name='name_example', + status='status_example') + response = self.client.open('/v2/pet/{petId}'.format(petId=789), + method='POST', + data=data, + content_type='application/x-www-form-urlencoded') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_upload_file(self): + """ + Test case for upload_file + + uploads an image + """ + data = dict(additionalMetadata='additionalMetadata_example', + file=(BytesIO(b'some file data'), 'file.txt')) + response = self.client.open('/v2/pet/{petId}/uploadImage'.format(petId=789), + method='POST', + data=data, + content_type='multipart/form-data') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + +if __name__ == '__main__': + import unittest + unittest.main() diff --git a/samples/server/petstore/flaskConnexion/test/test_store_controller.py b/samples/server/petstore/flaskConnexion/test/test_store_controller.py new file mode 100644 index 00000000000..33a007ae195 --- /dev/null +++ b/samples/server/petstore/flaskConnexion/test/test_store_controller.py @@ -0,0 +1,60 @@ +# coding: utf-8 + +from __future__ import absolute_import + +from models.order import Order +from . import BaseTestCase +from six import BytesIO +from flask import json + + +class TestStoreController(BaseTestCase): + """ StoreController integration test stubs """ + + def test_delete_order(self): + """ + Test case for delete_order + + Delete purchase order by ID + """ + response = self.client.open('/v2/store/order/{orderId}'.format(orderId='orderId_example'), + method='DELETE') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_get_inventory(self): + """ + Test case for get_inventory + + Returns pet inventories by status + """ + response = self.client.open('/v2/store/inventory', + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_get_order_by_id(self): + """ + Test case for get_order_by_id + + Find purchase order by ID + """ + response = self.client.open('/v2/store/order/{orderId}'.format(orderId=5), + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_place_order(self): + """ + Test case for place_order + + Place an order for a pet + """ + body = Order() + response = self.client.open('/v2/store/order', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + +if __name__ == '__main__': + import unittest + unittest.main() diff --git a/samples/server/petstore/flaskConnexion/test/test_user_controller.py b/samples/server/petstore/flaskConnexion/test/test_user_controller.py new file mode 100644 index 00000000000..52dacf3df32 --- /dev/null +++ b/samples/server/petstore/flaskConnexion/test/test_user_controller.py @@ -0,0 +1,112 @@ +# coding: utf-8 + +from __future__ import absolute_import + +from models.user import User +from . import BaseTestCase +from six import BytesIO +from flask import json + + +class TestUserController(BaseTestCase): + """ UserController integration test stubs """ + + def test_create_user(self): + """ + Test case for create_user + + Create user + """ + body = User() + response = self.client.open('/v2/user', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_create_users_with_array_input(self): + """ + Test case for create_users_with_array_input + + Creates list of users with given input array + """ + body = [User()] + response = self.client.open('/v2/user/createWithArray', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_create_users_with_list_input(self): + """ + Test case for create_users_with_list_input + + Creates list of users with given input array + """ + body = [User()] + response = self.client.open('/v2/user/createWithList', + method='POST', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_delete_user(self): + """ + Test case for delete_user + + Delete user + """ + response = self.client.open('/v2/user/{username}'.format(username='username_example'), + method='DELETE') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_get_user_by_name(self): + """ + Test case for get_user_by_name + + Get user by user name + """ + response = self.client.open('/v2/user/{username}'.format(username='username_example'), + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_login_user(self): + """ + Test case for login_user + + Logs user into the system + """ + query_string = [('username', 'username_example'), + ('password', 'password_example')] + response = self.client.open('/v2/user/login', + method='GET', + query_string=query_string) + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_logout_user(self): + """ + Test case for logout_user + + Logs out current logged in user session + """ + response = self.client.open('/v2/user/logout', + method='GET') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + def test_update_user(self): + """ + Test case for update_user + + Updated user + """ + body = User() + response = self.client.open('/v2/user/{username}'.format(username='username_example'), + method='PUT', + data=json.dumps(body), + content_type='application/json') + self.assert200(response, "Response body is : " + response.data.decode('utf-8')) + + +if __name__ == '__main__': + import unittest + unittest.main()