summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-05-31 23:18:46 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2016-05-31 23:18:46 +0800
commit915d8d123d665d47037e7385261a97b9113ddcd5 (patch)
tree1d70cce5d9a2f64d9eff5594c8a5083372417507 /utils/test
parentbbdf9f2a5ce6ef146a872aa0914588df714c1d95 (diff)
bugfix: query results failed due to wrong using period
JIRA: FUNCTEST-281 Change-Id: I3d0bdc302afc45593ad3feaec21b89d5c6eeaa0b Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/result_collection_api/resources/result_handlers.py2
-rw-r--r--utils/test/result_collection_api/tests/unit/fake_pymongo.py15
-rw-r--r--utils/test/result_collection_api/tests/unit/test_result.py26
3 files changed, 36 insertions, 7 deletions
diff --git a/utils/test/result_collection_api/resources/result_handlers.py b/utils/test/result_collection_api/resources/result_handlers.py
index 1d52235f6..f745d6331 100644
--- a/utils/test/result_collection_api/resources/result_handlers.py
+++ b/utils/test/result_collection_api/resources/result_handlers.py
@@ -31,7 +31,7 @@ class GenericResultHandler(GenericApiHandler):
if v > 0:
period = datetime.now() - timedelta(days=v)
obj = {"$gte": str(period)}
- query['creation_date'] = obj
+ query['start_date'] = obj
elif k == 'trust_indicator':
query[k] = float(v)
else:
diff --git a/utils/test/result_collection_api/tests/unit/fake_pymongo.py b/utils/test/result_collection_api/tests/unit/fake_pymongo.py
index 95c7371dc..bebb9e8b3 100644
--- a/utils/test/result_collection_api/tests/unit/fake_pymongo.py
+++ b/utils/test/result_collection_api/tests/unit/fake_pymongo.py
@@ -74,10 +74,23 @@ class MemDb(object):
return thread_execute(self._insert, doc_or_docs, check_keys)
@staticmethod
+ def _compare_date(spec, value):
+ for k, v in spec.iteritems():
+ if k == '$gte' and value >= v:
+ return True
+ return False
+
+ @staticmethod
def _in(content, *args):
for arg in args:
for k, v in arg.iteritems():
- if k != 'creation_date' and content.get(k, None) != v:
+ if k == 'start_date':
+ if not MemDb._compare_date(v, content.get(k)):
+ return False
+ elif k == 'trust_indicator':
+ if float(content.get(k)) != float(v):
+ return False
+ elif content.get(k, None) != v:
return False
return True
diff --git a/utils/test/result_collection_api/tests/unit/test_result.py b/utils/test/result_collection_api/tests/unit/test_result.py
index 7b1f97654..40daab87a 100644
--- a/utils/test/result_collection_api/tests/unit/test_result.py
+++ b/utils/test/result_collection_api/tests/unit/test_result.py
@@ -199,8 +199,15 @@ class TestResultGet(TestResultBase):
def test_queryCriteria(self):
self._query_and_assert(self._set_query('criteria'))
- def test_queryPeriod(self):
- self._query_and_assert(self._set_query('period=1'))
+ def test_queryPeriodFail(self):
+ self._query_and_assert(self._set_query('period=1'),
+ aheadof=True,
+ found=False)
+
+ def test_queryPeriodSuccess(self):
+ self._query_and_assert(self._set_query('period=1'),
+ aheadof=False,
+ found=True)
def test_combination(self):
self._query_and_assert(self._set_query('pod',
@@ -227,8 +234,17 @@ class TestResultGet(TestResultBase):
'period=1'),
found=False)
- def _query_and_assert(self, query, found=True):
- _, res = self.create_d()
+ def _query_and_assert(self, query, aheadof=False, found=True):
+ import copy
+ from datetime import datetime, timedelta
+ req = copy.deepcopy(self.req_d)
+ if aheadof:
+ req.start_date = datetime.now() - timedelta(days=10)
+ else:
+ req.start_date = datetime.now()
+ req.stop_date = str(req.start_date + timedelta(minutes=10))
+ req.start_date = str(req.start_date)
+ _, res = self.create(req)
code, body = self.query(query)
if not found:
self.assertEqual(code, HTTP_OK)
@@ -236,7 +252,7 @@ class TestResultGet(TestResultBase):
else:
self.assertEqual(1, len(body.results))
for result in body.results:
- self.assert_res(code, result)
+ self.assert_res(code, result, req)
def _set_query(self, *args):
uri = ''