summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi/common/check.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/common/check.py')
-rw-r--r--utils/test/testapi/opnfv_testapi/common/check.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/utils/test/testapi/opnfv_testapi/common/check.py b/utils/test/testapi/opnfv_testapi/common/check.py
index e80b1c6b7..667578fed 100644
--- a/utils/test/testapi/opnfv_testapi/common/check.py
+++ b/utils/test/testapi/opnfv_testapi/common/check.py
@@ -14,13 +14,14 @@ from tornado import gen
from opnfv_testapi.common import constants
from opnfv_testapi.common import message
from opnfv_testapi.common import raises
+from opnfv_testapi.common.config import CONF
from opnfv_testapi.db import api as dbapi
def is_authorized(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
- if self.table in ['pods']:
+ if CONF.api_authenticate and self.table in ['pods']:
testapi_id = self.get_secure_cookie(constants.TESTAPI_ID)
if not testapi_id:
raises.Unauthorized(message.not_login())
@@ -102,6 +103,19 @@ def carriers_exist(xstep):
return wrap
+def values_check(xstep):
+ @functools.wraps(xstep)
+ def wrap(self, *args, **kwargs):
+ checks = kwargs.pop('values_check', {})
+ if checks:
+ for field, check, options in checks:
+ if not check(field, options):
+ raises.BadRequest(message.invalid_value(field, options))
+ ret = yield gen.coroutine(xstep)(self, *args, **kwargs)
+ raise gen.Return(ret)
+ return wrap
+
+
def new_not_exists(xstep):
@functools.wraps(xstep)
def wrap(self, *args, **kwargs):