X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=utils%2Ftest%2Ftestapi%2Fopnfv_testapi%2Fresources%2Fhandlers.py;h=8e5dab23538c3fd1d44a8d7e8475c8172e5ec2d9;hb=63fbd31ac218846da13f84ee17ef7a61e159055f;hp=474a2033b585b7d76df3c1bb5c9e3442b13ab870;hpb=4f6caf1fc33163e92c77f4f326601860023c4801;p=releng.git diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py index 474a2033b..8e5dab235 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): @@ -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,6 +194,17 @@ class GenericApiHandler(web.RequestHandler): update_req['_id'] = str(data._id) self.finish_request(update_req) + @web.asynchronous + @gen.coroutine + @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) + self.finish_request() + def _update_requests(self, data): request = dict() for k, v in self.json_args.iteritems():