summaryrefslogtreecommitdiffstats
path: root/result_collection_api/opnfv_testapi/tests/unit/test_fake_pymongo.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-06-15 09:49:35 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2016-06-15 16:05:37 +0800
commit95c48ad7ad59486c609c3285c457d0352884e3d7 (patch)
tree2153ff64815a175dd342ad2c713fe4243ea8384a /result_collection_api/opnfv_testapi/tests/unit/test_fake_pymongo.py
parent9b418c0af7968c16cc661448bf7b4b7d5e116ee4 (diff)
support keys start with '$' or contain '.' in testAPI
set check_keys=False in insert and update db fix update and insert stub in fake_pymongo.py add unittest for check_keys in test_fake_pymongo.py JIRA: FUNCTEST-313 Change-Id: I4051ec4a1c70996c87167643f6ea19993f5b0811 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'result_collection_api/opnfv_testapi/tests/unit/test_fake_pymongo.py')
-rw-r--r--result_collection_api/opnfv_testapi/tests/unit/test_fake_pymongo.py65
1 files changed, 55 insertions, 10 deletions
diff --git a/result_collection_api/opnfv_testapi/tests/unit/test_fake_pymongo.py b/result_collection_api/opnfv_testapi/tests/unit/test_fake_pymongo.py
index 9bc311c..27382f0 100644
--- a/result_collection_api/opnfv_testapi/tests/unit/test_fake_pymongo.py
+++ b/result_collection_api/opnfv_testapi/tests/unit/test_fake_pymongo.py
@@ -53,25 +53,70 @@ class MyTest(AsyncHTTPTestCase):
user = yield self.db.pods.find_one({'_id': '1'})
self.assertEqual(user.get('name', None), 'new_test1')
+ def test_update_dot_error(self):
+ self._update_assert({'_id': '1', 'name': {'1. name': 'test1'}},
+ 'key 1. name must not contain .')
+
+ def test_update_dot_no_error(self):
+ self._update_assert({'_id': '1', 'name': {'1. name': 'test1'}},
+ None,
+ check_keys=False)
+
+ def test_update_dollar_error(self):
+ self._update_assert({'_id': '1', 'name': {'$name': 'test1'}},
+ 'key $name must not start with $')
+
+ def test_update_dollar_no_error(self):
+ self._update_assert({'_id': '1', 'name': {'$name': 'test1'}},
+ None,
+ check_keys=False)
+
@gen_test
def test_remove(self):
yield self.db.pods.remove({'_id': '1'})
user = yield self.db.pods.find_one({'_id': '1'})
self.assertIsNone(user)
- @gen_test
- def test_insert_check_keys(self):
- yield self.db.pods.insert({'_id': '1', 'name': 'test1'},
- check_keys=False)
- cursor = self.db.pods.find({'_id': '1'})
- names = []
- while (yield cursor.fetch_next):
- ob = cursor.next_object()
- names.append(ob.get('name'))
- self.assertItemsEqual(names, ['test1', 'test1'])
+ def test_insert_dot_error(self):
+ self._insert_assert({'_id': '1', '2. name': 'test1'},
+ 'key 2. name must not contain .')
+
+ def test_insert_dot_no_error(self):
+ self._insert_assert({'_id': '1', '2. name': 'test1'},
+ None,
+ check_keys=False)
+
+ def test_insert_dollar_error(self):
+ self._insert_assert({'_id': '1', '$name': 'test1'},
+ 'key $name must not start with $')
+
+ def test_insert_dollar_no_error(self):
+ self._insert_assert({'_id': '1', '$name': 'test1'},
+ None,
+ check_keys=False)
def _clear(self):
self.db.pods.clear()
+ def _update_assert(self, docs, error=None, **kwargs):
+ self._db_assert('update', error, {'_id': '1'}, docs, **kwargs)
+
+ def _insert_assert(self, docs, error=None, **kwargs):
+ self._db_assert('insert', error, docs, **kwargs)
+
+ @gen_test
+ def _db_assert(self, method, error, *args, **kwargs):
+ name_error = None
+ try:
+ yield self._eval_pods_db(method, *args, **kwargs)
+ except NameError as err:
+ name_error = err.args[0]
+ finally:
+ self.assertEqual(name_error, error)
+
+ def _eval_pods_db(self, method, *args, **kwargs):
+ return eval('self.db.pods.%s(*args, **kwargs)' % method)
+
+
if __name__ == '__main__':
unittest.main()