diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2016-05-25 22:56:11 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2016-05-26 14:18:08 +0800 |
commit | 119faa49c41ab093aaa9767e906b448198e5c6c4 (patch) | |
tree | a0733809af20e1dbf35d1ebcf851f2973603b4c2 /utils/test | |
parent | f41cc29366b2660ef7d9cb85be6b04b737526f45 (diff) |
attach version number to url in testAPI
version - /versions
api - /api/v1/pods(projects/results)
dashboard - /dashboard/v1/results
I tried to make the code smart, but in vain, sad......
JIRA: FUNCTEST-261
Change-Id: I3e9e3ad7180a6c6349fd743e24eafea07bdefd1d
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test')
9 files changed, 57 insertions, 50 deletions
diff --git a/utils/test/result_collection_api/resources/handlers.py b/utils/test/result_collection_api/resources/handlers.py index 268d19aba..6747767ea 100644 --- a/utils/test/result_collection_api/resources/handlers.py +++ b/utils/test/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/utils/test/result_collection_api/result_collection_api.py b/utils/test/result_collection_api/result_collection_api.py index 704d6075c..97aa58c77 100644 --- a/utils/test/result_collection_api/result_collection_api.py +++ b/utils/test/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/utils/test/result_collection_api/tests/unit/test_base.py b/utils/test/result_collection_api/tests/unit/test_base.py index a06cba9fb..99b1de286 100644 --- a/utils/test/result_collection_api/tests/unit/test_base.py +++ b/utils/test/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/utils/test/result_collection_api/tests/unit/test_dashboard.py b/utils/test/result_collection_api/tests/unit/test_dashboard.py index 1e0d22b91..5c3f92492 100644 --- a/utils/test/result_collection_api/tests/unit/test_dashboard.py +++ b/utils/test/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/utils/test/result_collection_api/tests/unit/test_pod.py b/utils/test/result_collection_api/tests/unit/test_pod.py index b6adc25ec..d7f4c3a63 100644 --- a/utils/test/result_collection_api/tests/unit/test_pod.py +++ b/utils/test/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/utils/test/result_collection_api/tests/unit/test_project.py b/utils/test/result_collection_api/tests/unit/test_project.py index 6ce21db24..c38078098 100644 --- a/utils/test/result_collection_api/tests/unit/test_project.py +++ b/utils/test/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/utils/test/result_collection_api/tests/unit/test_result.py b/utils/test/result_collection_api/tests/unit/test_result.py index 2ea1b6c11..40b7dacf1 100644 --- a/utils/test/result_collection_api/tests/unit/test_result.py +++ b/utils/test/result_collection_api/tests/unit/test_result.py @@ -64,15 +64,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/utils/test/result_collection_api/tests/unit/test_testcase.py b/utils/test/result_collection_api/tests/unit/test_testcase.py index e44c0b4b6..712a4e78c 100644 --- a/utils/test/result_collection_api/tests/unit/test_testcase.py +++ b/utils/test/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/utils/test/result_collection_api/tests/unit/test_version.py b/utils/test/result_collection_api/tests/unit/test_version.py index 918f2f052..a58cd5629 100644 --- a/utils/test/result_collection_api/tests/unit/test_version.py +++ b/utils/test/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() |