diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-05-10 11:39:42 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-05-10 11:39:42 +0800 |
commit | 71a3c218ef53459fca53b0e1cc31d5f726e5b436 (patch) | |
tree | fabe167648e5ddc1c910615bbfc41f380dd1e8aa /testapi/opnfv_testapi/tornado_swagger | |
parent | d12a70a7eebf025b90f46eaa8a5fee38ecadc518 (diff) |
correct the import impl of TestAPI
Change-Id: Ia721ff61e02b1819c32d228f5f8910364c139c8a
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/opnfv_testapi/tornado_swagger')
-rw-r--r-- | testapi/opnfv_testapi/tornado_swagger/handlers.py | 37 | ||||
-rw-r--r-- | testapi/opnfv_testapi/tornado_swagger/swagger.py | 23 | ||||
-rw-r--r-- | testapi/opnfv_testapi/tornado_swagger/views.py | 21 |
3 files changed, 41 insertions, 40 deletions
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'))) |