summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/common
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-07-14 19:27:44 +0800
committerSerena Feng <feng.xiaowei@zte.com.cn>2017-07-21 13:34:38 +0000
commit08014f8dea875cdfaf4afbaa80fb26073708327a (patch)
treecbbf7d6f02d52179453d44cc49ccb48fa32adf67 /testapi/opnfv_testapi/common
parentc0c8260d5b59bc697573c862cc292c1e5f95d1e9 (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 'testapi/opnfv_testapi/common')
-rw-r--r--testapi/opnfv_testapi/common/check.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py
index 67e8fbd..24ba876 100644
--- a/testapi/opnfv_testapi/common/check.py
+++ b/testapi/opnfv_testapi/common/check.py
@@ -13,6 +13,7 @@ from tornado import web
from opnfv_testapi.common import message
from opnfv_testapi.common import raises
+from opnfv_testapi.db import api as dbapi
def authenticate(method):
@@ -26,7 +27,7 @@ def authenticate(method):
except KeyError:
raises.Unauthorized(message.unauthorized())
query = {'access_token': token}
- check = yield self._eval_db_find_one(query, 'tokens')
+ check = yield dbapi.db_find_one('tokens', query)
if not check:
raises.Forbidden(message.invalid_token())
ret = yield gen.coroutine(method)(self, *args, **kwargs)
@@ -38,7 +39,7 @@ def not_exist(xstep):
@functools.wraps(xstep)
def wrap(self, *args, **kwargs):
query = kwargs.get('query')
- data = yield self._eval_db_find_one(query)
+ data = yield dbapi.db_find_one(self.table, query)
if not data:
raises.NotFound(message.not_found(self.table, query))
ret = yield gen.coroutine(xstep)(self, data, *args, **kwargs)
@@ -78,7 +79,7 @@ def carriers_exist(xstep):
carriers = kwargs.pop('carriers', {})
if carriers:
for table, query in carriers:
- exist = yield self._eval_db_find_one(query(), table)
+ exist = yield dbapi.db_find_one(table, query())
if not exist:
raises.Forbidden(message.not_found(table, query()))
ret = yield gen.coroutine(xstep)(self, *args, **kwargs)
@@ -91,7 +92,7 @@ def new_not_exists(xstep):
def wrap(self, *args, **kwargs):
query = kwargs.get('query')
if query:
- to_data = yield self._eval_db_find_one(query())
+ to_data = yield dbapi.db_find_one(self.table, query())
if to_data:
raises.Forbidden(message.exist(self.table, query()))
ret = yield gen.coroutine(xstep)(self, *args, **kwargs)
@@ -105,7 +106,7 @@ def updated_one_not_exist(xstep):
db_keys = kwargs.pop('db_keys', [])
query = self._update_query(db_keys, data)
if query:
- to_data = yield self._eval_db_find_one(query)
+ to_data = yield dbapi.db_find_one(self.table, query)
if to_data:
raises.Forbidden(message.exist(self.table, query))
ret = yield gen.coroutine(xstep)(self, data, *args, **kwargs)