summaryrefslogtreecommitdiffstats
path: root/utils/test/result_collection_api/opnfv_testapi/resources
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-06-06 11:01:13 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2016-06-06 11:01:13 +0800
commitcdf0e83b6697d2ff75ba30b567ead5bcfea0fa25 (patch)
treed96f2c4894d95d1f1a8bddb3b1b19a88722aadd7 /utils/test/result_collection_api/opnfv_testapi/resources
parent4e1089f55f3b52ddbb2c38246027b58215004037 (diff)
refactor int query parameter process in testAPI
add method GenericResultHandler.get_int() refactor GenericResultHandler.set_query() & ResultsCLHandler.get() JIRA: FUNCTEST-294 Change-Id: I44636983af7784a5b2863427abc0895e89cfa83c Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/result_collection_api/opnfv_testapi/resources')
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py17
1 files changed, 9 insertions, 8 deletions
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 0a4c0db7b..44834fd63 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
@@ -25,6 +25,13 @@ class GenericResultHandler(GenericApiHandler):
self.table = self.db_results
self.table_cls = TestResult
+ def get_int(self, key, value):
+ try:
+ value = int(value)
+ except:
+ raise HTTPError(HTTP_BAD_REQUEST, '{} must be int', key)
+ return value
+
def set_query(self):
query = dict()
for k in self.request.query_arguments.keys():
@@ -32,10 +39,7 @@ class GenericResultHandler(GenericApiHandler):
if k == 'project' or k == 'pod' or k == 'case':
query[k + '_name'] = v
elif k == 'period':
- try:
- v = int(v)
- except:
- raise HTTPError(HTTP_BAD_REQUEST, 'period must be int')
+ v = self.get_int(k, v)
if v > 0:
period = datetime.now() - timedelta(days=v)
obj = {"$gte": str(period)}
@@ -119,10 +123,7 @@ class ResultsCLHandler(GenericResultHandler):
"""
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')
+ last = self.get_int('last', last)
self._list(self.set_query(), sort=[{'start_date', -1}], last=last)