summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/testapi/opnfv_testapi/common/check.py6
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/handlers.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/models.py3
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/pod_handlers.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/pod_models.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/project_handlers.py4
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/project_models.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/result_models.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_models.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/testcase_models.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/tornado_swagger/handlers.py41
-rw-r--r--utils/test/testapi/opnfv_testapi/tornado_swagger/settings.py14
-rw-r--r--utils/test/testapi/opnfv_testapi/tornado_swagger/swagger.py23
-rw-r--r--utils/test/testapi/opnfv_testapi/tornado_swagger/views.py52
14 files changed, 81 insertions, 76 deletions
diff --git a/utils/test/testapi/opnfv_testapi/common/check.py b/utils/test/testapi/opnfv_testapi/common/check.py
index be4b1df12..4d9902cd0 100644
--- a/utils/test/testapi/opnfv_testapi/common/check.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py
index 955fbbef7..dbf94eb75 100644
--- a/utils/test/testapi/opnfv_testapi/resources/handlers.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/resources/models.py b/utils/test/testapi/opnfv_testapi/resources/models.py
index 0ea482fd2..e8fc532b7 100644
--- a/utils/test/testapi/opnfv_testapi/resources/models.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/resources/pod_handlers.py b/utils/test/testapi/opnfv_testapi/resources/pod_handlers.py
index e21841d33..502988752 100644
--- a/utils/test/testapi/opnfv_testapi/resources/pod_handlers.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/resources/pod_models.py b/utils/test/testapi/opnfv_testapi/resources/pod_models.py
index 26a9e6788..2c3ea978b 100644
--- a/utils/test/testapi/opnfv_testapi/resources/pod_models.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/resources/project_handlers.py b/utils/test/testapi/opnfv_testapi/resources/project_handlers.py
index d79cd3b61..be2950705 100644
--- a/utils/test/testapi/opnfv_testapi/resources/project_handlers.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/resources/project_models.py b/utils/test/testapi/opnfv_testapi/resources/project_models.py
index f7323c1c4..3243882bd 100644
--- a/utils/test/testapi/opnfv_testapi/resources/project_models.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/resources/result_models.py b/utils/test/testapi/opnfv_testapi/resources/result_models.py
index 50445fc22..62a6dacff 100644
--- a/utils/test/testapi/opnfv_testapi/resources/result_models.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
index b84accf4d..467cff241 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/resources/testcase_models.py b/utils/test/testapi/opnfv_testapi/resources/testcase_models.py
index 9b8f4b5ff..2379dfc4c 100644
--- a/utils/test/testapi/opnfv_testapi/resources/testcase_models.py
+++ b/utils/test/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/utils/test/testapi/opnfv_testapi/tornado_swagger/handlers.py b/utils/test/testapi/opnfv_testapi/tornado_swagger/handlers.py
index 2154b4697..fff6d2137 100644
--- a/utils/test/testapi/opnfv_testapi/tornado_swagger/handlers.py
+++ b/utils/test/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_API_LIST, SWAGGER_API_SPEC
-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.docs_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(
- _path(r'spec.json$'),
- SwaggerResourcesHandler,
- default_settings,
- name=SWAGGER_API_LIST),
- URLSpec(
- _path(r'spec$'),
- SwaggerApiHandler,
- default_settings,
- name=SWAGGER_API_SPEC),
+ views.SwaggerUIHandler,
+ settings.docs_settings,
+ name=settings.API_DOCS_NAME),
+ tornado.web.URLSpec(
+ _path(r'resources.json$'),
+ views.SwaggerResourcesHandler,
+ settings.docs_settings,
+ name=settings.RESOURCE_LISTING_NAME),
+ tornado.web.URLSpec(
+ _path(r'APIs$'),
+ views.SwaggerApiHandler,
+ settings.docs_settings,
+ name=settings.API_DECLARATION_NAME),
(
_path(r'(.*\.(css|png|gif|js))'),
- StaticFileHandler,
- {'path': default_settings.get('static_path')}),
+ 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 88d0d0f88..03e9bbdff 100644
--- a/utils/test/testapi/opnfv_testapi/tornado_swagger/settings.py
+++ b/utils/test/testapi/opnfv_testapi/tornado_swagger/settings.py
@@ -8,25 +8,21 @@
##############################################################################
import os.path
-SWAGGER_VERSION = '1.2'
-SWAGGER_API_DOCS = 'swagger-api-docs'
-SWAGGER_API_LIST = 'swagger-api-list'
-SWAGGER_API_SPEC = 'swagger-api-spec'
+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')
-default_settings = {
+docs_settings = {
'base_url': '',
'static_path': STATIC_PATH,
'swagger_prefix': '/swagger',
'api_version': 'v1.0',
+ 'swagger_version': '1.2',
'api_key': '',
'enabled_methods': ['get', 'post', 'put', 'patch', 'delete'],
'exclude_namespaces': [],
}
models = []
-
-
-def basePath():
- return default_settings.get('base_url')
diff --git a/utils/test/testapi/opnfv_testapi/tornado_swagger/swagger.py b/utils/test/testapi/opnfv_testapi/tornado_swagger/swagger.py
index 3d21edefb..83f389a6b 100644
--- a/utils/test/testapi/opnfv_testapi/tornado_swagger/swagger.py
+++ b/utils/test/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.docs_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/utils/test/testapi/opnfv_testapi/tornado_swagger/views.py b/utils/test/testapi/opnfv_testapi/tornado_swagger/views.py
index 25083195b..ca4f01cfc 100644
--- a/utils/test/testapi/opnfv_testapi/tornado_swagger/views.py
+++ b/utils/test/testapi/opnfv_testapi/tornado_swagger/views.py
@@ -8,47 +8,52 @@
##############################################################################
import inspect
import json
+import os.path
import tornado.template
import tornado.web
-from settings import SWAGGER_VERSION, SWAGGER_API_LIST, SWAGGER_API_SPEC
-from settings import models, basePath
+from opnfv_testapi.tornado_swagger import settings
def json_dumps(obj, pretty=False):
- return json.dumps(obj, sort_keys=True, indent=4, separators=(',', ': ')) \
- if pretty else json.dumps(obj)
+ return json.dumps(obj,
+ sort_keys=True,
+ indent=4,
+ separators=(',', ': ')) if pretty else json.dumps(obj)
class SwaggerUIHandler(tornado.web.RequestHandler):
- def initialize(self, static_path, **kwds):
- self.static_path = static_path
+ def initialize(self, **kwargs):
+ self.static_path = kwargs.get('static_path')
+ self.base_url = kwargs.get('base_url')
def get_template_path(self):
return self.static_path
def get(self):
- discovery_url = basePath() + self.reverse_url(SWAGGER_API_LIST)
+ discovery_url = os.path.join(
+ self.base_url,
+ self.reverse_url(settings.RESOURCE_LISTING_NAME))
self.render('index.html', discovery_url=discovery_url)
class SwaggerResourcesHandler(tornado.web.RequestHandler):
- def initialize(self, api_version, exclude_namespaces, **kwds):
- self.api_version = api_version
- self.exclude_namespaces = exclude_namespaces
+ def initialize(self, **kwargs):
+ self.api_version = kwargs.get('api_version')
+ self.swagger_version = kwargs.get('swagger_version')
+ self.base_url = kwargs.get('base_url')
+ self.exclude_namespaces = kwargs.get('exclude_namespaces')
def get(self):
self.set_header('content-type', 'application/json')
resources = {
'apiVersion': self.api_version,
- 'swaggerVersion': SWAGGER_VERSION,
- 'basePath': basePath(),
- 'produces': ["application/json"],
- 'description': 'Test Api Spec',
+ 'swaggerVersion': self.swagger_version,
+ 'basePath': self.base_url,
'apis': [{
- 'path': self.reverse_url(SWAGGER_API_SPEC),
- 'description': 'Test Api Spec'
+ 'path': self.reverse_url(settings.API_DECLARATION_NAME),
+ 'description': 'Restful APIs Specification'
}]
}
@@ -56,9 +61,10 @@ class SwaggerResourcesHandler(tornado.web.RequestHandler):
class SwaggerApiHandler(tornado.web.RequestHandler):
- def initialize(self, api_version, base_url, **kwds):
- self.api_version = api_version
- self.base_url = base_url
+ def initialize(self, **kwargs):
+ self.api_version = kwargs.get('api_version')
+ self.swagger_version = kwargs.get('swagger_version')
+ self.base_url = kwargs.get('base_url')
def get(self):
self.set_header('content-type', 'application/json')
@@ -68,11 +74,13 @@ class SwaggerApiHandler(tornado.web.RequestHandler):
specs = {
'apiVersion': self.api_version,
- 'swaggerVersion': SWAGGER_VERSION,
- 'basePath': basePath(),
+ 'swaggerVersion': self.swagger_version,
+ 'basePath': self.base_url,
+ 'resourcePath': '/',
+ 'produces': ["application/json"],
'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')))