From 62b6c74a33da6a12f4a743ef6fe77cf901245181 Mon Sep 17 00:00:00 2001 From: Paul Van Eck Date: Mon, 19 Jan 2015 13:23:38 -0800 Subject: [PATCH] Add GET test results and add report page output A GET handler was added for retrieving test results with URL of the form: /v1/results/{test_id}. The report page can now be used to view results. It should be accessed with URL of the form: /output.html?test_id={test_id}. This is just to keep it simple for now. Change-Id: I28e9ebf74cc7a6dad360232840b49c6aae27dab0 --- defcore/js/helpers.js | 12 ++++++++++++ refstack/api/config.py | 9 ++++++--- refstack/api/controllers/v1.py | 17 +++++++++++++++++ refstack/backend.py | 18 ++++++++++++++++++ refstack/static/js/refstack.js | 18 +++++++++--------- refstack/templates/output.html | 7 ++++--- specs/approved/api-v1.md | 19 +++++++++++++++++++ 7 files changed, 85 insertions(+), 15 deletions(-) diff --git a/defcore/js/helpers.js b/defcore/js/helpers.js index f95a5b1f..23dbd872 100644 --- a/defcore/js/helpers.js +++ b/defcore/js/helpers.js @@ -29,6 +29,18 @@ var capitaliseFirstLetter = function (string) { return string.charAt(0).toUpperCase() + string.slice(1); }; +// Get the value of a GET variable in the URL. +var getUrlParam = function(variable) { + var searchString = window.location.search.substring(1); + var searchVariables = searchString.split('&'); + for (var i = 0; i < searchVariables.length; i++) { + var getVar = searchVariables[i].split('='); + if (getVar[0] == variable) { + return getVar[1]; + } + } +} + // Function searches for test with specified test_id on github and opens result in new window var get_code_url = function (test_id) { var id = test_id.split('/').join('.'), diff --git a/refstack/api/config.py b/refstack/api/config.py index 801a5ac0..88324522 100644 --- a/refstack/api/config.py +++ b/refstack/api/config.py @@ -26,7 +26,8 @@ pecan.conf # Server Specific Configurations server = { 'port': '8000', - 'host': '0.0.0.0' + 'host': '0.0.0.0', + 'protocol': 'http' } # Pecan Application Configurations @@ -34,8 +35,10 @@ app = { 'root': 'refstack.api.controllers.root.RootController', 'modules': ['refstack.api'], 'db_url': 'mysql://root:r00t@127.0.0.1/refstack', - 'static_root': '%(confdir)s/public', - 'template_path': '%(confdir)s/${package}/templates', + 'static_root': '%(confdir)s/../static', + 'template_path': '%(confdir)s/../templates', + # The 'debug' option should be false in production servers, but needs to be + # true in development in order to allow the static_root option to work. 'debug': False, 'errors': { '404': '/error/404', diff --git a/refstack/api/controllers/v1.py b/refstack/api/controllers/v1.py index a18a2d54..eba5ee65 100644 --- a/refstack/api/controllers/v1.py +++ b/refstack/api/controllers/v1.py @@ -31,6 +31,23 @@ class ResultsController(rest.RestController): """GET handler.""" return {'Result': 'Ok'} + @pecan.expose("json") + def get_one(self, test_id): + """Return test results in JSON format. + + :param test_id: ID of the test to get the JSON for. + """ + test_info = pecan.request.backend.get_test(test_id) + if not test_info: + pecan.abort(404) + + test_list = pecan.request.backend.get_test_results(test_id) + test_name_list = [test_dict[0] for test_dict in test_list] + return {"cpid": test_info.cpid, + "created_at": test_info.created_at, + "duration_seconds": test_info.duration_seconds, + "results": test_name_list} + @pecan.expose(template='json') def post(self, ): """POST handler.""" diff --git a/refstack/backend.py b/refstack/backend.py index 87d49b63..dc8cb627 100644 --- a/refstack/backend.py +++ b/refstack/backend.py @@ -68,3 +68,21 @@ class LocalBackend(object): session.add(test) session.commit() return test_id + + def get_test(self, test_id): + """Get test information from the database. + + :param test_id: The ID of the test. + """ + test_info = self.db_session.query(models.Test).\ + filter_by(id=test_id).first() + return test_info + + def get_test_results(self, test_id): + """Get all passed tempest tests for a particular test. + + :param test_id: The ID of the test. + """ + results = self.db_session.query(models.TestResults.name).filter_by( + test_id=test_id).all() + return results diff --git a/refstack/static/js/refstack.js b/refstack/static/js/refstack.js index 9eb76ec4..f955cba1 100644 --- a/refstack/static/js/refstack.js +++ b/refstack/static/js/refstack.js @@ -276,7 +276,7 @@ var render_defcore_report_page = function () { schema = '', schema_selector = $('select#schema_selector'); - if (window.result_source === '{{result_source}}') { + if (!window.result_source) { window.result_source = 'sample_test_result.json'; } if (schema_selector.length === 0) { @@ -286,10 +286,10 @@ var render_defcore_report_page = function () { } console.log(schema); $.when( - $.get('mustache/report_base.mst', undefined, undefined, 'html'), - $.get('mustache/single_header.mst', undefined, undefined, 'html'), - $.get('mustache/single_capabilities_details.mst', undefined, undefined, 'html'), - $.get('capabilities/' + schema, undefined, undefined, 'json'), + $.get('/mustache/report_base.mst', undefined, undefined, 'html'), + $.get('/mustache/single_header.mst', undefined, undefined, 'html'), + $.get('/mustache/single_capabilities_details.mst', undefined, undefined, 'html'), + $.get('/capabilities/' + schema, undefined, undefined, 'json'), $.get(window.result_source, undefined, undefined, 'json') ).done(function (base_template, header_template, caps_template, schema, test_result) { var caps_list = window.build_caps_list(schema[0], filters), @@ -320,10 +320,10 @@ var render_defcore_diff_report_page = function () { schema = schema_selector[0].value; } $.when( - $.get('mustache/report_base.mst', undefined, undefined, 'html'), - $.get('mustache/diff_header.mst', undefined, undefined, 'html'), - $.get('mustache/diff_capabilities_details.mst', undefined, undefined, 'html'), - $.get('capabilities/' + schema, undefined, undefined, 'json'), + $.get('/mustache/report_base.mst', undefined, undefined, 'html'), + $.get('/mustache/diff_header.mst', undefined, undefined, 'html'), + $.get('/mustache/diff_capabilities_details.mst', undefined, undefined, 'html'), + $.get('/capabilities/' + schema, undefined, undefined, 'json'), $.get(window.result_source, undefined, undefined, 'json'), $.get(window.prev_result_source, undefined, undefined, 'json') ).done(function (base_template, header_template, caps_template, schema, diff --git a/refstack/templates/output.html b/refstack/templates/output.html index c1c49206..3d37ba87 100644 --- a/refstack/templates/output.html +++ b/refstack/templates/output.html @@ -11,12 +11,13 @@ -