summaryrefslogtreecommitdiffstats
path: root/utils/test/result_collection_api/tests/unit/fake_pymongo.py
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2016-05-25 09:50:08 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-05-25 09:50:08 +0000
commitf41cc29366b2660ef7d9cb85be6b04b737526f45 (patch)
treeb236264b26a1a037c59635227b5cce9fcd0f00e3 /utils/test/result_collection_api/tests/unit/fake_pymongo.py
parent345abdddd5d263b53e3104c1cb9f657515521f77 (diff)
parentf4f8328db358131963b3fa9e81677bf570b8d0aa (diff)
Merge "add test result/dashboard related unittests in testAPI and refactor its response"
Diffstat (limited to 'utils/test/result_collection_api/tests/unit/fake_pymongo.py')
-rw-r--r--utils/test/result_collection_api/tests/unit/fake_pymongo.py15
1 files changed, 8 insertions, 7 deletions
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 1521bfa35..40eb164db 100644
--- a/utils/test/result_collection_api/tests/unit/fake_pymongo.py
+++ b/utils/test/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()