From 3952ea27715f853efaccccb71902eceb6f212324 Mon Sep 17 00:00:00 2001 From: Diogo Dutra Date: Thu, 16 Mar 2017 13:19:51 -0300 Subject: [PATCH] did changes requested by isort and flake8 --- connexion/apis/__init__.py | 9 ++------ connexion/apis/abstract.py | 11 +++++++--- connexion/apis/flask_api.py | 13 ++++++------ connexion/apps/__init__.py | 2 ++ connexion/apps/abstract.py | 28 ++++++++++++------------- connexion/apps/flask_app.py | 34 +++++++++++++++++-------------- connexion/cli.py | 12 +++++------ connexion/decorators/parameter.py | 1 - connexion/decorators/produces.py | 1 - connexion/handlers.py | 2 -- connexion/operation.py | 3 ++- connexion/problem.py | 4 ++-- connexion/request.py | 2 +- tests/api/test_bootstrap.py | 2 +- tests/api/test_secure_api.py | 2 +- tests/conftest.py | 2 +- tests/test_api.py | 3 ++- tests/test_flask_utils.py | 2 +- tests/test_metrics.py | 8 +++++--- tests/test_operation.py | 3 ++- tests/test_utils.py | 3 ++- tests/test_validation.py | 4 ++-- tests/util.py | 2 +- 23 files changed, 80 insertions(+), 73 deletions(-) diff --git a/connexion/apis/__init__.py b/connexion/apis/__init__.py index 37f81a86a..defe04391 100644 --- a/connexion/apis/__init__.py +++ b/connexion/apis/__init__.py @@ -1,9 +1,4 @@ - -def canonical_base_url(base_path): - """ - Make given "basePath" a canonical base URL which can be prepended to paths starting with "/". - """ - return base_path.rstrip('/') - from .abstract import AbstractAPI from .flask_api import FlaskApi + +__all__ = ['AbstractAPI', 'FlaskApi'] diff --git a/connexion/apis/abstract.py b/connexion/apis/abstract.py index fc2cfe60e..b0ae1d479 100644 --- a/connexion/apis/abstract.py +++ b/connexion/apis/abstract.py @@ -1,3 +1,4 @@ +import abc import copy import logging import pathlib @@ -5,13 +6,10 @@ import jinja2 import six -import abc import yaml from swagger_spec_validator.validator20 import validate_spec -from . import canonical_base_url -from .. import utils from ..exceptions import ResolverError from ..operation import Operation from ..resolver import Resolver @@ -25,6 +23,13 @@ logger = logging.getLogger('connexion.apis') +def canonical_base_url(base_path): + """ + Make given "basePath" a canonical base URL which can be prepended to paths starting with "/". + """ + return base_path.rstrip('/') + + def compatibility_layer(spec): """Make specs compatible with older versions of Connexion.""" if not isinstance(spec, dict): diff --git a/connexion/apis/flask_api.py b/connexion/apis/flask_api.py index f28e060ec..3bfd8a89f 100644 --- a/connexion/apis/flask_api.py +++ b/connexion/apis/flask_api.py @@ -1,16 +1,15 @@ import logging -import functools import flask -import werkzeug.exceptions import six -from connexion.handlers import AuthErrorHandler +import werkzeug.exceptions +from connexion import flask_utils from connexion.apis.abstract import AbstractAPI -from connexion.response import ConnexionResponse -from connexion.request import ConnexionRequest from connexion.decorators.produces import BaseSerializer, NoContent +from connexion.handlers import AuthErrorHandler +from connexion.request import ConnexionRequest +from connexion.response import ConnexionResponse from connexion.utils import is_json_mimetype -from connexion import flask_utils logger = logging.getLogger('connexion.apis.flask_api') @@ -178,7 +177,7 @@ def _build_flask_response(cls, mimetype=None, content_type=None, 'content_type': content_type, 'headers': headers } - kwargs = {k:v for k, v in six.iteritems(kwargs) if v is not None} + kwargs = {k: v for k, v in six.iteritems(kwargs) if v is not None} flask_response = flask.current_app.response_class(**kwargs) # type: flask.Response if status_code is not None: diff --git a/connexion/apps/__init__.py b/connexion/apps/__init__.py index eea7e1293..83067db54 100644 --- a/connexion/apps/__init__.py +++ b/connexion/apps/__init__.py @@ -1,2 +1,4 @@ from .abstract import AbstractApp from .flask_app import FlaskApp + +__all__ = ['AbstractApp', 'FlaskApp'] diff --git a/connexion/apps/abstract.py b/connexion/apps/abstract.py index ed6246cf9..c2e3e47d8 100644 --- a/connexion/apps/abstract.py +++ b/connexion/apps/abstract.py @@ -1,7 +1,7 @@ +import abc import logging import pathlib import six -import abc from ..resolver import Resolver @@ -152,19 +152,19 @@ def add_api(self, specification, base_path=None, arguments=None, specification = self.specification_dir / specification api = self.api_cls(specification=specification, - base_url=base_path, arguments=arguments, - swagger_json=swagger_json, - swagger_ui=swagger_ui, - swagger_path=swagger_path, - swagger_url=swagger_url, - resolver=resolver, - resolver_error_handler=resolver_error_handler, - validate_responses=validate_responses, - strict_validation=strict_validation, - auth_all_paths=auth_all_paths, - debug=self.debug, - validator_map=self.validator_map, - pythonic_params=pythonic_params) + base_url=base_path, arguments=arguments, + swagger_json=swagger_json, + swagger_ui=swagger_ui, + swagger_path=swagger_path, + swagger_url=swagger_url, + resolver=resolver, + resolver_error_handler=resolver_error_handler, + validate_responses=validate_responses, + strict_validation=strict_validation, + auth_all_paths=auth_all_paths, + debug=self.debug, + validator_map=self.validator_map, + pythonic_params=pythonic_params) return api def _resolver_error_handler(self, *args, **kwargs): diff --git a/connexion/apps/flask_app.py b/connexion/apps/flask_app.py index 05659c582..cefc2e614 100644 --- a/connexion/apps/flask_app.py +++ b/connexion/apps/flask_app.py @@ -1,18 +1,18 @@ +import datetime import logging import pathlib -import datetime +from decimal import Decimal import flask import werkzeug.exceptions -import six +from flask import json +from ..apis.flask_api import FlaskApi from ..exceptions import ProblemException from ..problem import problem from ..resolver import Resolver -from ..apis.flask_api import FlaskApi from .abstract import AbstractApp -from flask import json -from decimal import Decimal + logger = logging.getLogger('connexion.app') @@ -23,11 +23,13 @@ def __init__(self, import_name, port=None, specification_dir='', debug=False, swagger_json=True, swagger_ui=True, swagger_path=None, swagger_url=None, host=None, validator_map=None): server = server or 'flask' - super(FlaskApp, self).__init__(import_name, port=port, specification_dir=specification_dir, - server=server, arguments=arguments, auth_all_paths=auth_all_paths, - debug=debug, swagger_json=swagger_json, swagger_ui=swagger_ui, - swagger_path=swagger_path, swagger_url=swagger_url, - host=host, validator_map=validator_map, api_cls=FlaskApi) + super(FlaskApp, self).__init__( + import_name, port=port, specification_dir=specification_dir, + server=server, arguments=arguments, auth_all_paths=auth_all_paths, + debug=debug, swagger_json=swagger_json, swagger_ui=swagger_ui, + swagger_path=swagger_path, swagger_url=swagger_url, + host=host, validator_map=validator_map, api_cls=FlaskApi + ) def create_app(self): app = flask.Flask(self.import_name) @@ -66,11 +68,13 @@ def add_api(self, specification, base_path=None, arguments=None, auth_all_paths=None, swagger_json=None, swagger_ui=None, swagger_path=None, swagger_url=None, validate_responses=False, strict_validation=False, resolver=Resolver(), resolver_error=None): - api = super(FlaskApp, self).add_api(specification, base_path=base_path, - arguments=arguments, auth_all_paths=auth_all_paths, swagger_json=swagger_json, - swagger_ui=swagger_ui, swagger_path=swagger_path, swagger_url=swagger_url, - validate_responses=validate_responses, strict_validation=strict_validation, - resolver=resolver, resolver_error=resolver_error) + api = super(FlaskApp, self).add_api( + specification, base_path=base_path, + arguments=arguments, auth_all_paths=auth_all_paths, swagger_json=swagger_json, + swagger_ui=swagger_ui, swagger_path=swagger_path, swagger_url=swagger_url, + validate_responses=validate_responses, strict_validation=strict_validation, + resolver=resolver, resolver_error=resolver_error + ) self.app.register_blueprint(api.blueprint) return api diff --git a/connexion/cli.py b/connexion/cli.py index dae8b4742..cb7323211 100644 --- a/connexion/cli.py +++ b/connexion/cli.py @@ -129,12 +129,12 @@ def run(spec_file, api_extra_args['resolver'] = resolver app = connexion.FlaskApp(__name__, - swagger_json=not hide_spec, - swagger_ui=not hide_console_ui, - swagger_path=console_ui_from or None, - swagger_url=console_ui_url or None, - auth_all_paths=auth_all_paths, - debug=debug) + swagger_json=not hide_spec, + swagger_ui=not hide_console_ui, + swagger_path=console_ui_from or None, + swagger_url=console_ui_url or None, + auth_all_paths=auth_all_paths, + debug=debug) app.add_api(spec_file_full_path, base_path=base_path, diff --git a/connexion/decorators/parameter.py b/connexion/decorators/parameter.py index 61a3a805c..efb25c6d7 100644 --- a/connexion/decorators/parameter.py +++ b/connexion/decorators/parameter.py @@ -5,7 +5,6 @@ import logging import re import six -import werkzeug.exceptions as exceptions from ..utils import all_json, boolean, is_null, is_nullable diff --git a/connexion/decorators/produces.py b/connexion/decorators/produces.py index e0d7cf9ec..7cbc6748a 100644 --- a/connexion/decorators/produces.py +++ b/connexion/decorators/produces.py @@ -1,5 +1,4 @@ # Decorators to change the return type of endpoints -import datetime import functools import logging diff --git a/connexion/handlers.py b/connexion/handlers.py index 9cf830634..87093b48f 100644 --- a/connexion/handlers.py +++ b/connexion/handlers.py @@ -44,7 +44,6 @@ def handle(self, *args, **kwargs): """ Actual handler for the execution after authentication. """ - request = self.api.get_request(**kwargs) response = problem( title=self.exception.name, detail=self.exception.description, @@ -68,7 +67,6 @@ def function(self): return self.handle def handle(self, *args, **kwargs): - request = self.api.get_request(**kwargs) response = problem( title='Not Implemented', detail=self.exception.reason, diff --git a/connexion/operation.py b/connexion/operation.py index dec886814..3f2656934 100644 --- a/connexion/operation.py +++ b/connexion/operation.py @@ -5,7 +5,8 @@ from jsonschema import ValidationError from .decorators import validation -from .decorators.decorator import BeginOfRequestLifecycleDecorator, EndOfRequestLifecycleDecorator +from .decorators.decorator import (BeginOfRequestLifecycleDecorator, + EndOfRequestLifecycleDecorator) from .decorators.metrics import UWSGIMetricsCollector from .decorators.parameter import parameter_to_arg from .decorators.produces import BaseSerializer, Produces diff --git a/connexion/problem.py b/connexion/problem.py index 8821ff7db..f5c83dd26 100644 --- a/connexion/problem.py +++ b/connexion/problem.py @@ -43,5 +43,5 @@ def problem(status, title, detail, type=None, instance=None, headers=None, ext=N # return a problem payload in JSON format. mimetype = content_type = 'application/problem+json' return ConnexionResponse(status, mimetype, content_type, - body=problem_response, - headers=headers) + body=problem_response, + headers=headers) diff --git a/connexion/request.py b/connexion/request.py index cff14258a..fb4bd5bf1 100644 --- a/connexion/request.py +++ b/connexion/request.py @@ -3,7 +3,7 @@ _ConnexionRequest = namedtuple('SwaggerRequest', [ 'url', 'method', 'path_params', 'query', 'headers', - 'form', 'body', 'json', 'files', 'context' + 'form', 'body', 'json', 'files', 'context' ]) diff --git a/tests/api/test_bootstrap.py b/tests/api/test_bootstrap.py index 1e0ae6d69..db106e302 100644 --- a/tests/api/test_bootstrap.py +++ b/tests/api/test_bootstrap.py @@ -3,8 +3,8 @@ import pytest from conftest import TEST_FOLDER, build_app_from_fixture -from connexion.apps import FlaskApp from connexion.apis import FlaskApi +from connexion.apps import FlaskApp from connexion.exceptions import InvalidSpecification diff --git a/tests/api/test_secure_api.py b/tests/api/test_secure_api.py index 37e4c20e2..1a8179595 100644 --- a/tests/api/test_secure_api.py +++ b/tests/api/test_secure_api.py @@ -1,7 +1,7 @@ import json -from connexion.apps import FlaskApp from connexion.apis import FlaskApi +from connexion.apps import FlaskApp def test_security_over_inexistent_endpoints(oauth_requests, secure_api_spec_dir): diff --git a/tests/conftest.py b/tests/conftest.py index ee8f8ae9b..2641329a0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,8 +3,8 @@ import pathlib import pytest -from connexion.apps import FlaskApp from connexion.apis import FlaskApi +from connexion.apps import FlaskApp logging.basicConfig(level=logging.DEBUG) diff --git a/tests/test_api.py b/tests/test_api.py index d8b5a54ea..622574a4a 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -7,7 +7,8 @@ from yaml import YAMLError import pytest -from connexion.apis import FlaskApi, canonical_base_url +from connexion.apis import FlaskApi +from connexion.apis.abstract import canonical_base_url from connexion.apis.flask_api import FlaskApi from connexion.exceptions import InvalidSpecification, ResolverError diff --git a/tests/test_flask_utils.py b/tests/test_flask_utils.py index 742b2b83d..7adcbfb4c 100644 --- a/tests/test_flask_utils.py +++ b/tests/test_flask_utils.py @@ -1,8 +1,8 @@ import math import connexion.apps -import connexion.utils as utils import connexion.flask_utils as flask_utils +import connexion.utils as utils import pytest from mock import MagicMock diff --git a/tests/test_metrics.py b/tests/test_metrics.py index a49e33b77..91b8d58bd 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -1,9 +1,11 @@ +import json + +import flask + import connexion -from connexion.decorators.metrics import UWSGIMetricsCollector from connexion.apis import FlaskApi +from connexion.decorators.metrics import UWSGIMetricsCollector from mock import MagicMock -import json -import flask def test_timer(monkeypatch): diff --git a/tests/test_operation.py b/tests/test_operation.py index 2af152869..04d11ffb8 100644 --- a/tests/test_operation.py +++ b/tests/test_operation.py @@ -3,8 +3,9 @@ import mock import pytest -from connexion.decorators.security import security_passthrough, verify_oauth + from connexion.apis.flask_api import Jsonifier +from connexion.decorators.security import security_passthrough, verify_oauth from connexion.exceptions import InvalidSpecification from connexion.operation import Operation from connexion.resolver import Resolver diff --git a/tests/test_utils.py b/tests/test_utils.py index 38a514156..9646c24c9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,9 +1,10 @@ import math import connexion.apps -import connexion.utils as utils import connexion.flask_utils as flask_utils +import connexion.utils as utils import pytest + from mock import MagicMock diff --git a/tests/test_validation.py b/tests/test_validation.py index 0897e031a..8e97e3454 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -1,11 +1,11 @@ import json +import flask -from connexion.decorators.validation import ParameterValidator from connexion.apis.flask_api import FlaskApi +from connexion.decorators.validation import ParameterValidator # we are using "mock" module here for Py 2.7 support from mock import MagicMock -import flask def test_parameter_validator(monkeypatch): diff --git a/tests/util.py b/tests/util.py index 24f7cd571..0bc9393b5 100644 --- a/tests/util.py +++ b/tests/util.py @@ -3,8 +3,8 @@ import pathlib import pytest -from connexion.apps import FlaskApp from connexion.apis import FlaskApi +from connexion.apps import FlaskApp logging.basicConfig(level=logging.DEBUG)