X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Ftest%2Ftestapi%2Fopnfv_testapi%2Fresources%2Fhandlers.py;h=8e5dab23538c3fd1d44a8d7e8475c8172e5ec2d9;hb=63fbd31ac218846da13f84ee17ef7a61e159055f;hp=685687a48e77ff538c31257e45abf05661d69ae9;hpb=58d4a3695c36f95204820a5e693ea78ed1beb0a6;p=releng.git diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py index 685687a48..8e5dab235 100644 --- a/utils/test/testapi/opnfv_testapi/resources/handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py @@ -73,7 +73,10 @@ class GenericApiHandler(web.RequestHandler): cls_data = self.table_cls.from_dict(data) return cls_data.format_http() - @check.authenticate + @web.asynchronous + @gen.coroutine + @check.is_authorized + @check.valid_token @check.no_body @check.miss_fields @check.carriers_exist @@ -110,22 +113,23 @@ class GenericApiHandler(web.RequestHandler): pipelines.append({'$match': query}) total_pages = 0 - if page > 0: - cursor = dbapi.db_list(self.table, query) - records_count = yield cursor.count() - total_pages, return_nr = self._calc_total_pages(records_count, - last, - page, - per_page) - pipelines = self._set_pipelines(pipelines, - sort, - return_nr, - page, - per_page) - cursor = dbapi.db_aggregate(self.table, pipelines) data = list() - while (yield cursor.fetch_next): - data.append(self.format_data(cursor.next_object())) + cursor = dbapi.db_list(self.table, query) + records_count = yield cursor.count() + if records_count > 0: + if page > 0: + total_pages, return_nr = self._calc_total_pages(records_count, + last, + page, + per_page) + pipelines = self._set_pipelines(pipelines, + sort, + return_nr, + page, + per_page) + cursor = dbapi.db_aggregate(self.table, pipelines) + while (yield cursor.fetch_next): + data.append(self.format_data(cursor.next_object())) if res_op is None: res = {self.table: data} else: @@ -171,13 +175,15 @@ class GenericApiHandler(web.RequestHandler): def _get_one(self, data, query=None): self.finish_request(self.format_data(data)) - @check.authenticate + @web.asynchronous + @gen.coroutine @check.not_exist def _delete(self, data, query=None): yield dbapi.db_delete(self.table, query) self.finish_request() - @check.authenticate + @web.asynchronous + @gen.coroutine @check.no_body @check.not_exist @check.updated_one_not_exist @@ -188,7 +194,8 @@ class GenericApiHandler(web.RequestHandler): update_req['_id'] = str(data._id) self.finish_request(update_req) - @check.authenticate + @web.asynchronous + @gen.coroutine @check.no_body @check.not_exist @check.updated_one_not_exist @@ -196,6 +203,7 @@ class GenericApiHandler(web.RequestHandler): data = self.table_cls.from_dict(data) update_req = self._update_requests(data) yield dbapi.db_update(self.table, query, update_req) + self.finish_request() def _update_requests(self, data): request = dict()