From c0de44528cb8fdfb7d29158909a589db3628d889 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Fri, 20 Oct 2017 15:21:59 +0800 Subject: criteria field must be 'PASS/FAIL' criteria must be fix with 'PASS/FAIL', case insensitive or else, BADREQUEST exception will be raises JIRA: RELENG-327 Change-Id: Ic648b9d38937fc63924e42cfdf5345cdaa32e1ed Signed-off-by: SerenaFeng --- utils/test/testapi/opnfv_testapi/common/check.py | 13 +++++++++++++ utils/test/testapi/opnfv_testapi/common/message.py | 4 ++++ 2 files changed, 17 insertions(+) (limited to 'utils/test/testapi/opnfv_testapi/common') diff --git a/utils/test/testapi/opnfv_testapi/common/check.py b/utils/test/testapi/opnfv_testapi/common/check.py index e80b1c6b7..1dff37a67 100644 --- a/utils/test/testapi/opnfv_testapi/common/check.py +++ b/utils/test/testapi/opnfv_testapi/common/check.py @@ -102,6 +102,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): diff --git a/utils/test/testapi/opnfv_testapi/common/message.py b/utils/test/testapi/opnfv_testapi/common/message.py index 8b5c3fb7a..3e14f7258 100644 --- a/utils/test/testapi/opnfv_testapi/common/message.py +++ b/utils/test/testapi/opnfv_testapi/common/message.py @@ -26,6 +26,10 @@ def missing(name): return '{} Missing'.format(name) +def invalid_value(name, options): + return '{} must be in {}'.format(name, options) + + def exist(key, value): return '{} [{}] {}'.format(key, value, exist_base) -- cgit 1.2.3-korg