[python-flask] Apply template tweaks to improve lint results (#6826)

The linting results for the generated samples are as follows
where the first number is the BEFORE and the second is AFTER.

flaskConnexion          1843 vs. 20
flaskConnexion-python2  1841 vs. 19

For the complete details please see the following gist.
https://gist.github.com/kenjones-cisco/edc9d71ef7fd2bf23714ecbb693d52b3
This commit is contained in:
Kenny Jones
2017-10-27 10:18:14 -04:00
committed by wing328
parent f472b623f0
commit 28d14e34c4
46 changed files with 1276 additions and 1239 deletions

View File

@@ -1,8 +1,10 @@
from flask_testing import TestCase
from ..encoder import JSONEncoder
import connexion
import logging
import connexion
from flask_testing import TestCase
from swagger_server.encoder import JSONEncoder
class BaseTestCase(TestCase):

View File

@@ -2,115 +2,124 @@
from __future__ import absolute_import
from swagger_server.models.api_response import ApiResponse
from swagger_server.models.pet import Pet
from . import BaseTestCase
from six import BytesIO
from flask import json
from six import BytesIO
from swagger_server.models.api_response import ApiResponse # noqa: E501
from swagger_server.models.pet import Pet # noqa: E501
from swagger_server.test import BaseTestCase
class TestPetController(BaseTestCase):
""" PetController integration test stubs """
"""PetController integration test stubs"""
def test_add_pet(self):
"""
Test case for add_pet
"""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'))
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
"""Test case for delete_pet
Deletes a pet
"""
headers = [('api_key', 'api_key_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'))
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
"""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'))
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
"""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'))
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
"""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'))
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
"""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'))
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
"""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'))
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
"""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'))
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__':

View File

@@ -2,57 +2,62 @@
from __future__ import absolute_import
from swagger_server.models.order import Order
from . import BaseTestCase
from six import BytesIO
from flask import json
from six import BytesIO
from swagger_server.models.order import Order # noqa: E501
from swagger_server.test import BaseTestCase
class TestStoreController(BaseTestCase):
""" StoreController integration test stubs """
"""StoreController integration test stubs"""
def test_delete_order(self):
"""
Test case for delete_order
"""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'))
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
"""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'))
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
"""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'))
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
"""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'))
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__':

View File

@@ -2,109 +2,118 @@
from __future__ import absolute_import
from swagger_server.models.user import User
from . import BaseTestCase
from six import BytesIO
from flask import json
from six import BytesIO
from swagger_server.models.user import User # noqa: E501
from swagger_server.test import BaseTestCase
class TestUserController(BaseTestCase):
""" UserController integration test stubs """
"""UserController integration test stubs"""
def test_create_user(self):
"""
Test case for create_user
"""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'))
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
"""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'))
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
"""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'))
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
"""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'))
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
"""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'))
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
"""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'))
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
"""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'))
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
"""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'))
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__':