summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi/resources
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/resources')
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py45
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_models.py34
2 files changed, 69 insertions, 10 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
index 7bf3d5d53..28fe28e68 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
@@ -19,11 +19,49 @@ class ScenariosCLHandler(GenericScenarioHandler):
"""
@description: Retrieve scenario(s).
@notes: Retrieve scenario(s)
- @return 200: all scenarios consist with query,
+ Available filters for this request are :
+ - name : scenario name
+
+ GET /scenarios?name=scenario_1
+ @param name: scenario name
+ @type name: L{string}
+ @in name: query
+ @required name: False
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: False
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: False
+ @param project: project name
+ @type project: L{string}
+ @in project: query
+ @required project: False
+ @return 200: all scenarios satisfy queries,
empty list if no scenario is found
@rtype: L{Scenarios}
"""
- self._list()
+
+ def _set_query():
+ query = dict()
+ elem_query = dict()
+ for k in self.request.query_arguments.keys():
+ v = self.get_query_argument(k)
+ if k == 'installer':
+ elem_query["installer"] = v
+ elif k == 'version':
+ elem_query["versions.version"] = v
+ elif k == 'project':
+ elem_query["versions.projects.project"] = v
+ else:
+ query[k] = v
+ if elem_query:
+ query['installers'] = {'$elemMatch': elem_query}
+ return query
+
+ self._list(_set_query())
@swagger.operation(nickname="Create a new scenario")
def post(self):
@@ -58,6 +96,7 @@ class ScenarioGURHandler(GenericScenarioHandler):
@return 200: scenario exist
@raise 404: scenario not exist
"""
+ self._get_one({'name': name})
pass
@swagger.operation(nickname="Update the scenario by name")
@@ -65,7 +104,7 @@ class ScenarioGURHandler(GenericScenarioHandler):
"""
@description: update a single scenario by name
@param body: fields to be updated
- @type body: L{string}
+ @type body: L{ScenarioCreateRequest}
@in body: body
@rtype: L{Scenario}
@return 200: update success
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
index b4bb3634b..f89a12428 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
@@ -11,7 +11,7 @@ class ScenarioTI(models.ModelBase):
@swagger.model()
class ScenarioScore(models.ModelBase):
- def __init__(self, date=None, score=''):
+ def __init__(self, date=None, score='0'):
self.date = date
self.score = score
@@ -27,14 +27,19 @@ class ScenarioProject(models.ModelBase):
@ptype trust_indicators: C{list} of L{ScenarioTI}
"""
def __init__(self,
- name='',
+ project='',
customs=None,
scores=None,
trust_indicators=None):
- self.name = name
+ self.project = project
self.customs = customs
self.scores = scores
- self.trust_indicator = trust_indicators
+ self.trust_indicators = trust_indicators
+
+ @staticmethod
+ def attr_parser():
+ return {'scores': ScenarioScore,
+ 'trust_indicators': ScenarioTI}
@swagger.model()
@@ -43,10 +48,14 @@ class ScenarioVersion(models.ModelBase):
@property projects:
@ptype projects: C{list} of L{ScenarioProject}
"""
- def __init__(self, version, projects=None):
+ def __init__(self, version=None, projects=None):
self.version = version
self.projects = projects
+ @staticmethod
+ def attr_parser():
+ return {'projects': ScenarioProject}
+
@swagger.model()
class ScenarioInstaller(models.ModelBase):
@@ -54,11 +63,14 @@ class ScenarioInstaller(models.ModelBase):
@property versions:
@ptype versions: C{list} of L{ScenarioVersion}
"""
- def __init__(self, installer=None, owner=None, versions=None):
+ def __init__(self, installer=None, versions=None):
self.installer = installer
- self.owner = owner
self.versions = versions if versions else list()
+ @staticmethod
+ def attr_parser():
+ return {'versions': ScenarioVersion}
+
@swagger.model()
class ScenarioCreateRequest(models.ModelBase):
@@ -70,6 +82,10 @@ class ScenarioCreateRequest(models.ModelBase):
self.name = name
self.installers = installers if installers else list()
+ @staticmethod
+ def attr_parser():
+ return {'installers': ScenarioInstaller}
+
@swagger.model()
class Scenario(models.ModelBase):
@@ -83,6 +99,10 @@ class Scenario(models.ModelBase):
self.creation_date = create_date
self.installers = installers if installers else list()
+ @staticmethod
+ def attr_parser():
+ return {'installers': ScenarioInstaller}
+
@swagger.model()
class Scenarios(models.ModelBase):