From f4f8328db358131963b3fa9e81677bf570b8d0aa Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Mon, 23 May 2016 18:34:19 +0800 Subject: 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 --- .../test/result_collection_api/tests/unit/fake_pymongo.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'utils/test/result_collection_api/tests/unit/fake_pymongo.py') 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() -- cgit 1.2.3-korg