summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test/testapi/opnfv_testapi')
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/handlers.py1
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py61
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_models.py87
-rw-r--r--utils/test/testapi/opnfv_testapi/router/url_mappings.py7
4 files changed, 155 insertions, 1 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py
index f1ad15e97..9fc5d6be1 100644
--- a/utils/test/testapi/opnfv_testapi/resources/handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py
@@ -43,6 +43,7 @@ class GenericApiHandler(RequestHandler):
self.db_pods = 'pods'
self.db_testcases = 'testcases'
self.db_results = 'results'
+ self.db_scenarios = 'scenarios'
def prepare(self):
if self.request.method != "GET" and self.request.method != "DELETE":
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
new file mode 100644
index 000000000..75754d8b9
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
@@ -0,0 +1,61 @@
+from opnfv_testapi.resources.handlers import GenericApiHandler
+from opnfv_testapi.resources.scenario_models import Scenario
+from opnfv_testapi.tornado_swagger import swagger
+
+
+class GenericScenarioHandler(GenericApiHandler):
+ def __init__(self, application, request, **kwargs):
+ super(GenericScenarioHandler, self).__init__(application,
+ request,
+ **kwargs)
+ self.table = self.db_scenarios
+ self.table_cls = Scenario
+
+
+class ScenariosCLHandler(GenericScenarioHandler):
+ @swagger.operation(nickname="List scenarios by queries")
+ def get(self):
+ """
+ @description: Retrieve scenario(s).
+ @notes: Retrieve scenario(s)
+ @return 200: all scenarios consist with query,
+ empty list if no scenario is found
+ @rtype: L{Scenarios}
+ """
+ self._list()
+
+ @swagger.operation(nickname="Create a new scenario")
+ def post(self):
+ """
+ @description: create a new scenario by name
+ @param body: scenario to be created
+ @type body: L{string}
+ @rtype: L{CreateResponse}
+ """
+ pass
+
+
+class ScenarioGURHandler(GenericScenarioHandler):
+ @swagger.operation(nickname='Get the scenario by name')
+ def get(self, name):
+ """
+ @description: get a single scenario by name
+ @rtype: L{Scenario}
+ @return 200: scenario exist
+ @raise 404: scenario not exist
+ """
+ pass
+
+ @swagger.operation(nickname="Update the scenario by name")
+ def put(self, name):
+ """
+ @description: update a single scenario by name
+ @param body: fields to be updated
+ @type body: L{string}
+ @in body: body
+ @rtype: L{Scenario}
+ @return 200: update success
+ @raise 404: scenario not exist
+ @raise 403: nothing to update
+ """
+ pass
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
new file mode 100644
index 000000000..0748a3738
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
@@ -0,0 +1,87 @@
+import models
+from opnfv_testapi.tornado_swagger import swagger
+
+
+@swagger.model()
+class ScenarioTI(models.ModelBase):
+ def __init__(self, date=None, status='silver'):
+ self.date = date
+ self.status = status
+
+
+@swagger.model()
+class ScenarioScore(models.ModelBase):
+ def __init__(self, date=None, score=''):
+ self.date = date
+ self.score = score
+
+
+@swagger.model()
+class ScenarioProject(models.ModelBase):
+ """
+ @property customs:
+ @ptype customs: C{list} of L{string}
+ @property scores:
+ @ptype scores: C{list} of L{ScenarioScore}
+ @property trust_indicators:
+ @ptype trust_indicators: C{list} of L{ScenarioTI}
+ """
+ def __init__(self,
+ name='',
+ customs=None,
+ scores=None,
+ trust_indicators=None):
+ self.name = name
+ self.customs = customs
+ self.scores = scores
+ self.trust_indicator = trust_indicators
+
+
+@swagger.model()
+class ScenarioVersion(models.ModelBase):
+ """
+ @property projects:
+ @ptype projects: C{list} of L{ScenarioProject}
+ """
+ def __init__(self, version, projects=None):
+ self.version = version
+ self.projects = projects
+
+
+@swagger.model()
+class ScenarioInstaller(models.ModelBase):
+ """
+ @property versions:
+ @ptype versions: C{list} of L{ScenarioVersion}
+ """
+ def __init__(self, installer=None, owner=None, versions=None):
+ self.installer = installer
+ self.owner = owner
+ self.versions = versions if versions else list()
+
+
+@swagger.model()
+class Scenario(models.ModelBase):
+ """
+ @property installers:
+ @ptype installers: C{list} of L{ScenarioInstaller}
+ """
+ def __init__(self, name='', create_date='', _id='', installers=None):
+ self.name = name
+ self._id = _id
+ self.create_date = create_date
+ self.installers = installers if installers else list()
+
+
+@swagger.model()
+class Scenarios(models.ModelBase):
+ """
+ @property scenarios:
+ @ptype scenarios: C{list} of L{Scenario}
+ """
+ def __init__(self):
+ self.scenarios = list()
+
+ @staticmethod
+ def attr_parser():
+ return {'scenarios': Scenario}
diff --git a/utils/test/testapi/opnfv_testapi/router/url_mappings.py b/utils/test/testapi/opnfv_testapi/router/url_mappings.py
index eb648ecbb..0ae3c31c3 100644
--- a/utils/test/testapi/opnfv_testapi/router/url_mappings.py
+++ b/utils/test/testapi/opnfv_testapi/router/url_mappings.py
@@ -14,7 +14,8 @@ from opnfv_testapi.resources.project_handlers import ProjectCLHandler, \
ProjectGURHandler
from opnfv_testapi.resources.result_handlers import ResultsCLHandler, \
ResultsGURHandler
-
+from opnfv_testapi.resources.scenario_handlers import ScenariosCLHandler
+from opnfv_testapi.resources.scenario_handlers import ScenarioGURHandler
mappings = [
# GET /versions => GET API version
@@ -45,4 +46,8 @@ mappings = [
# (project, case, and pod)
(r"/api/v1/results", ResultsCLHandler),
(r"/api/v1/results/([^/]+)", ResultsGURHandler),
+
+ # scenarios
+ (r"/api/v1/scenarios", ScenariosCLHandler),
+ (r"/api/v1/scenarios/([^/]+)", ScenarioGURHandler),
]