diff options
Diffstat (limited to 'utils/test/testapi')
3 files changed, 98 insertions, 22 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py index a89e7ee13..66e8559f7 100644 --- a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py @@ -13,10 +13,10 @@ class GenericScenarioHandler(handlers.GenericApiHandler): self.table = self.db_scenarios self.table_cls = models.Scenario - def set_query(self, filters): + def set_query(self, locators): query = dict() elem_query = dict() - for k, v in filters.iteritems(): + for k, v in locators.iteritems(): if k == 'scenario': query['name'] = v elif k == 'installer': @@ -134,11 +134,12 @@ class ScenarioUpdater(object): self.version = version self.project = project - def update(self, item, op): + def update(self, item, action): updates = { - ('score', 'add'): self._update_requests_add_score, + ('scores', 'post'): self._update_requests_add_score, + ('trust_indicators', 'post'): self._update_requests_add_ti, } - updates[(item, op)](self.data) + updates[(item, action)](self.data) return self.data.format() @@ -170,6 +171,13 @@ class ScenarioUpdater(object): project.scores.append( models.ScenarioScore.from_dict(self.body)) + @iter_installers + @iter_versions + @iter_projects + def _update_requests_add_ti(self, project): + project.trust_indicators.append( + models.ScenarioTI.from_dict(self.body)) + def _filter_installers(self, installers): return self._filter('installer', installers) @@ -185,7 +193,36 @@ class ScenarioUpdater(object): items) -class ScenarioScoresHandler(GenericScenarioHandler): +class GenericScenarioUpdateHandler(GenericScenarioHandler): + def __init__(self, application, request, **kwargs): + super(GenericScenarioUpdateHandler, self).__init__(application, + request, + **kwargs) + self.installer = None + self.version = None + self.project = None + self.item = None + self.action = None + + def do_post(self, scenario, item, action, locators): + self.item = item + self.action = action + for k in locators.keys(): + v = self.get_query_argument(k) + setattr(self, k, v) + locators[k] = v + db_keys = ['name'] + self._update(query=self.set_query(locators=locators), db_keys=db_keys) + + def _update_requests(self, data): + return ScenarioUpdater(data, + self.json_args, + self.installer, + self.version, + self.project).update(self.item, self.action) + + +class ScenarioScoresHandler(GenericScenarioUpdateHandler): @swagger.operation(nickname="addScoreRecord") def post(self, scenario): """ @@ -214,20 +251,46 @@ class ScenarioScoresHandler(GenericScenarioHandler): @return 200: score is created. @raise 404: scenario/installer/version/project not existed """ - self.installer = self.get_query_argument('installer') - self.version = self.get_query_argument('version') - self.project = self.get_query_argument('project') - - filters = {'scenario': scenario, - 'installer': self.installer, - 'version': self.version, - 'project': self.project} - db_keys = ['name'] - self._update(query=self.set_query(filters=filters), db_keys=db_keys) + self.do_post(scenario, + 'scores', + 'post', + locators={'installer': None, + 'version': None, + 'project': None}) - def _update_requests(self, data): - return ScenarioUpdater(data, - self.json_args, - self.installer, - self.version, - self.project).update('score', 'add') + +class ScenarioTIsHandler(GenericScenarioUpdateHandler): + @swagger.operation(nickname="addTrustIndicatorRecord") + def post(self, scenario): + """ + @description: add a new trust indicator record + @notes: add a new trust indicator record to a project + POST /api/v1/scenarios/<scenario_name>/trust_indicators? \ + installer=<installer_name>& \ + version=<version_name>& \ + project=<project_name> + @param body: trust indicator to be added + @type body: L{ScenarioTI} + @in body: body + @param installer: installer type + @type installer: L{string} + @in installer: query + @required installer: True + @param version: version + @type version: L{string} + @in version: query + @required version: True + @param project: project name + @type project: L{string} + @in project: query + @required project: True + @rtype: L{Scenario} + @return 200: trust indicator is added. + @raise 404: scenario/installer/version/project not existed + """ + self.do_post(scenario, + 'trust_indicators', + 'post', + locators={'installer': None, + 'version': None, + 'project': None}) diff --git a/utils/test/testapi/opnfv_testapi/router/url_mappings.py b/utils/test/testapi/opnfv_testapi/router/url_mappings.py index 4f990f03e..458942576 100644 --- a/utils/test/testapi/opnfv_testapi/router/url_mappings.py +++ b/utils/test/testapi/opnfv_testapi/router/url_mappings.py @@ -56,6 +56,8 @@ mappings = [ (r"/api/v1/scenarios/([^/]+)", scenario_handlers.ScenarioGURHandler), (r"/api/v1/scenarios/([^/]+)/scores", scenario_handlers.ScenarioScoresHandler), + (r"/api/v1/scenarios/([^/]+)/trust_indicators", + scenario_handlers.ScenarioTIsHandler), # static path (r'/(.*\.(css|png|gif|js|html|json|map|woff2|woff|ttf))', diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py index c12c52ba9..0558ea30d 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_scenario.py @@ -189,6 +189,17 @@ class TestScenarioUpdate(TestScenarioBase): return add, scenario + @update_partial('_add', '_success') + def test_addTrustIndicator(self, scenario): + add = models.ScenarioTI(date=str(datetime.now()), status='gold') + projects = scenario['installers'][0]['versions'][0]['projects'] + functest = filter(lambda f: f['project'] == 'functest', projects)[0] + functest['trust_indicators'].append(add.format()) + self.update_url = '{}/trust_indicators?{}'.format(self.scenario_url, + self.locate_project) + + return add, scenario + def _add(self, update_req, new_scenario): return self.post_direct_url(self.update_url, update_req) |