summaryrefslogtreecommitdiffstats
path: root/utils/test/result_collection_api/opnfv_testapi/resources
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2016-06-04 16:59:51 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-06-04 16:59:52 +0000
commit1e8e716c35b90005506417f118ba97d1c39e56da (patch)
tree93823342c70b11ac3eb9260a4d20e9000684cc7e /utils/test/result_collection_api/opnfv_testapi/resources
parentf61173ebe98f1c746f7cb7eef439d56590a4b78e (diff)
parent5d2050686734a4636efe1bd35221a7d6c60a3d5f (diff)
Merge "test APi evolution add filter to retrieve last results"
Diffstat (limited to 'utils/test/result_collection_api/opnfv_testapi/resources')
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/resources/handlers.py6
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py15
2 files changed, 18 insertions, 3 deletions
diff --git a/utils/test/result_collection_api/opnfv_testapi/resources/handlers.py b/utils/test/result_collection_api/opnfv_testapi/resources/handlers.py
index 3d39502db..df920c48f 100644
--- a/utils/test/result_collection_api/opnfv_testapi/resources/handlers.py
+++ b/utils/test/result_collection_api/opnfv_testapi/resources/handlers.py
@@ -106,11 +106,15 @@ class GenericApiHandler(RequestHandler):
@asynchronous
@gen.coroutine
- def _list(self, query=None, res_op=None, *args):
+ def _list(self, query=None, res_op=None, *args, **kwargs):
if query is None:
query = {}
data = []
cursor = self._eval_db(self.table, 'find', query)
+ if 'sort' in kwargs:
+ cursor = cursor.sort(kwargs.get('sort'))
+ if 'last' in kwargs:
+ cursor = cursor.limit(kwargs.get('last'))
while (yield cursor.fetch_next):
data.append(self.format_data(cursor.next_object()))
if res_op is None:
diff --git a/utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py b/utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py
index 473a38d06..0a4c0db7b 100644
--- a/utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py
+++ b/utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py
@@ -42,7 +42,7 @@ class GenericResultHandler(GenericApiHandler):
query['start_date'] = obj
elif k == 'trust_indicator':
query[k] = float(v)
- else:
+ elif k != 'last':
query[k] = v
return query
@@ -108,12 +108,23 @@ class ResultsCLHandler(GenericResultHandler):
@type period: L{string}
@in period: query
@required period: False
+ @param last: last days
+ @type last: L{string}
+ @in last: query
+ @required last: False
@param trust_indicator: must be int/long/float
@type trust_indicator: L{string}
@in trust_indicator: query
@required trust_indicator: False
"""
- self._list(self.set_query())
+ last = self.get_query_argument('last', 0)
+ if last is not None:
+ try:
+ last = int(last)
+ except:
+ raise HTTPError(HTTP_BAD_REQUEST, 'last must be int')
+
+ self._list(self.set_query(), sort=[{'start_date', -1}], last=last)
@swagger.operation(nickname="create")
def post(self):