summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/dashboard/dashboard_utils.py16
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/resources/dashboard_handlers.py15
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/resources/handlers.py6
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py24
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/router/url_mappings.py4
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py6
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/tests/unit/test_dashboard_project.py20
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/tests/unit/test_result.py9
8 files changed, 85 insertions, 15 deletions
diff --git a/utils/test/result_collection_api/opnfv_testapi/dashboard/dashboard_utils.py b/utils/test/result_collection_api/opnfv_testapi/dashboard/dashboard_utils.py
index 090aaa5b4..f331e28cd 100644
--- a/utils/test/result_collection_api/opnfv_testapi/dashboard/dashboard_utils.py
+++ b/utils/test/result_collection_api/opnfv_testapi/dashboard/dashboard_utils.py
@@ -67,6 +67,22 @@ def get_dashboard_cases():
return modules
+def get_dashboard_projects():
+ # Retrieve all the projects that could provide
+ # Dashboard ready graphs
+ # look in the releng repo
+ # search all the project2Dashboard.py files
+ # we assume that dashboard processing of project <Project>
+ # is performed in the <Project>2Dashboard.py file
+ projects = []
+ cp = re.compile('opnfv_testapi\.dashboard\.(.+?)2Dashboard')
+ for module in sys.modules:
+ project = re.findall(cp, module)
+ if project:
+ projects.extend(project)
+ return projects
+
+
def get_dashboard_result(project, case, results=None):
# get the dashboard ready results
# paramters are:
diff --git a/utils/test/result_collection_api/opnfv_testapi/resources/dashboard_handlers.py b/utils/test/result_collection_api/opnfv_testapi/resources/dashboard_handlers.py
index 84e7bc1b0..303e8d164 100644
--- a/utils/test/result_collection_api/opnfv_testapi/resources/dashboard_handlers.py
+++ b/utils/test/result_collection_api/opnfv_testapi/resources/dashboard_handlers.py
@@ -11,8 +11,8 @@ from tornado.web import HTTPError
from opnfv_testapi.common.constants import HTTP_NOT_FOUND
from opnfv_testapi.dashboard.dashboard_utils import \
- check_dashboard_ready_project, \
- check_dashboard_ready_case, get_dashboard_result
+ check_dashboard_ready_project, check_dashboard_ready_case, \
+ get_dashboard_result, get_dashboard_projects
from opnfv_testapi.resources.result_handlers import GenericResultHandler
from opnfv_testapi.resources.result_models import TestResult
from opnfv_testapi.tornado_swagger import swagger
@@ -107,3 +107,14 @@ class DashboardHandler(GenericDashboardHandler):
return get_dashboard_result(project, case, res)
self._list(self.set_query(), get_result, project_arg, case_arg)
+
+
+class DashboardProjectsHandler(GenericDashboardHandler):
+ @swagger.operation(nickname='list')
+ def get(self):
+ """
+ @description: Retrieve dashboard ready project(s)
+ @rtype: L{list}
+ @return 200: return all dashboard ready project(s)
+ """
+ self.finish_request(get_dashboard_projects())
diff --git a/utils/test/result_collection_api/opnfv_testapi/resources/handlers.py b/utils/test/result_collection_api/opnfv_testapi/resources/handlers.py
index 3d39502db..df920c48f 100644
--- a/utils/test/result_collection_api/opnfv_testapi/resources/handlers.py
+++ b/utils/test/result_collection_api/opnfv_testapi/resources/handlers.py
@@ -106,11 +106,15 @@ class GenericApiHandler(RequestHandler):
@asynchronous
@gen.coroutine
- def _list(self, query=None, res_op=None, *args):
+ def _list(self, query=None, res_op=None, *args, **kwargs):
if query is None:
query = {}
data = []
cursor = self._eval_db(self.table, 'find', query)
+ if 'sort' in kwargs:
+ cursor = cursor.sort(kwargs.get('sort'))
+ if 'last' in kwargs:
+ cursor = cursor.limit(kwargs.get('last'))
while (yield cursor.fetch_next):
data.append(self.format_data(cursor.next_object()))
if res_op is None:
diff --git a/utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py b/utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py
index 473a38d06..44834fd63 100644
--- a/utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py
+++ b/utils/test/result_collection_api/opnfv_testapi/resources/result_handlers.py
@@ -25,6 +25,13 @@ class GenericResultHandler(GenericApiHandler):
self.table = self.db_results
self.table_cls = TestResult
+ def get_int(self, key, value):
+ try:
+ value = int(value)
+ except:
+ raise HTTPError(HTTP_BAD_REQUEST, '{} must be int', key)
+ return value
+
def set_query(self):
query = dict()
for k in self.request.query_arguments.keys():
@@ -32,17 +39,14 @@ class GenericResultHandler(GenericApiHandler):
if k == 'project' or k == 'pod' or k == 'case':
query[k + '_name'] = v
elif k == 'period':
- try:
- v = int(v)
- except:
- raise HTTPError(HTTP_BAD_REQUEST, 'period must be int')
+ v = self.get_int(k, v)
if v > 0:
period = datetime.now() - timedelta(days=v)
obj = {"$gte": str(period)}
query['start_date'] = obj
elif k == 'trust_indicator':
query[k] = float(v)
- else:
+ elif k != 'last':
query[k] = v
return query
@@ -108,12 +112,20 @@ class ResultsCLHandler(GenericResultHandler):
@type period: L{string}
@in period: query
@required period: False
+ @param last: last days
+ @type last: L{string}
+ @in last: query
+ @required last: False
@param trust_indicator: must be int/long/float
@type trust_indicator: L{string}
@in trust_indicator: query
@required trust_indicator: False
"""
- self._list(self.set_query())
+ last = self.get_query_argument('last', 0)
+ if last is not None:
+ last = self.get_int('last', last)
+
+ self._list(self.set_query(), sort=[{'start_date', -1}], last=last)
@swagger.operation(nickname="create")
def post(self):
diff --git a/utils/test/result_collection_api/opnfv_testapi/router/url_mappings.py b/utils/test/result_collection_api/opnfv_testapi/router/url_mappings.py
index 874754b91..695c27de1 100644
--- a/utils/test/result_collection_api/opnfv_testapi/router/url_mappings.py
+++ b/utils/test/result_collection_api/opnfv_testapi/router/url_mappings.py
@@ -14,7 +14,8 @@ from opnfv_testapi.resources.project_handlers import ProjectCLHandler, \
ProjectGURHandler
from opnfv_testapi.resources.result_handlers import ResultsCLHandler, \
ResultsGURHandler
-from opnfv_testapi.resources.dashboard_handlers import DashboardHandler
+from opnfv_testapi.resources.dashboard_handlers import DashboardHandler, \
+ DashboardProjectsHandler
mappings = [
@@ -53,4 +54,5 @@ mappings = [
# get /dashboard
# => get the list of project with dashboard ready results
(r"/dashboard/v1/results", DashboardHandler),
+ (r"/dashboard/v1/projects", DashboardProjectsHandler),
]
diff --git a/utils/test/result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py b/utils/test/result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py
index e55696890..9b4d1208c 100644
--- a/utils/test/result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py
+++ b/utils/test/result_collection_api/opnfv_testapi/tests/unit/fake_pymongo.py
@@ -32,6 +32,12 @@ class MemCursor(object):
self.count -= 1
return self.collection.pop()
+ def sort(self, key_or_list, direction=None):
+ return self
+
+ def limit(self, limit):
+ return self
+
class MemDb(object):
diff --git a/utils/test/result_collection_api/opnfv_testapi/tests/unit/test_dashboard_project.py b/utils/test/result_collection_api/opnfv_testapi/tests/unit/test_dashboard_project.py
new file mode 100644
index 000000000..f9d2015be
--- /dev/null
+++ b/utils/test/result_collection_api/opnfv_testapi/tests/unit/test_dashboard_project.py
@@ -0,0 +1,20 @@
+import json
+
+from opnfv_testapi.common.constants import HTTP_OK
+from test_base import TestBase
+
+
+class TestDashboardProjectBase(TestBase):
+ def setUp(self):
+ super(TestDashboardProjectBase, self).setUp()
+ self.basePath = '/dashboard/v1/projects'
+ self.list_res = None
+ self.projects = ['bottlenecks', 'doctor', 'functest',
+ 'promise', 'qtip', 'vsperf', 'yardstick']
+
+
+class TestDashboardProjectGet(TestDashboardProjectBase):
+ def test_list(self):
+ code, body = self.get()
+ self.assertEqual(code, HTTP_OK)
+ self.assertItemsEqual(self.projects, json.loads(body))
diff --git a/utils/test/result_collection_api/opnfv_testapi/tests/unit/test_result.py b/utils/test/result_collection_api/opnfv_testapi/tests/unit/test_result.py
index fc1e9bacd..5a5dd3852 100644
--- a/utils/test/result_collection_api/opnfv_testapi/tests/unit/test_result.py
+++ b/utils/test/result_collection_api/opnfv_testapi/tests/unit/test_result.py
@@ -7,16 +7,15 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import unittest
-import copy
-from test_base import TestBase
+from opnfv_testapi.common.constants import HTTP_OK, HTTP_BAD_REQUEST, \
+ HTTP_NOT_FOUND
from opnfv_testapi.resources.pod_models import PodCreateRequest
from opnfv_testapi.resources.project_models import ProjectCreateRequest
-from opnfv_testapi.resources.testcase_models import TestcaseCreateRequest
from opnfv_testapi.resources.result_models import ResultCreateRequest, \
TestResult, TestResults
-from opnfv_testapi.common.constants import HTTP_OK, HTTP_BAD_REQUEST, \
- HTTP_NOT_FOUND
+from opnfv_testapi.resources.testcase_models import TestcaseCreateRequest
+from test_base import TestBase
class Details(object):