summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-07-20 18:20:21 +0800
committerSerena Feng <feng.xiaowei@zte.com.cn>2017-07-21 13:35:07 +0000
commit1675a3a90118579b0ecbb122ccc3027e311399e1 (patch)
tree6405fa39d77d93eb2cf130a3ca6e7e7897e1fce8 /utils/test
parent822cd5c32c9a129aa8aad9952f25a37123c96733 (diff)
query date from oldest to newest
Change-Id: I3d0345bb85967f48617c485bbee1dfe6fa04a644 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/result_handlers.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
index 1ccafd507..2bf1792f2 100644
--- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
@@ -66,7 +66,7 @@ class GenericResultHandler(handlers.GenericApiHandler):
del query['public']
if role != "reviewer":
query['user'] = openid
- elif k != 'last' and k != 'page':
+ elif k not in ['last', 'page', 'descend']:
query[k] = v
if date_range:
query['start_date'] = date_range
@@ -167,18 +167,27 @@ class ResultsCLHandler(GenericResultHandler):
@type signed: L{string}
@in signed: query
@required signed: False
+ @param descend: true, newest2oldest; false, oldest2newest
+ @type descend: L{string}
+ @in descend: query
+ @required descend: False
"""
- limitations = {'sort': {'_id': -1}}
- last = self.get_query_argument('last', 0)
- if last is not None:
- last = self.get_int('last', last)
- limitations.update({'last': last})
+ def descend_limit():
+ descend = self.get_query_argument('descend', 'true')
+ return -1 if descend.lower() == 'true' else 1
- page = self.get_query_argument('page', None)
- if page is not None:
- page = self.get_int('page', page)
- limitations.update({'page': page,
- 'per_page': CONF.api_results_per_page})
+ def last_limit():
+ return self.get_int('last', self.get_query_argument('last', 0))
+
+ def page_limit():
+ return self.get_int('page', self.get_query_argument('page', 0))
+
+ limitations = {
+ 'sort': {'_id': descend_limit()},
+ 'last': last_limit(),
+ 'page': page_limit(),
+ 'per_page': CONF.api_results_per_page
+ }
self._list(query=self.set_query(), **limitations)