import motor
from opnfv_testapi.common.config import APIConfig
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
from opnfv_testapi.router import url_mappings
# optionally get config file from command line
check_dashboard_ready_case, get_dashboard_result
from opnfv_testapi.resources.result_handlers import GenericResultHandler
from opnfv_testapi.resources.result_models import TestResult
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
class GenericDashboardHandler(GenericResultHandler):
from models import CreateResponse
from opnfv_testapi.common.constants import DEFAULT_REPRESENTATION, \
HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_FORBIDDEN
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
class GenericApiHandler(RequestHandler):
# feng.xiaowei@zte.com.cn mv TestCase to testcase_models.py 5-20-2016\r
# feng.xiaowei@zte.com.cn mv TestResut to result_models.py 5-23-2016\r
##############################################################################\r
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger\r
+from opnfv_testapi.tornado_swagger import swagger\r
\r
\r
class CreateResponse(object):\r
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
from handlers import GenericApiHandler
from pod_models import Pod
from opnfv_testapi.common.constants import HTTP_FORBIDDEN
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
__author__ = '__serena__'
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
from handlers import GenericApiHandler
from opnfv_testapi.common.constants import HTTP_FORBIDDEN
from project_models import Project
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
__author__ = '__serena__'
from opnfv_testapi.common.constants import HTTP_BAD_REQUEST, HTTP_NOT_FOUND
from opnfv_testapi.resources.handlers import GenericApiHandler
from opnfv_testapi.resources.result_models import TestResult
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
class GenericResultHandler(GenericApiHandler):
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
@swagger.model()
from opnfv_testapi.common.constants import HTTP_FORBIDDEN
from opnfv_testapi.resources.handlers import GenericApiHandler
from opnfv_testapi.resources.testcase_models import Testcase
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
class GenericTestcaseHandler(GenericApiHandler):
-from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
+from opnfv_testapi.tornado_swagger import swagger
__author__ = '__serena__'
+++ /dev/null
-The MIT License (MIT)
-
-Copyright (c) 2013 Ran Tavory
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+++ /dev/null
-Please see documentation here: https://github.com/SerenaFeng/tornado-swagger
+++ /dev/null
-# tornado-swagger
-
-## What is tornado-swagger?
-tornado is a wrapper for tornado which enables swagger-ui support.
-
-In essense, you just need to wrap the Api instance and add a few python decorators to get full swagger support.
-
-## How to:
-Install:
-
-```
-python setup.py install
-```
-(This installs tornado and epydoc as well)
-
-
-And in your program, where you'd usually just use tornado, add just a little bit of sauce and get a swagger spec out.
-
-
-```python
-from tornado.web import RequestHandler, HTTPError
-from tornado_swagger import swagger
-
-swagger.docs()
-
-# You may decorate your operation with @swagger.operation and use docs to inform information
-class ItemNoParamHandler(GenericApiHandler):
- @swagger.operation(nickname='create')
- def post(self):
- """
- @param body: create test results for a item.
- @type body: L{Item}
- @return 200: item is created.
- @raise 400: invalid input
- """
-
-# Operations not decorated with @swagger.operation do not get added to the swagger docs
-
-class ItemNoParamHandler(GenericApiHandler):
- def options(self):
- """
- I'm not visible in the swagger docs
- """
- pass
-
-
-# Then you use swagger.Application instead of tornado.web.Application
-# and do other operations as usual
-
-def make_app():
- return swagger.Application([
- (r"/items", ItemNoParamHandler),
- (r"/items/([^/]+)", ItemHandler),
- (r"/items/([^/]+)/cases/([^/]+)", ItemOptionParamHandler),
- ])
-
-# You define models like this:
-@swagger.model
-class Item:
- """
- @descriptin:
- This is an example of a model class that has parameters in its constructor
- and the fields in the swagger spec are derived from the parameters to __init__.
- @notes:
- In this case we would have property1, property2 as required parameters and property3 as optional parameter.
- @property property3: Item decription
- @ptype property3: L{PropertySubclass}
- """
- def __init__(self, property1, property2=None):
- self.property1 = property1
- self.property2 = property2
-
-# Swagger json:
- "models": {
- "Item": {
- "description": "A description...",
- "id": "Item",
- "required": [
- "property1",
- ],
- "properties": [
- "property1": {
- "type": "string"
- },
- "property2": {
- "type": "string"
- "default": null
- }
- ]
- }
- }
-
-# If you declare an __init__ method with meaningful arguments
-# then those args could be used to deduce the swagger model fields.
-# just as shown above
-
-# if you declare an @property in docs, this property property2 will also be used to deduce the swagger model fields
-class Item:
- """
- @property property3: Item description
- """
- def __init__(self, property1, property2):
- self.property1 = property1
- self.property2 = property2
-
-# Swagger json:
- "models": {
- "Item": {
- "description": "A description...",
- "id": "Item",
- "required": [
- "property1",
- ],
- "properties": [
- "property1": {
- "type": "string"
- },
- "property2": {
- "type": "string"
- }
- "property3": {
- "type": "string"
- }
- ]
- }
- }
-
-# if you declare an argument with @ptype, the type of this argument will be specified rather than the default 'string'
-class Item:
- """
- @ptype property3: L{PropertySubclass}
- """
- def __init__(self, property1, property2, property3=None):
- self.property1 = property1
- self.property2 = property2
- self.property3 = property3
-
-# Swagger json:
- "models": {
- "Item": {
- "description": "A description...",
- "id": "Item",
- "required": [
- "property1",
- ],
- "properties": [
- "property1": {
- "type": "string"
- },
- "property2": {
- "type": "string"
- },
- "property3": {
- "type": "PropertySubclass"
- "default": null
- }
- ]
- }
- }
-
-# if you want to declare an list property, you can do it like this:
-class Item:
- """
- @ptype property3: L{PropertySubclass}
- @ptype property4: C{list} of L{PropertySubclass}
- """
- def __init__(self, property1, property2, property3, property4=None):
- self.property1 = property1
- self.property2 = property2
- self.property3 = property3
- self.property4 = property4
-
-# Swagger json:
- "models": {
- "Item": {
- "description": "A description...",
- "id": "Item",
- "required": [
- "property1",
- ],
- "properties": [
- "property1": {
- "type": "string"
- },
- "property2": {
- "type": "string"
- },
- "property3": {
- "type": "PropertySubclass"
- "default": null
- },
- "property4": {
- "default": null,
- "items": {
- "type": "PropertySubclass"},
- "type": "array"
- }
- }
- ]
- }
- }
-
-# if it is a query:
-class ItemQueryHandler(GenericApiHandler):
- @swagger.operation(nickname='query')
- def get(self):
- """
- @param property1:
- @type property1: L{string}
- @in property1: query
- @required property1: False
-
- @param property2:
- @type property2: L{string}
- @in property2: query
- @required property2: True
- @rtype: L{Item}
-
- @notes: GET /item?property1=1&property2=1
- """
-
-# Swagger json:
- "apis": [
- {
- "operations": [
- {
- "parameters": [
- {
- "name": "property1",
- "dataType": "string",
- "paramType": "query",
- "description": ""
- },
- {
- "name": "property2",
- "dataType": "string",
- "paramType": "query",
- "required": true,
- "description": ""
- }
- ],
- "responseClass": "Item",
- "notes": null,
- "responseMessages": [],
- "summary": null,
- "httpMethod": "GET",
- "nickname": "query"
- }
- ],
- "path": "/item",
- "description": null
- },
- ....
- ]
-```
-
-# Running and testing
-
-Now run your tornado app
-
-```
-python basic.py
-```
-
-And visit:
-
-```
-curl http://localhost:711/swagger/spec
-```
-
-access to web
-```
-http://localhost:711/swagger/spec.html
-```
-
-# Passing more metadata to swagger
-customized arguments used in creating the 'swagger.docs' object will be supported later
+++ /dev/null
-import json
-
-import tornado.ioloop
-from tornado.web import RequestHandler, HTTPError
-from tornado_swagger_ui.tornado_swagger import swagger
-
-DEFAULT_REPRESENTATION = "application/json"
-HTTP_BAD_REQUEST = 400
-HTTP_FORBIDDEN = 403
-HTTP_NOT_FOUND = 404
-
-swagger.docs()
-
-
-@swagger.model()
-class PropertySubclass:
- def __init__(self, sub_property=None):
- self.sub_property = sub_property
-
-
-@swagger.model()
-class Item:
- """
- @description:
- This is an example of a model class that has parameters in its
- constructor and the fields in the swagger spec are derived from
- the parameters to __init__.
- @notes:
- In this case we would have property1, name as required parameters
- and property3 as optional parameter.
- @property property3: Item description
- @ptype property3: L{PropertySubclass}
- @ptype property4: C{list} of L{PropertySubclass}
- """
- def __init__(self,
- property1,
- property2=None,
- property3=None,
- property4=None):
- self.property1 = property1
- self.property2 = property2
- self.property3 = property3
- self.property4 = property4
-
- def format_http(self):
- return {
- "property1": self.property1,
- "property2": self.property2,
- "property3": self.property3,
- "property4": self.property4,
- }
-
- @staticmethod
- def item_from_dict(item_dict):
-
- if item_dict is None:
- return None
-
- t = Item(None)
- t.property1 = item_dict.get('property1')
- t.property2 = item_dict.get('property2')
- t.property3 = item_dict.get('property3')
- t.property4 = item_dict.get('property4')
-
- return t
-
- @classmethod
- def test_classmethod(cls):
- pass
-
-
-items = {}
-
-
-class GenericApiHandler(RequestHandler):
- """
- The purpose of this class is to take benefit of inheritance and prepare
- a set of common functions for
- the handlers
- """
-
- def initialize(self):
- """ Prepares the database for the entire class """
- pass
-
- def prepare(self):
- if self.request.method != "GET" and self.request.method != "DELETE":
- self.json_args = None
- content_type = self.request.headers.get("Content-Type")
- if content_type is not None:
- if content_type.startswith(DEFAULT_REPRESENTATION):
- try:
- self.json_args = json.loads(self.request.body)
- except (ValueError, KeyError, TypeError) as error:
- raise HTTPError(HTTP_BAD_REQUEST,
- "Bad Json format [{}]".
- format(error))
-
- def finish_request(self, json_object):
- self.write(json.dumps(json_object))
- self.set_header("Content-Type", DEFAULT_REPRESENTATION)
- self.finish()
-
-
-class ItemNoParamHandler(GenericApiHandler):
- @swagger.operation(nickname='create')
- def post(self):
- """
- @param body: create a item.
- @type body: L{Item}
- @in body: body
- @return 200: item is created.
- @raise 400: invalid input
- """
- property1 = self.json_args.get('property1')
- item = Item.item_from_dict(self.json_args)
- items[property1] = item
- Item.test_classmethod()
- self.finish_request(item.format_http())
-
- @swagger.operation(nickname='list')
- def get(self):
- """
- @rtype: L{Item}
- """
- res = []
- for key, value in items.iteritems():
- res.append(value.format_http())
- self.finish_request(res)
-
- def options(self):
- """
- I'm not visible in the swagger docs
- """
- self.finish_request("I'm invisible in the swagger docs")
-
-
-class ItemHandler(GenericApiHandler):
- @swagger.operation(nickname='get')
- def get(self, arg):
- """
- @rtype: L{Item}
- @description: get information of a item
- @notes:
- get a item,
-
- This will be added to the Implementation Notes.
- It lets you put very long text in your api.
- """
- self.finish_request(items[arg].format_http())
-
- @swagger.operation(nickname='delete')
- def delete(self, arg):
- """
- @description: delete a item
- @notes:
- delete a item in items
- """
- del items[arg]
- self.finish_request("success")
-
-
-class ItemOptionParamHandler(GenericApiHandler):
- @swagger.operation(nickname='create')
- def post(self, arg1, arg2=''):
- """
- @return 200: case is created
- """
- fs = open("/home/%s/%s" % (arg1, arg2), "wb")
- fs.write(self.request.body)
- self.write("success")
-
-
-class ItemQueryHandler(GenericApiHandler):
- @swagger.operation(nickname='query')
- def get(self):
- """
- @param property1:
- @type property1: L{string}
- @in property1: query
- @required property1: False
-
- @param property2:
- @type property2: L{string}
- @in property2: query
- @required property2: True
- @rtype: L{Item}
- @notes: GET /item?property1=1&property2=1
- """
- property1 = self.get_query_argument("property1", None)
- property2 = self.get_query_argument("property2", None)
-
- res = []
- if property1 is None:
- for key, value in items.iteritems():
- if property2 is None:
- res.append(value.format_http())
- elif value.property2 == property2:
- res.append(value.format_http())
- elif property1 in items:
- if items.get(property1).property2 == property2:
- res.append(items.get(property1).format_http())
-
- self.finish_request(res)
-
-
-def make_app():
- return swagger.Application([
- (r"/item", ItemQueryHandler),
- (r"/items", ItemNoParamHandler),
- (r"/items/([^/]+)", ItemHandler),
- (r"/items/([^/]+)/cases/([^/]+)", ItemOptionParamHandler),
- ])
-
-
-if __name__ == "__main__":
- app = make_app()
- app.listen(711)
- tornado.ioloop.IOLoop.current().start()
+++ /dev/null
-try:
- from setuptools import setup
-except ImportError:
- from distutils.core import setup
-
-with open('README') as f:
- long_description = f.read()
-
-setup(name='tornado-swagger',
- version='1.0',
- url='https://github.com/SerenaFeng/tornado-swagger',
- zip_safe=False,
- packages=['tornado_swagger'],
- package_data={
- 'tornado_swagger': [
- 'static/*.*',
- 'static/css/*.*',
- 'static/images/*.*',
- 'static/lib/*.*',
- 'static/lib/shred/*.*'
- ]
- },
- description='Extract swagger specs from your tornado project',
- author='Serena Feng',
- license='MIT',
- long_description=long_description,
- install_requires=[
- 'tornado>=3.1',
- 'epydoc>=0.3.1'
- ])
+++ /dev/null
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-__author__ = 'serena'
opnfv_testapi
package_data =
opnfv_testapi =
- tornado_swagger_ui/tornado_swagger/static/*.*
- tornado_swagger_ui/tornado_swagger/static/css/*.*
- tornado_swagger_ui/tornado_swagger/static/images/*.*
- tornado_swagger_ui/tornado_swagger/static/lib/*.*
- tornado_swagger_ui/tornado_swagger/static/lib/shred/*.*
+ tornado_swagger/static/*.*
+ tornado_swagger/static/css/*.*
+ tornado_swagger/static/images/*.*
+ tornado_swagger/static/lib/*.*
+ tornado_swagger/static/lib/shred/*.*
data_files =
/etc/opnfv_testapi =
etc/config.ini