diff options
author | Serena Feng <feng.xiaowei@zte.com.cn> | 2017-08-22 01:41:57 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-08-22 01:41:57 +0000 |
commit | 58d4a3695c36f95204820a5e693ea78ed1beb0a6 (patch) | |
tree | a6eb5044b21cb138ff2d1dd75e9d70f8ed28e94f /utils/test/testapi/opnfv_testapi/resources | |
parent | 4f6caf1fc33163e92c77f4f326601860023c4801 (diff) | |
parent | d9950c167886a2df6684de313d95f5aa3f8d89ed (diff) |
Merge "update customs in scenario"
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/resources')
-rw-r--r-- | utils/test/testapi/opnfv_testapi/resources/handlers.py | 11 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py | 168 |
2 files changed, 157 insertions, 22 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py index 474a2033b..685687a48 100644 --- a/utils/test/testapi/opnfv_testapi/resources/handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py @@ -50,7 +50,7 @@ class GenericApiHandler(web.RequestHandler): self.auth = self.settings["auth"] def prepare(self): - if self.request.method != "GET" and self.request.method != "DELETE": + if self.request.body: if self.request.headers.get("Content-Type") is not None: if self.request.headers["Content-Type"].startswith( DEFAULT_REPRESENTATION): @@ -188,6 +188,15 @@ class GenericApiHandler(web.RequestHandler): update_req['_id'] = str(data._id) self.finish_request(update_req) + @check.authenticate + @check.no_body + @check.not_exist + @check.updated_one_not_exist + def pure_update(self, data, query=None, **kwargs): + data = self.table_cls.from_dict(data) + update_req = self._update_requests(data) + yield dbapi.db_update(self.table, query, update_req) + def _update_requests(self, data): request = dict() for k, v in self.json_args.iteritems(): diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py index 66e8559f7..c3d471c57 100644 --- a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py @@ -138,6 +138,9 @@ class ScenarioUpdater(object): updates = { ('scores', 'post'): self._update_requests_add_score, ('trust_indicators', 'post'): self._update_requests_add_ti, + ('customs', 'post'): self._update_requests_add_customs, + ('customs', 'put'): self._update_requests_update_customs, + ('customs', 'delete'): self._update_requests_delete_customs, } updates[(item, action)](self.data) @@ -178,6 +181,26 @@ class ScenarioUpdater(object): project.trust_indicators.append( models.ScenarioTI.from_dict(self.body)) + @iter_installers + @iter_versions + @iter_projects + def _update_requests_add_customs(self, project): + project.customs = list(set(project.customs + self.body)) + + @iter_installers + @iter_versions + @iter_projects + def _update_requests_update_customs(self, project): + project.customs = list(set(self.body)) + + @iter_installers + @iter_versions + @iter_projects + def _update_requests_delete_customs(self, project): + project.customs = filter( + lambda f: f not in self.body, + project.customs) + def _filter_installers(self, installers): return self._filter('installer', installers) @@ -204,15 +227,16 @@ class GenericScenarioUpdateHandler(GenericScenarioHandler): self.item = None self.action = None - def do_post(self, scenario, item, action, locators): + def do_update(self, 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) + for k, v in locators.iteritems(): + if not v: + v = self.get_query_argument(k) + setattr(self, k, v) + locators[k] = v + self.pure_update(query=self.set_query(locators=locators)) + self.finish_request() def _update_requests(self, data): return ScenarioUpdater(data, @@ -247,16 +271,15 @@ class ScenarioScoresHandler(GenericScenarioUpdateHandler): @type project: L{string} @in project: query @required project: True - @rtype: L{Scenario} @return 200: score is created. @raise 404: scenario/installer/version/project not existed """ - self.do_post(scenario, - 'scores', - 'post', - locators={'installer': None, - 'version': None, - 'project': None}) + self.do_update('scores', + 'post', + locators={'scenario': scenario, + 'installer': None, + 'version': None, + 'project': None}) class ScenarioTIsHandler(GenericScenarioUpdateHandler): @@ -284,13 +307,116 @@ class ScenarioTIsHandler(GenericScenarioUpdateHandler): @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}) + self.do_update('trust_indicators', + 'post', + locators={'scenario': scenario, + 'installer': None, + 'version': None, + 'project': None}) + + +class ScenarioCustomsHandler(GenericScenarioUpdateHandler): + @swagger.operation(nickname="addCustomizedTestCases") + def post(self, scenario): + """ + @description: add customized test cases + @notes: add several test cases to a project + POST /api/v1/scenarios/<scenario_name>/customs? \ + installer=<installer_name>& \ + version=<version_name>& \ + project=<project_name> + @param body: test cases to be added + @type body: C{list} of L{string} + @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 + @return 200: test cases are added. + @raise 404: scenario/installer/version/project not existed + """ + self.do_update('customs', + 'post', + locators={'scenario': scenario, + 'installer': None, + 'version': None, + 'project': None}) + + @swagger.operation(nickname="updateCustomizedTestCases") + def put(self, scenario): + """ + @description: update customized test cases + @notes: substitute all the customized test cases + PUT /api/v1/scenarios/<scenario_name>/customs? \ + installer=<installer_name>& \ + version=<version_name>& \ + project=<project_name> + @param body: new supported test cases + @type body: C{list} of L{string} + @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 + @return 200: substitute test cases success. + @raise 404: scenario/installer/version/project not existed + """ + self.do_update('customs', + 'put', + locators={'scenario': scenario, + 'installer': None, + 'version': None, + 'project': None}) + + @swagger.operation(nickname="deleteCustomizedTestCases") + def delete(self, scenario): + """ + @description: delete one or several customized test cases + @notes: delete one or some customized test cases + DELETE /api/v1/scenarios/<scenario_name>/customs? \ + installer=<installer_name>& \ + version=<version_name>& \ + project=<project_name> + @param body: test case(s) to be deleted + @type body: C{list} of L{string} + @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 + @return 200: delete test case(s) success. + @raise 404: scenario/installer/version/project not existed + """ + self.do_update('customs', + 'delete', + locators={'scenario': scenario, + 'installer': None, + 'version': None, + 'project': None}) |