X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Ftest%2Ftestapi%2Fopnfv_testapi%2Fcommon%2Fcheck.py;h=24ba876a9eb90b0e658afcb550c12b03c36399ad;hb=c839d60298dcc73233a16a36ffc00c1bcbcee6b4;hp=4d9902cd06433b2dc24c9d08d72fb791dd25b0a7;hpb=9620b4676471e8cd21890776f8573112cdd16282;p=releng.git diff --git a/utils/test/testapi/opnfv_testapi/common/check.py b/utils/test/testapi/opnfv_testapi/common/check.py index 4d9902cd0..24ba876a9 100644 --- a/utils/test/testapi/opnfv_testapi/common/check.py +++ b/utils/test/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) @@ -61,7 +62,7 @@ def no_body(xstep): def miss_fields(xstep): @functools.wraps(xstep) def wrap(self, *args, **kwargs): - fields = kwargs.get('miss_fields') + fields = kwargs.pop('miss_fields', []) if fields: for miss in fields: miss_data = self.json_args.get(miss) @@ -75,10 +76,10 @@ def miss_fields(xstep): def carriers_exist(xstep): @functools.wraps(xstep) def wrap(self, *args, **kwargs): - carriers = kwargs.get('carriers') + 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) @@ -102,10 +103,10 @@ def new_not_exists(xstep): def updated_one_not_exist(xstep): @functools.wraps(xstep) def wrap(self, data, *args, **kwargs): - db_keys = kwargs.get('db_keys') + 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)