From 78677f8e9aaeb03be0a39685caa4204632e8d14b Mon Sep 17 00:00:00 2001 From: Alexandra Morozova Date: Fri, 19 Jun 2015 13:03:45 +0200 Subject: [PATCH] Fix for wrong JSON format on OSTF tab - iterating over testsets, not tests Closes-bug: #1466468 Change-Id: Ic19c489833b3ad8c5c21e7445997bbe3e30a8cff --- .../cluster_page_tabs/healthcheck_tab.jsx | 65 ++++++++++--------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/nailgun/static/views/cluster_page_tabs/healthcheck_tab.jsx b/nailgun/static/views/cluster_page_tabs/healthcheck_tab.jsx index 637577642e..a21853ad99 100644 --- a/nailgun/static/views/cluster_page_tabs/healthcheck_tab.jsx +++ b/nailgun/static/views/cluster_page_tabs/healthcheck_tab.jsx @@ -141,38 +141,45 @@ function($, _, i18n, Backbone, React, models, utils, componentMixins, controls) runTests: function() { var testruns = new models.TestRuns(), oldTestruns = new models.TestRuns(), - selectedTests = this.props.tests.where({checked: true}); + testsetIds = this.props.testsets.pluck('id'); this.setState({actionInProgress: true}); - _.each(selectedTests, function(test) { - var testsetId = test.get('testset'), - testrunConfig = {tests: _.pluck(selectedTests, 'id')}, - addCredentials = _.bind(function(obj) { - obj.ostf_os_access_creds = { - ostf_os_username: this.state.credentials.user, - ostf_os_tenant_name: this.state.credentials.tenant, - ostf_os_password: this.state.credentials.password - }; - return obj; - }, this); - if (this.props.testruns.where({testset: testsetId}).length) { - _.each(this.props.testruns.where({testset: testsetId}), function(testrun) { - _.extend(testrunConfig, addCredentials({ - id: testrun.id, - status: 'restarted' - })); - oldTestruns.add(new models.TestRun(testrunConfig)); - }, this); - } else { - _.extend(testrunConfig, { - testset: testsetId, - metadata: addCredentials({ - config: {}, - cluster_id: this.props.cluster.id - }) - }); - testruns.add(new models.TestRun(testrunConfig)); + _.each(testsetIds, function(testsetId) { + var testsToRun = _.pluck(this.props.tests.where({ + testset: testsetId, + checked: true + }), 'id'); + if (testsToRun.length) { + var testrunConfig = {tests: testsToRun}, + addCredentials = _.bind(function(obj) { + obj.ostf_os_access_creds = { + ostf_os_username: this.state.credentials.user, + ostf_os_tenant_name: this.state.credentials.tenant, + ostf_os_password: this.state.credentials.password + }; + return obj; + }, this); + + if (this.props.testruns.where({testset: testsetId}).length) { + _.each(this.props.testruns.where({testset: testsetId}), function(testrun) { + _.extend(testrunConfig, addCredentials({ + id: testrun.id, + status: 'restarted' + })); + oldTestruns.add(new models.TestRun(testrunConfig)); + }, this); + } else { + _.extend(testrunConfig, { + testset: testsetId, + metadata: addCredentials({ + config: {}, + cluster_id: this.props.cluster.id + }) + }); + testruns.add(new models.TestRun(testrunConfig)); + } } }, this); + var requests = []; if (testruns.length) { requests.push(Backbone.sync('create', testruns));