diff options
author | 2016-05-25 09:50:08 +0000 | |
---|---|---|
committer | 2016-05-25 09:50:08 +0000 | |
commit | f204fed9d8519f994b085a1139f036bc40fcddbc (patch) | |
tree | 9e90094bbb1760363d666b8ad1c52b99ad730fab /result_collection_api/tests/unit/fake_pymongo.py | |
parent | 02825c3c21fc5c46d4952c1410f96e3836b50b61 (diff) | |
parent | 0c898e11323cf4e5baabecb55d8be2ff2268690d (diff) |
Merge "add test result/dashboard related unittests in testAPI and refactor its response"
Diffstat (limited to 'result_collection_api/tests/unit/fake_pymongo.py')
-rw-r--r-- | result_collection_api/tests/unit/fake_pymongo.py | 15 |
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() |