From a1a745b4820ec46a2e707d77f6178cf9e97654f6 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Fri, 12 May 2017 18:33:00 +0800 Subject: refactor static_path to accomodate web portal move tornado_swagger/static to opnfv_testapi/static move swagger related 3rd libs to 3rd_party/swagger Change-Id: I32bba10584c99d13687b93f32577e37581db0c63 Signed-off-by: SerenaFeng --- utils/test/testapi/opnfv_testapi/cmd/server.py | 3 ++- utils/test/testapi/opnfv_testapi/common/config.py | 4 ++++ utils/test/testapi/opnfv_testapi/resources/ui_handlers.py | 7 ++----- utils/test/testapi/opnfv_testapi/router/url_mappings.py | 8 ++++++++ utils/test/testapi/opnfv_testapi/tests/unit/test_base.py | 7 ++++++- utils/test/testapi/opnfv_testapi/tornado_swagger/handlers.py | 4 ---- utils/test/testapi/opnfv_testapi/tornado_swagger/settings.py | 5 +---- utils/test/testapi/opnfv_testapi/tornado_swagger/views.py | 2 +- 8 files changed, 24 insertions(+), 16 deletions(-) (limited to 'utils/test/testapi/opnfv_testapi') diff --git a/utils/test/testapi/opnfv_testapi/cmd/server.py b/utils/test/testapi/opnfv_testapi/cmd/server.py index 8b092b89e..2696bb397 100644 --- a/utils/test/testapi/opnfv_testapi/cmd/server.py +++ b/utils/test/testapi/opnfv_testapi/cmd/server.py @@ -58,7 +58,8 @@ def get_db(): def make_app(): - swagger.docs(base_url=CONF.swagger_base_url) + swagger.docs(base_url=CONF.swagger_base_url, + static_path=CONF.static_path) return swagger.Application( url_mappings.mappings, db=get_db(), diff --git a/utils/test/testapi/opnfv_testapi/common/config.py b/utils/test/testapi/opnfv_testapi/common/config.py index 70d7bd63f..46765ffd1 100644 --- a/utils/test/testapi/opnfv_testapi/common/config.py +++ b/utils/test/testapi/opnfv_testapi/common/config.py @@ -17,6 +17,10 @@ class Config(object): def __init__(self): self.file = self.CONFIG if self.CONFIG else self._default_config() self._parse() + self.static_path = os.path.join( + os.path.dirname(os.path.normpath(__file__)), + os.pardir, + 'static') def _parse(self): if not os.path.exists(self.file): diff --git a/utils/test/testapi/opnfv_testapi/resources/ui_handlers.py b/utils/test/testapi/opnfv_testapi/resources/ui_handlers.py index ac8f816a4..4c14802c4 100644 --- a/utils/test/testapi/opnfv_testapi/resources/ui_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/ui_handlers.py @@ -1,14 +1,11 @@ from opnfv_testapi.resources.handlers import GenericApiHandler -from opnfv_testapi.tornado_swagger import settings +from opnfv_testapi.common import config class UIHandler(GenericApiHandler): - def initialize(self, **kwargs): - self.static_path = settings.docs_settings.get('static_path') - self.base_url = 'http://localhost:8000' def get_template_path(self): - return self.static_path + return config.Config().static_path def get(self): self.render('testapi-ui/index.html') diff --git a/utils/test/testapi/opnfv_testapi/router/url_mappings.py b/utils/test/testapi/opnfv_testapi/router/url_mappings.py index 94e71c62d..ebe59941a 100644 --- a/utils/test/testapi/opnfv_testapi/router/url_mappings.py +++ b/utils/test/testapi/opnfv_testapi/router/url_mappings.py @@ -6,6 +6,9 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import tornado.web + +from opnfv_testapi.common import config from opnfv_testapi.resources import handlers from opnfv_testapi.resources import pod_handlers from opnfv_testapi.resources import project_handlers @@ -49,4 +52,9 @@ mappings = [ # scenarios (r"/api/v1/scenarios", scenario_handlers.ScenariosCLHandler), (r"/api/v1/scenarios/([^/]+)", scenario_handlers.ScenarioGURHandler), + + # static path + (r'/(.*\.(css|png|gif|js|html|json))', + tornado.web.StaticFileHandler, + {'path': config.Config().static_path}), ] diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py index a6e733914..4d3445659 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py @@ -12,10 +12,13 @@ from os import path import mock from tornado import testing -from opnfv_testapi.cmd import server +from opnfv_testapi.common import config from opnfv_testapi.resources import models from opnfv_testapi.tests.unit import fake_pymongo +config.Config.CONFIG = path.join(path.dirname(__file__), + '../../../etc/config.ini') + class TestBase(testing.AsyncHTTPTestCase): headers = {'Content-Type': 'application/json; charset=UTF-8'} @@ -36,6 +39,7 @@ class TestBase(testing.AsyncHTTPTestCase): self.db_patcher.stop() def _patch_server(self): + from opnfv_testapi.cmd import server server.parse_config([ '--config-file', path.join(path.dirname(__file__), 'common/normal.ini') @@ -49,6 +53,7 @@ class TestBase(testing.AsyncHTTPTestCase): return fake_pymongo def get_app(self): + from opnfv_testapi.cmd import server return server.make_app() def create_d(self, *args): diff --git a/utils/test/testapi/opnfv_testapi/tornado_swagger/handlers.py b/utils/test/testapi/opnfv_testapi/tornado_swagger/handlers.py index c9c8a0863..e39a9f639 100644 --- a/utils/test/testapi/opnfv_testapi/tornado_swagger/handlers.py +++ b/utils/test/testapi/opnfv_testapi/tornado_swagger/handlers.py @@ -35,8 +35,4 @@ def swagger_handlers(): views.SwaggerApiHandler, settings.docs_settings, name=settings.API_DECLARATION_NAME), - ( - _path(r'(.*\.(css|png|gif|js|html|json))'), - tornado.web.StaticFileHandler, - {'path': settings.docs_settings.get('static_path')}), ] diff --git a/utils/test/testapi/opnfv_testapi/tornado_swagger/settings.py b/utils/test/testapi/opnfv_testapi/tornado_swagger/settings.py index 03e9bbdff..284226116 100644 --- a/utils/test/testapi/opnfv_testapi/tornado_swagger/settings.py +++ b/utils/test/testapi/opnfv_testapi/tornado_swagger/settings.py @@ -6,17 +6,14 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import os.path API_DOCS_NAME = 'swagger-api-docs' RESOURCE_LISTING_NAME = 'swagger-resource-listing' API_DECLARATION_NAME = 'swagger-api-declaration' -STATIC_PATH = os.path.join(os.path.dirname(os.path.normpath(__file__)), - 'static') docs_settings = { 'base_url': '', - 'static_path': STATIC_PATH, + 'static_path': '', 'swagger_prefix': '/swagger', 'api_version': 'v1.0', 'swagger_version': '1.2', diff --git a/utils/test/testapi/opnfv_testapi/tornado_swagger/views.py b/utils/test/testapi/opnfv_testapi/tornado_swagger/views.py index 42b37483b..793999700 100644 --- a/utils/test/testapi/opnfv_testapi/tornado_swagger/views.py +++ b/utils/test/testapi/opnfv_testapi/tornado_swagger/views.py @@ -33,7 +33,7 @@ class SwaggerUIHandler(tornado.web.RequestHandler): def get(self): resource_url = self.reverse_url(settings.RESOURCE_LISTING_NAME) discovery_url = self.base_url + resource_url - self.render('index.html', discovery_url=discovery_url) + self.render('swagger/index.html', discovery_url=discovery_url) class SwaggerResourcesHandler(tornado.web.RequestHandler): -- cgit 1.2.3-korg