summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--result_collection_api/resources/handlers.py4
-rw-r--r--result_collection_api/result_collection_api.py25
-rw-r--r--result_collection_api/tests/unit/test_base.py25
-rw-r--r--result_collection_api/tests/unit/test_dashboard.py6
-rw-r--r--result_collection_api/tests/unit/test_pod.py12
-rw-r--r--result_collection_api/tests/unit/test_project.py2
-rw-r--r--result_collection_api/tests/unit/test_result.py10
-rw-r--r--result_collection_api/tests/unit/test_testcase.py4
-rw-r--r--result_collection_api/tests/unit/test_version.py19
9 files changed, 57 insertions, 50 deletions
diff --git a/result_collection_api/resources/handlers.py b/result_collection_api/resources/handlers.py
index 8cc68e9..4353343 100644
--- a/result_collection_api/resources/handlers.py
+++ b/result_collection_api/resources/handlers.py
@@ -73,10 +73,10 @@ class GenericApiHandler(RequestHandler):
return CreateResponse(href=href).format()
-class VersionHandler(RequestHandler):
+class VersionHandler(GenericApiHandler):
""" Display a message for the API version """
def get(self):
- self.write("Collection of test result API, v1")
+ self.finish_request([{'v1': 'basics'}])
class PodHandler(GenericApiHandler):
diff --git a/result_collection_api/result_collection_api.py b/result_collection_api/result_collection_api.py
index 704d607..97aa58c 100644
--- a/result_collection_api/result_collection_api.py
+++ b/result_collection_api/result_collection_api.py
@@ -54,25 +54,25 @@ def make_app():
return tornado.web.Application(
[
# GET /version => GET API version
- (r"/version", VersionHandler),
+ (r"/versions", VersionHandler),
# few examples:
# GET /pods => Get all pods
# GET /pods/1 => Get details on POD 1
- (r"/pods", PodHandler),
- (r"/pods/([^/]+)", PodHandler),
+ (r"/api/v1/pods", PodHandler),
+ (r"/api/v1/pods/([^/]+)", PodHandler),
# few examples:
# GET /projects
# GET /projects/yardstick
- (r"/projects", ProjectHandler),
- (r"/projects/([^/]+)", ProjectHandler),
+ (r"/api/v1/projects", ProjectHandler),
+ (r"/api/v1/projects/([^/]+)", ProjectHandler),
# few examples
# GET /projects/qtip/cases => Get cases for qtip
#
- (r"/projects/([^/]+)/cases", TestcaseHandler),
- (r"/projects/([^/]+)/cases/([^/]+)", TestcaseHandler),
+ (r"/api/v1/projects/([^/]+)/cases", TestcaseHandler),
+ (r"/api/v1/projects/([^/]+)/cases/([^/]+)", TestcaseHandler),
# (r"/test_cases/([^/]+)", TestCasesHandler),
# new path to avoid a long depth
@@ -81,18 +81,17 @@ def make_app():
# POST /results =>
# Push results with mandatory request payload parameters
# (project, case, and pod)
- (r"/results", TestResultsHandler),
- (r"/results([^/]*)", TestResultsHandler),
- (r"/results/([^/]*)", TestResultsHandler),
+ (r"/api/v1/results", TestResultsHandler),
+ (r"/api/v1/results([^/]*)", TestResultsHandler),
+ (r"/api/v1/results/([^/]*)", TestResultsHandler),
# Method to manage Dashboard ready results
# GET /dashboard?project=functest&case=vPing&pod=opnfv-jump2
# => get results in dasboard ready format
# get /dashboard
# => get the list of project with dashboard ready results
- (r"/dashboard", DashboardHandler),
- (r"/dashboard([^/]*)", DashboardHandler),
- (r"/dashboard/([^/]*)", DashboardHandler),
+ (r"/dashboard/v1/results", DashboardHandler),
+ (r"/dashboard/v1/results([^/]*)", DashboardHandler),
],
db=db,
debug=CONF.api_debug_on,
diff --git a/result_collection_api/tests/unit/test_base.py b/result_collection_api/tests/unit/test_base.py
index a06cba9..99b1de2 100644
--- a/result_collection_api/tests/unit/test_base.py
+++ b/result_collection_api/tests/unit/test_base.py
@@ -25,19 +25,18 @@ class TestBase(AsyncHTTPTestCase):
def get_app(self):
return Application(
[
- (r"/version", VersionHandler),
- (r"/pods", PodHandler),
- (r"/pods/([^/]+)", PodHandler),
- (r"/projects", ProjectHandler),
- (r"/projects/([^/]+)", ProjectHandler),
- (r"/projects/([^/]+)/cases", TestcaseHandler),
- (r"/projects/([^/]+)/cases/([^/]+)", TestcaseHandler),
- (r"/results", TestResultsHandler),
- (r"/results([^/]*)", TestResultsHandler),
- (r"/results/([^/]*)", TestResultsHandler),
- (r"/dashboard", DashboardHandler),
- (r"/dashboard([^/]*)", DashboardHandler),
- (r"/dashboard/([^/]*)", DashboardHandler),
+ (r"/versions", VersionHandler),
+ (r"/api/v1/pods", PodHandler),
+ (r"/api/v1/pods/([^/]+)", PodHandler),
+ (r"/api/v1/projects", ProjectHandler),
+ (r"/api/v1/projects/([^/]+)", ProjectHandler),
+ (r"/api/v1/projects/([^/]+)/cases", TestcaseHandler),
+ (r"/api/v1/projects/([^/]+)/cases/([^/]+)", TestcaseHandler),
+ (r"/api/v1/results", TestResultsHandler),
+ (r"/api/v1/results([^/]*)", TestResultsHandler),
+ (r"/api/v1/results/([^/]*)", TestResultsHandler),
+ (r"/dashboard/v1/results", DashboardHandler),
+ (r"/dashboard/v1/results([^/]*)", DashboardHandler),
],
db=fake_pymongo,
debug=True,
diff --git a/result_collection_api/tests/unit/test_dashboard.py b/result_collection_api/tests/unit/test_dashboard.py
index 1e0d22b..5c3f924 100644
--- a/result_collection_api/tests/unit/test_dashboard.py
+++ b/result_collection_api/tests/unit/test_dashboard.py
@@ -9,9 +9,9 @@ __author__ = '__serena__'
class TestDashboardBase(TestResultBase):
def setUp(self):
super(TestDashboardBase, self).setUp()
- self.basePath = '/dashboard'
- self.create_help('/results', self.req_d)
- self.create_help('/results', self.req_d)
+ self.basePath = '/dashboard/v1/results'
+ self.create_help('/api/v1/results', self.req_d)
+ self.create_help('/api/v1/results', self.req_d)
self.list_res = None
diff --git a/result_collection_api/tests/unit/test_pod.py b/result_collection_api/tests/unit/test_pod.py
index b6adc25..d7f4c3a 100644
--- a/result_collection_api/tests/unit/test_pod.py
+++ b/result_collection_api/tests/unit/test_pod.py
@@ -9,11 +9,12 @@ from common.constants import HTTP_OK, HTTP_BAD_REQUEST, \
class TestPodBase(TestBase):
def setUp(self):
super(TestPodBase, self).setUp()
- self.req_d = PodCreateRequest('zte-1', 'virtual', 'zte pod 1','ci-pod')
+ self.req_d = PodCreateRequest('zte-1', 'virtual',
+ 'zte pod 1', 'ci-pod')
self.req_e = PodCreateRequest('zte-2', 'metal', 'zte pod 2')
self.get_res = Pod
self.list_res = Pods
- self.basePath = '/pods'
+ self.basePath = '/api/v1/pods'
def assert_get_body(self, pod, req=None):
if not req:
@@ -21,7 +22,7 @@ class TestPodBase(TestBase):
self.assertEqual(pod.name, req.name)
self.assertEqual(pod.mode, req.mode)
self.assertEqual(pod.details, req.details)
- self.assertEqual(pod.role, req.role)
+ self.assertEqual(pod.role, req.role)
self.assertIsNotNone(pod.creation_date)
self.assertIsNotNone(pod._id)
@@ -42,11 +43,6 @@ class TestPodCreate(TestPodBase):
self.assertEqual(code, HTTP_FORBIDDEN)
self.assertIn('already exists', body)
- def _assertMeta(self, meta, success):
- self.assertEqual(meta.success, success)
- if success:
- self.assertEqual(meta.uri, '/pods/{}'.format(self.req_d.name))
-
class TestPodGet(TestPodBase):
def test_notExist(self):
diff --git a/result_collection_api/tests/unit/test_project.py b/result_collection_api/tests/unit/test_project.py
index 6ce21db..c380780 100644
--- a/result_collection_api/tests/unit/test_project.py
+++ b/result_collection_api/tests/unit/test_project.py
@@ -14,7 +14,7 @@ class TestProjectBase(TestBase):
self.get_res = Project
self.list_res = Projects
self.update_res = Project
- self.basePath = '/projects'
+ self.basePath = '/api/v1/projects'
def assert_body(self, project, req=None):
if not req:
diff --git a/result_collection_api/tests/unit/test_result.py b/result_collection_api/tests/unit/test_result.py
index 9e27e3c..9c5093e 100644
--- a/result_collection_api/tests/unit/test_result.py
+++ b/result_collection_api/tests/unit/test_result.py
@@ -67,15 +67,17 @@ class TestResultBase(TestBase):
trust_indicator=self.trust_indicator)
self.get_res = TestResult
self.list_res = TestResults
- self.basePath = '/results'
+ self.basePath = '/api/v1/results'
self.req_pod = PodCreateRequest(self.pod, 'metal', 'zte pod 1')
self.req_project = ProjectCreateRequest(self.project, 'vping test')
self.req_testcase = TestcaseCreateRequest('/cases/vping',
self.case,
'vping-ssh test')
- self.create_help('/pods', self.req_pod)
- self.create_help('/projects', self.req_project)
- self.create_help('/projects/%s/cases', self.req_testcase, self.project)
+ self.create_help('/api/v1/pods', self.req_pod)
+ self.create_help('/api/v1/projects', self.req_project)
+ self.create_help('/api/v1/projects/%s/cases',
+ self.req_testcase,
+ self.project)
def assert_res(self, code, result):
self.assertEqual(code, HTTP_OK)
diff --git a/result_collection_api/tests/unit/test_testcase.py b/result_collection_api/tests/unit/test_testcase.py
index e44c0b4..712a4e7 100644
--- a/result_collection_api/tests/unit/test_testcase.py
+++ b/result_collection_api/tests/unit/test_testcase.py
@@ -29,7 +29,7 @@ class TestCaseBase(TestBase):
self.get_res = Testcase
self.list_res = Testcases
self.update_res = Testcase
- self.basePath = '/projects/%s/cases'
+ self.basePath = '/api/v1/projects/%s/cases'
self.create_project()
def assert_body(self, case, req=None):
@@ -52,7 +52,7 @@ class TestCaseBase(TestBase):
def create_project(self):
req_p = ProjectCreateRequest('functest', 'vping-ssh test')
- self.create_help('/projects', req_p)
+ self.create_help('/api/v1/projects', req_p)
self.project = req_p.name
def create_d(self):
diff --git a/result_collection_api/tests/unit/test_version.py b/result_collection_api/tests/unit/test_version.py
index 918f2f0..a58cd56 100644
--- a/result_collection_api/tests/unit/test_version.py
+++ b/result_collection_api/tests/unit/test_version.py
@@ -1,3 +1,4 @@
+import json
import unittest
from test_base import TestBase
@@ -5,10 +6,20 @@ from test_base import TestBase
__author__ = 'serena'
-class TestVersion(TestBase):
- def test_get_version(self):
- response = self.fetch('/version')
- self.assertEqual(response.code, 200)
+class TestVersionbBase(TestBase):
+ def setUp(self):
+ super(TestVersionbBase, self).setUp()
+ self.list_res = None
+ self.basePath = '/versions'
+
+
+class TestVersion(TestVersionbBase):
+ def test_success(self):
+ code, body = self.get()
+ self.assertEqual(200, code)
+ json_body = json.loads(body)
+ self.assertEqual(len(json_body), 1)
+ self.assertEqual('basics', json_body[0].get('v1'))
if __name__ == '__main__':
unittest.main()