diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-07-14 19:27:44 +0800 |
---|---|---|
committer | Serena Feng <feng.xiaowei@zte.com.cn> | 2017-07-21 13:34:38 +0000 |
commit | 822cd5c32c9a129aa8aad9952f25a37123c96733 (patch) | |
tree | 6f4edb8aa5d130a7812b15c70f1186f0138fc560 /utils/test/testapi/opnfv_testapi/db | |
parent | cbcabf6643e68c019b407c95b1526e77337f7697 (diff) |
separate db methods from handler.py
db methods are mingled in handler, which is not well structured
Change-Id: I639679d3fc05a0b6528158186b8bf89e0cd10596
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/db')
-rw-r--r-- | utils/test/testapi/opnfv_testapi/db/__init__.py | 0 | ||||
-rw-r--r-- | utils/test/testapi/opnfv_testapi/db/api.py | 38 |
2 files changed, 38 insertions, 0 deletions
diff --git a/utils/test/testapi/opnfv_testapi/db/__init__.py b/utils/test/testapi/opnfv_testapi/db/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/utils/test/testapi/opnfv_testapi/db/__init__.py diff --git a/utils/test/testapi/opnfv_testapi/db/api.py b/utils/test/testapi/opnfv_testapi/db/api.py new file mode 100644 index 000000000..c057480d4 --- /dev/null +++ b/utils/test/testapi/opnfv_testapi/db/api.py @@ -0,0 +1,38 @@ +import motor + +from opnfv_testapi.common.config import CONF + +DB = motor.MotorClient(CONF.mongo_url)[CONF.mongo_dbname] + + +def db_update(collection, query, update_req): + return _eval_db(collection, 'update', query, update_req, check_keys=False) + + +def db_delete(collection, query): + return _eval_db(collection, 'remove', query) + + +def db_aggregate(collection, pipelines): + return _eval_db(collection, 'aggregate', pipelines, allowDiskUse=True) + + +def db_list(collection, query): + return _eval_db(collection, 'find', query) + + +def db_save(collection, data): + return _eval_db(collection, 'insert', data, check_keys=False) + + +def db_find_one(collection, query): + return _eval_db(collection, 'find_one', query) + + +def _eval_db(collection, method, *args, **kwargs): + exec_collection = DB.__getattr__(collection) + return exec_collection.__getattribute__(method)(*args, **kwargs) + + +def _eval_db_find_one(query, table=None): + return _eval_db(table, 'find_one', query) |