summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi/tests
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-06-20 17:40:38 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-06-20 17:45:42 +0800
commitd96bf32a81e1c109c87013db5799940c0f9d726b (patch)
treebd496f878173b51d1cd298d38dbf1ee8920748c9 /utils/test/testapi/opnfv_testapi/tests
parentb9492a0eaac9838fdfb6b070bcec328387881129 (diff)
support pagination in TestAPI
In this patch, pagination is supported, so you can go through results leveraging: http://testresults.opnfv.org/test/api/v1/results?page=2 Change-Id: Ibe31c787643f27dbb06c4899e713b3c8e716e784 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/tests')
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py b/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
index ef74a0857..b2564a6de 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
@@ -20,18 +20,18 @@ def thread_execute(method, *args, **kwargs):
class MemCursor(object):
def __init__(self, collection):
self.collection = collection
- self.count = len(self.collection)
+ self.length = len(self.collection)
self.sorted = []
def _is_next_exist(self):
- return self.count != 0
+ return self.length != 0
@property
def fetch_next(self):
return thread_execute(self._is_next_exist)
def next_object(self):
- self.count -= 1
+ self.length -= 1
return self.collection.pop()
def sort(self, key_or_list):
@@ -48,10 +48,25 @@ class MemCursor(object):
def limit(self, limit):
if limit != 0 and limit < len(self.collection):
- self.collection = self.collection[0:limit]
- self.count = limit
+ self.collection = self.collection[0: limit]
+ self.length = limit
return self
+ def skip(self, skip):
+ if skip < self.length and (skip > 0):
+ self.collection = self.collection[self.length - skip: -1]
+ self.length -= skip
+ elif skip >= self.length:
+ self.collection = []
+ self.length = 0
+ return self
+
+ def _count(self):
+ return self.length
+
+ def count(self):
+ return thread_execute(self._count)
+
class MemDb(object):