summaryrefslogtreecommitdiffstats
path: root/utils/test/result_collection_api/resources/project_handlers.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-05-27 16:55:17 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2016-05-27 16:58:48 +0800
commitfd767d0b24749d5834a4aae85785a2e397da34bf (patch)
tree1b57fa64896dc9fa79d833ef06a80fd4dc363b30 /utils/test/result_collection_api/resources/project_handlers.py
parent6668fa4f4c1b660dc130775b3a3d8c38d6646e8d (diff)
swagger-ize testcase-apis of testAPI
Change-Id: Ibe4b068fd667b796455be3fd4d9701d50879aace JIRA: FUNCTEST-266 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/result_collection_api/resources/project_handlers.py')
-rw-r--r--utils/test/result_collection_api/resources/project_handlers.py67
1 files changed, 13 insertions, 54 deletions
diff --git a/utils/test/result_collection_api/resources/project_handlers.py b/utils/test/result_collection_api/resources/project_handlers.py
index 69ce3b592..e56c01c36 100644
--- a/utils/test/result_collection_api/resources/project_handlers.py
+++ b/utils/test/result_collection_api/resources/project_handlers.py
@@ -1,9 +1,6 @@
-from tornado import gen
-from tornado.web import HTTPError, asynchronous
-
from tornado_swagger_ui.tornado_swagger import swagger
-from handlers import GenericApiHandler, prepare_put_request, format_data
-from common.constants import HTTP_BAD_REQUEST, HTTP_FORBIDDEN, HTTP_NOT_FOUND
+from handlers import GenericApiHandler
+from common.constants import HTTP_FORBIDDEN
from project_models import Project
@@ -38,7 +35,15 @@ class ProjectCLHandler(GenericProjectHandler):
@raise 403: project already exists
@raise 400: post without body
"""
- self._create('{} already exists as a {}')
+ def query(data):
+ return {'name': data.name}
+
+ def error(data):
+ message = '{} already exists as a project'.format(data.name)
+ return HTTP_FORBIDDEN, message
+
+ db_check = [(self.table, False, query, error)]
+ self._create(db_check)
class ProjectGURHandler(GenericProjectHandler):
@@ -52,8 +57,6 @@ class ProjectGURHandler(GenericProjectHandler):
"""
self._get_one({'name': project_name})
- @asynchronous
- @gen.coroutine
@swagger.operation(nickname="update")
def put(self, project_name):
"""
@@ -66,53 +69,9 @@ class ProjectGURHandler(GenericProjectHandler):
@raise 404: project not exist
@raise 403: new project name already exist or nothing to update
"""
- if self.json_args is None:
- raise HTTPError(HTTP_BAD_REQUEST)
-
query = {'name': project_name}
- from_project = yield self.db.projects.find_one(query)
- if from_project is None:
- raise HTTPError(HTTP_NOT_FOUND,
- "{} could not be found".format(project_name))
-
- project = Project.from_dict(from_project)
- new_name = self.json_args.get("name")
- new_description = self.json_args.get("description")
-
- # check for payload name parameter in db
- # avoid a request if the project name has not changed in the payload
- if new_name != project.name:
- to_project = yield self.db.projects.find_one(
- {"name": new_name})
- if to_project is not None:
- raise HTTPError(HTTP_FORBIDDEN,
- "{} already exists as a project"
- .format(new_name))
-
- # new dict for changes
- request = dict()
- request = prepare_put_request(request,
- "name",
- new_name,
- project.name)
- request = prepare_put_request(request,
- "description",
- new_description,
- project.description)
-
- """ raise exception if there isn't a change """
- if not request:
- raise HTTPError(HTTP_FORBIDDEN, "Nothing to update")
-
- """ we merge the whole document """
- edit_request = project.format()
- edit_request.update(request)
-
- """ Updating the DB """
- yield self.db.projects.update(query, edit_request)
- new_project = yield self.db.projects.find_one({"_id": project._id})
-
- self.finish_request(format_data(new_project, Project))
+ db_keys = ['name']
+ self._update(query, db_keys)
@swagger.operation(nickname='delete')
def delete(self, project_name):