Merge "bugfix: OperationFailure: the limit must be positive"
authorSerena Feng <feng.xiaowei@zte.com.cn>
Tue, 22 Aug 2017 01:42:55 +0000 (01:42 +0000)
committerGerrit Code Review <gerrit@opnfv.org>
Tue, 22 Aug 2017 01:42:55 +0000 (01:42 +0000)
1  2 
utils/test/testapi/opnfv_testapi/resources/handlers.py

@@@ -50,7 -50,7 +50,7 @@@ class GenericApiHandler(web.RequestHand
          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):
          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:
          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)
 +        self.finish_request()
 +
      def _update_requests(self, data):
          request = dict()
          for k, v in self.json_args.iteritems():