diff options
Diffstat (limited to 'utils/test/result_collection_api/resources/project_handlers.py')
-rw-r--r-- | utils/test/result_collection_api/resources/project_handlers.py | 67 |
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): |