From 71a3c218ef53459fca53b0e1cc31d5f726e5b436 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Wed, 10 May 2017 11:39:42 +0800 Subject: correct the import impl of TestAPI Change-Id: Ia721ff61e02b1819c32d228f5f8910364c139c8a Signed-off-by: SerenaFeng --- testapi/opnfv_testapi/common/check.py | 6 ++-- testapi/opnfv_testapi/resources/handlers.py | 2 +- testapi/opnfv_testapi/resources/models.py | 3 +- testapi/opnfv_testapi/resources/pod_handlers.py | 2 +- testapi/opnfv_testapi/resources/pod_models.py | 2 +- .../opnfv_testapi/resources/project_handlers.py | 4 +-- testapi/opnfv_testapi/resources/project_models.py | 2 +- testapi/opnfv_testapi/resources/result_models.py | 2 +- testapi/opnfv_testapi/resources/scenario_models.py | 2 +- testapi/opnfv_testapi/resources/testcase_models.py | 2 +- testapi/opnfv_testapi/tornado_swagger/handlers.py | 37 +++++++++++----------- testapi/opnfv_testapi/tornado_swagger/swagger.py | 23 +++++++------- testapi/opnfv_testapi/tornado_swagger/views.py | 21 ++++++------ 13 files changed, 55 insertions(+), 53 deletions(-) diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py index be4b1df..4d9902c 100644 --- a/testapi/opnfv_testapi/common/check.py +++ b/testapi/opnfv_testapi/common/check.py @@ -8,9 +8,11 @@ ############################################################################## import functools -from tornado import web, gen +from tornado import gen +from tornado import web -from opnfv_testapi.common import raises, message +from opnfv_testapi.common import message +from opnfv_testapi.common import raises def authenticate(method): diff --git a/testapi/opnfv_testapi/resources/handlers.py b/testapi/opnfv_testapi/resources/handlers.py index 955fbbe..dbf94eb 100644 --- a/testapi/opnfv_testapi/resources/handlers.py +++ b/testapi/opnfv_testapi/resources/handlers.py @@ -26,10 +26,10 @@ import json from tornado import gen from tornado import web -import models from opnfv_testapi.common import check from opnfv_testapi.common import message from opnfv_testapi.common import raises +from opnfv_testapi.resources import models from opnfv_testapi.tornado_swagger import swagger DEFAULT_REPRESENTATION = "application/json" diff --git a/testapi/opnfv_testapi/resources/models.py b/testapi/opnfv_testapi/resources/models.py index 0ea482f..e8fc532 100644 --- a/testapi/opnfv_testapi/resources/models.py +++ b/testapi/opnfv_testapi/resources/models.py @@ -14,9 +14,8 @@ # feng.xiaowei@zte.com.cn mv TestResut to result_models.py 5-23-2016 # feng.xiaowei@zte.com.cn add ModelBase 12-20-2016 ############################################################################## -import copy import ast - +import copy from opnfv_testapi.tornado_swagger import swagger diff --git a/testapi/opnfv_testapi/resources/pod_handlers.py b/testapi/opnfv_testapi/resources/pod_handlers.py index e21841d..5029887 100644 --- a/testapi/opnfv_testapi/resources/pod_handlers.py +++ b/testapi/opnfv_testapi/resources/pod_handlers.py @@ -7,8 +7,8 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import handlers +from opnfv_testapi.resources import pod_models from opnfv_testapi.tornado_swagger import swagger -import pod_models class GenericPodHandler(handlers.GenericApiHandler): diff --git a/testapi/opnfv_testapi/resources/pod_models.py b/testapi/opnfv_testapi/resources/pod_models.py index 26a9e67..2c3ea97 100644 --- a/testapi/opnfv_testapi/resources/pod_models.py +++ b/testapi/opnfv_testapi/resources/pod_models.py @@ -6,7 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import models +from opnfv_testapi.resources import models from opnfv_testapi.tornado_swagger import swagger diff --git a/testapi/opnfv_testapi/resources/project_handlers.py b/testapi/opnfv_testapi/resources/project_handlers.py index d79cd3b..be29507 100644 --- a/testapi/opnfv_testapi/resources/project_handlers.py +++ b/testapi/opnfv_testapi/resources/project_handlers.py @@ -7,9 +7,9 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import handlers +from opnfv_testapi.resources import handlers +from opnfv_testapi.resources import project_models from opnfv_testapi.tornado_swagger import swagger -import project_models class GenericProjectHandler(handlers.GenericApiHandler): diff --git a/testapi/opnfv_testapi/resources/project_models.py b/testapi/opnfv_testapi/resources/project_models.py index f7323c1..3243882 100644 --- a/testapi/opnfv_testapi/resources/project_models.py +++ b/testapi/opnfv_testapi/resources/project_models.py @@ -6,7 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import models +from opnfv_testapi.resources import models from opnfv_testapi.tornado_swagger import swagger diff --git a/testapi/opnfv_testapi/resources/result_models.py b/testapi/opnfv_testapi/resources/result_models.py index 50445fc..62a6dac 100644 --- a/testapi/opnfv_testapi/resources/result_models.py +++ b/testapi/opnfv_testapi/resources/result_models.py @@ -6,7 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import models +from opnfv_testapi.resources import models from opnfv_testapi.tornado_swagger import swagger diff --git a/testapi/opnfv_testapi/resources/scenario_models.py b/testapi/opnfv_testapi/resources/scenario_models.py index b84accf..467cff2 100644 --- a/testapi/opnfv_testapi/resources/scenario_models.py +++ b/testapi/opnfv_testapi/resources/scenario_models.py @@ -1,4 +1,4 @@ -import models +from opnfv_testapi.resources import models from opnfv_testapi.tornado_swagger import swagger diff --git a/testapi/opnfv_testapi/resources/testcase_models.py b/testapi/opnfv_testapi/resources/testcase_models.py index 8cc3c6c..86aed25 100644 --- a/testapi/opnfv_testapi/resources/testcase_models.py +++ b/testapi/opnfv_testapi/resources/testcase_models.py @@ -6,7 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import models +from opnfv_testapi.resources import models from opnfv_testapi.tornado_swagger import swagger diff --git a/testapi/opnfv_testapi/tornado_swagger/handlers.py b/testapi/opnfv_testapi/tornado_swagger/handlers.py index af0b515..72add2d 100644 --- a/testapi/opnfv_testapi/tornado_swagger/handlers.py +++ b/testapi/opnfv_testapi/tornado_swagger/handlers.py @@ -6,38 +6,37 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from tornado.web import URLSpec, StaticFileHandler +import tornado.web -from settings import default_settings, \ - SWAGGER_API_DOCS, SWAGGER_RESOURCE_LISTING, SWAGGER_API_DECLARATION -from views import SwaggerUIHandler, SwaggerResourcesHandler, SwaggerApiHandler +from opnfv_testapi.tornado_swagger import settings +from opnfv_testapi.tornado_swagger import views def swagger_handlers(): - prefix = default_settings.get('swagger_prefix', '/swagger') + prefix = settings.default_settings.get('swagger_prefix', '/swagger') if prefix[-1] != '/': prefix += '/' def _path(suffix): return prefix + suffix return [ - URLSpec( + tornado.web.URLSpec( _path(r'spec.html$'), - SwaggerUIHandler, - default_settings, - name=SWAGGER_API_DOCS), - URLSpec( + views.SwaggerUIHandler, + settings.default_settings, + name=settings.SWAGGER_API_DOCS), + tornado.web.URLSpec( _path(r'resources.json$'), - SwaggerResourcesHandler, - default_settings, - name=SWAGGER_RESOURCE_LISTING), - URLSpec( + views.SwaggerResourcesHandler, + settings.default_settings, + name=settings.SWAGGER_RESOURCE_LISTING), + tornado.web.URLSpec( _path(r'APIs$'), - SwaggerApiHandler, - default_settings, - name=SWAGGER_API_DECLARATION), + views.SwaggerApiHandler, + settings.default_settings, + name=settings.SWAGGER_API_DECLARATION), ( _path(r'(.*\.(css|png|gif|js))'), - StaticFileHandler, - {'path': default_settings.get('static_path')}), + tornado.web.StaticFileHandler, + {'path': settings.default_settings.get('static_path')}), ] diff --git a/testapi/opnfv_testapi/tornado_swagger/swagger.py b/testapi/opnfv_testapi/tornado_swagger/swagger.py index 3d21ede..a0f6ae7 100644 --- a/testapi/opnfv_testapi/tornado_swagger/swagger.py +++ b/testapi/opnfv_testapi/tornado_swagger/swagger.py @@ -6,15 +6,15 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import inspect -from functools import wraps from HTMLParser import HTMLParser +from functools import wraps +import inspect import epydoc.markup import tornado.web -from settings import default_settings, models -from handlers import swagger_handlers +from opnfv_testapi.tornado_swagger import handlers +from opnfv_testapi.tornado_swagger import settings class EpytextParser(HTMLParser): @@ -204,7 +204,7 @@ class model(DocParser): if '__init__' in dir(cls): self._parse_args(cls.__init__) self.parse_docstring(inspect.getdoc(cls)) - models.append(self) + settings.models.append(self) def _parse_args(self, func): argspec = inspect.getargspec(func) @@ -276,15 +276,16 @@ class operation(DocParser): def docs(**opts): - default_settings.update(opts) + settings.default_settings.update(opts) class Application(tornado.web.Application): - def __init__(self, handlers=None, + def __init__(self, app_handlers=None, default_host="", transforms=None, **settings): - super(Application, self).__init__(swagger_handlers() + handlers, - default_host, - transforms, - **settings) + super(Application, self).__init__( + handlers.swagger_handlers() + app_handlers, + default_host, + transforms, + **settings) diff --git a/testapi/opnfv_testapi/tornado_swagger/views.py b/testapi/opnfv_testapi/tornado_swagger/views.py index 2168c5e..591cb44 100644 --- a/testapi/opnfv_testapi/tornado_swagger/views.py +++ b/testapi/opnfv_testapi/tornado_swagger/views.py @@ -8,13 +8,12 @@ ############################################################################## import inspect import json +import os.path import tornado.template import tornado.web -from settings import SWAGGER_VERSION -from settings import SWAGGER_RESOURCE_LISTING, SWAGGER_API_DECLARATION -from settings import models, basePath +from opnfv_testapi.tornado_swagger import settings def json_dumps(obj, pretty=False): @@ -30,7 +29,9 @@ class SwaggerUIHandler(tornado.web.RequestHandler): return self.static_path def get(self): - discovery_url = basePath() + self.reverse_url(SWAGGER_RESOURCE_LISTING) + discovery_url = os.path.join( + settings.basePath(), + self.reverse_url(settings.SWAGGER_RESOURCE_LISTING)) self.render('index.html', discovery_url=discovery_url) @@ -43,12 +44,12 @@ class SwaggerResourcesHandler(tornado.web.RequestHandler): self.set_header('content-type', 'application/json') resources = { 'apiVersion': self.api_version, - 'swaggerVersion': SWAGGER_VERSION, - 'basePath': basePath(), + 'swaggerVersion': settings.SWAGGER_VERSION, + 'basePath': settings.basePath(), 'produces': ["application/json"], 'description': 'Test Api Spec', 'apis': [{ - 'path': self.reverse_url(SWAGGER_API_DECLARATION), + 'path': self.reverse_url(settings.SWAGGER_API_DECLARATION), 'description': 'Test Api Spec' }] } @@ -69,11 +70,11 @@ class SwaggerApiHandler(tornado.web.RequestHandler): specs = { 'apiVersion': self.api_version, - 'swaggerVersion': SWAGGER_VERSION, - 'basePath': basePath(), + 'swaggerVersion': settings.SWAGGER_VERSION, + 'basePath': settings.basePath(), 'apis': [self.__get_api_spec__(path, spec, operations) for path, spec, operations in apis], - 'models': self.__get_models_spec(models) + 'models': self.__get_models_spec(settings.models) } self.finish(json_dumps(specs, self.get_arguments('pretty'))) -- cgit 1.2.3-korg