diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-06-20 17:40:38 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-06-20 17:45:42 +0800 |
commit | b87da1f862c1966dba0c60cb5368b86bb698104e (patch) | |
tree | 5254e00c8185233327c688c6539b196ac5bd87f5 /testapi/opnfv_testapi/tests/unit | |
parent | c9cb0fd7d6b7f3736f94b0eebb517f248b8e670e (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 'testapi/opnfv_testapi/tests/unit')
-rw-r--r-- | testapi/opnfv_testapi/tests/unit/fake_pymongo.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/testapi/opnfv_testapi/tests/unit/fake_pymongo.py b/testapi/opnfv_testapi/tests/unit/fake_pymongo.py index ef74a08..b2564a6 100644 --- a/testapi/opnfv_testapi/tests/unit/fake_pymongo.py +++ b/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): |