summaryrefslogtreecommitdiffstats
path: root/result_collection_api/tests/unit/fake_pymongo.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-05-23 18:34:19 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2016-05-25 15:14:28 +0800
commit0c898e11323cf4e5baabecb55d8be2ff2268690d (patch)
tree85860cd1859ebcfc6c877c115acecbab8b2c5266 /result_collection_api/tests/unit/fake_pymongo.py
parent12ef6fc908872a2c8f52b53d3f2527d98365fd91 (diff)
add test result/dashboard related unittests in testAPI and refactor its response
modification: add unittests for test result/dashboard rename test_results table name in db to results refactor response body JIRA: FUNCTEST-255 Change-Id: I0657e6e95156a8c79072e7333fd8aaeb12d986e5 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'result_collection_api/tests/unit/fake_pymongo.py')
-rw-r--r--result_collection_api/tests/unit/fake_pymongo.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/result_collection_api/tests/unit/fake_pymongo.py b/result_collection_api/tests/unit/fake_pymongo.py
index 1521bfa..40eb164 100644
--- a/result_collection_api/tests/unit/fake_pymongo.py
+++ b/result_collection_api/tests/unit/fake_pymongo.py
@@ -1,6 +1,7 @@
from bson.objectid import ObjectId
from concurrent.futures import ThreadPoolExecutor
+
__author__ = 'serena'
@@ -42,7 +43,7 @@ class MemDb(object):
result = executor.submit(self._find_one, spec_or_id, *args)
return result
- def _insert(self, doc_or_docs):
+ def _insert(self, doc_or_docs, check_keys=True):
docs = doc_or_docs
return_one = False
@@ -53,8 +54,8 @@ class MemDb(object):
ids = []
for doc in docs:
if '_id' not in doc:
- doc['_id'] = ObjectId()
- if not self._find_one(doc['_id']):
+ doc['_id'] = str(ObjectId())
+ if not check_keys or not self._find_one(doc['_id']):
ids.append(doc['_id'])
self.contents.append(doc_or_docs)
@@ -65,16 +66,16 @@ class MemDb(object):
else:
return ids
- def insert(self, doc_or_docs):
+ def insert(self, doc_or_docs, check_keys=True):
with ThreadPoolExecutor(max_workers=2) as executor:
- result = executor.submit(self._insert, doc_or_docs)
+ result = executor.submit(self._insert, doc_or_docs, check_keys)
return result
@staticmethod
def _in(content, *args):
for arg in args:
for k, v in arg.iteritems():
- if content.get(k, None) != v:
+ if k != 'creation_date' and content.get(k, None) != v:
return False
return True
@@ -129,4 +130,4 @@ class MemDb(object):
pods = MemDb()
projects = MemDb()
testcases = MemDb()
-test_results = MemDb()
+results = MemDb()