summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--utils/test/testapi/opnfv_testapi/common/check.py13
-rw-r--r--utils/test/testapi/opnfv_testapi/common/message.py4
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/handlers.py1
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/result_handlers.py8
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py9
5 files changed, 33 insertions, 2 deletions
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)
diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py
index 8e5dab235..6c7a819c9 100644
--- a/utils/test/testapi/opnfv_testapi/resources/handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py
@@ -79,6 +79,7 @@ class GenericApiHandler(web.RequestHandler):
@check.valid_token
@check.no_body
@check.miss_fields
+ @check.values_check
@check.carriers_exist
@check.new_not_exists
def _create(self, **kwargs):
diff --git a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
index e202f5c2c..a25852856 100644
--- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py
@@ -215,12 +215,18 @@ class ResultsCLHandler(GenericResultHandler):
return {'project_name': self.json_args.get('project_name'),
'name': self.json_args.get('case_name')}
+ def options_check(field, options):
+ return self.json_args.get(field).upper() in options
+
miss_fields = ['pod_name', 'project_name', 'case_name']
carriers = [('pods', pod_query),
('projects', project_query),
('testcases', testcase_query)]
+ values_check = [('criteria', options_check, ['PASS', 'FAIL'])]
- self._create(miss_fields=miss_fields, carriers=carriers)
+ self._create(miss_fields=miss_fields,
+ carriers=carriers,
+ values_check=values_check)
class ResultsUploadHandler(ResultsCLHandler):
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py
index 1df31f36c..6c1a07a91 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/resources/test_result.py
@@ -62,7 +62,7 @@ class TestResultBase(base.TestBase):
self.version = 'C'
self.build_tag = 'v3.0'
self.scenario = 'odl-l2'
- self.criteria = 'passed'
+ self.criteria = 'PASS'
self.trust_indicator = result_models.TI(0.7)
self.start_date = str(datetime.now())
self.stop_date = str(datetime.now() + timedelta(minutes=1))
@@ -170,6 +170,13 @@ class TestResultCreate(TestResultBase):
req.case_name = None
return req
+ @executor.create(httplib.BAD_REQUEST,
+ message.invalid_value('criteria', ['PASS', 'FAIL']))
+ def test_invalid_criteria(self):
+ req = self.req_d
+ req.criteria = 'invalid'
+ return req
+
@executor.create(httplib.FORBIDDEN, message.not_found_base)
def test_noPod(self):
req = self.req_d