summaryrefslogtreecommitdiffstats
path: root/result_collection_api/opnfv_testapi
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-06-04 14:58:14 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2016-06-04 15:13:14 +0800
commitaad984f2b471149f0c8ceaf2487583cb0e64edf1 (patch)
tree285295e1ad10b9220dab07ec54e3e01d46362a4d /result_collection_api/opnfv_testapi
parentb0deca64aa30b264ce845ed67118c36ba76c391b (diff)
test APi evolution add filter to retrieve last results
add 'last' query parameter prcess in ResultsCLHandler.get() add 'sort' and 'last' parameters process in GenericApiHandler._list() add sort() and limit() fake in fake_pymongo.py JIRA: FUNCTEST-259 Change-Id: I96c1ff37325c65cf9c421f4277662dde28b1473d Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'result_collection_api/opnfv_testapi')
-rw-r--r--result_collection_api/opnfv_testapi/resources/handlers.py6
-rw-r--r--result_collection_api/opnfv_testapi/resources/result_handlers.py15
-rw-r--r--result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py6
3 files changed, 24 insertions, 3 deletions
diff --git a/result_collection_api/opnfv_testapi/resources/handlers.py b/result_collection_api/opnfv_testapi/resources/handlers.py
index 3d39502..df920c4 100644
--- a/result_collection_api/opnfv_testapi/resources/handlers.py
+++ b/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/result_collection_api/opnfv_testapi/resources/result_handlers.py b/result_collection_api/opnfv_testapi/resources/result_handlers.py
index 473a38d..0a4c0db 100644
--- a/result_collection_api/opnfv_testapi/resources/result_handlers.py
+++ b/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):
diff --git a/result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py b/result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py
index e556968..9b4d120 100644
--- a/result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py
+++ b/result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py
@@ -32,6 +32,12 @@ class MemCursor(object):
self.count -= 1
return self.collection.pop()
+ def sort(self, key_or_list, direction=None):
+ return self
+
+ def limit(self, limit):
+ return self
+
class MemDb(object):