summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-05-12 18:33:00 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-05-17 16:43:12 +0800
commit74a3b45c290d1b6e289ac1c3b9425e804e2f0ab7 (patch)
tree905343c0fbd8114b1619641dcf359e2cd3fc1928 /testapi/opnfv_testapi
parentde3ac5fcdb1259df876df53d93b4166011fae79b (diff)
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 <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/opnfv_testapi')
-rw-r--r--testapi/opnfv_testapi/cmd/server.py3
-rw-r--r--testapi/opnfv_testapi/common/config.py4
-rw-r--r--testapi/opnfv_testapi/resources/ui_handlers.py7
-rw-r--r--testapi/opnfv_testapi/router/url_mappings.py8
-rw-r--r--testapi/opnfv_testapi/tests/unit/test_base.py7
-rw-r--r--testapi/opnfv_testapi/tornado_swagger/handlers.py4
-rw-r--r--testapi/opnfv_testapi/tornado_swagger/settings.py5
-rw-r--r--testapi/opnfv_testapi/tornado_swagger/views.py2
8 files changed, 24 insertions, 16 deletions
diff --git a/testapi/opnfv_testapi/cmd/server.py b/testapi/opnfv_testapi/cmd/server.py
index 8b092b8..2696bb3 100644
--- a/testapi/opnfv_testapi/cmd/server.py
+++ b/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/testapi/opnfv_testapi/common/config.py b/testapi/opnfv_testapi/common/config.py
index 70d7bd6..46765ff 100644
--- a/testapi/opnfv_testapi/common/config.py
+++ b/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/testapi/opnfv_testapi/resources/ui_handlers.py b/testapi/opnfv_testapi/resources/ui_handlers.py
index ac8f816..4c14802 100644
--- a/testapi/opnfv_testapi/resources/ui_handlers.py
+++ b/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/testapi/opnfv_testapi/router/url_mappings.py b/testapi/opnfv_testapi/router/url_mappings.py
index 94e71c6..ebe5994 100644
--- a/testapi/opnfv_testapi/router/url_mappings.py
+++ b/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/testapi/opnfv_testapi/tests/unit/test_base.py b/testapi/opnfv_testapi/tests/unit/test_base.py
index a6e7339..4d34456 100644
--- a/testapi/opnfv_testapi/tests/unit/test_base.py
+++ b/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/testapi/opnfv_testapi/tornado_swagger/handlers.py b/testapi/opnfv_testapi/tornado_swagger/handlers.py
index c9c8a08..e39a9f6 100644
--- a/testapi/opnfv_testapi/tornado_swagger/handlers.py
+++ b/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/testapi/opnfv_testapi/tornado_swagger/settings.py b/testapi/opnfv_testapi/tornado_swagger/settings.py
index 03e9bbd..2842261 100644
--- a/testapi/opnfv_testapi/tornado_swagger/settings.py
+++ b/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/testapi/opnfv_testapi/tornado_swagger/views.py b/testapi/opnfv_testapi/tornado_swagger/views.py
index 42b3748..7939997 100644
--- a/testapi/opnfv_testapi/tornado_swagger/views.py
+++ b/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):