Merge "allow authentication to be disabled"
authorSerena Feng <feng.xiaowei@zte.com.cn>
Mon, 23 Oct 2017 01:27:12 +0000 (01:27 +0000)
committerGerrit Code Review <gerrit@opnfv.org>
Mon, 23 Oct 2017 01:27:12 +0000 (01:27 +0000)
1  2 
utils/test/testapi/opnfv_testapi/common/check.py

@@@ -14,13 -14,14 +14,14 @@@ from tornado import ge
  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,19 -103,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):