| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 | 6 |
| 7 import mock | 7 import mock |
| 8 import webapp2 | 8 import webapp2 |
| 9 import webtest | 9 import webtest |
| 10 | 10 |
| 11 from google.appengine.api import users | 11 from google.appengine.api import users |
| 12 | 12 |
| 13 from dashboard.api import api_auth | 13 from dashboard.api import api_auth |
| 14 from dashboard.common import namespaced_stored_object | 14 from dashboard.common import namespaced_stored_object |
| 15 from dashboard.common import testing_common | 15 from dashboard.common import testing_common |
| 16 from dashboard.common import utils | 16 from dashboard.common import utils |
| 17 from dashboard.services import gitiles_service | 17 from dashboard.services import gitiles_service |
| 18 from dashboard.pinpoint.handlers import new | 18 from dashboard.pinpoint.handlers import new |
| 19 from dashboard.pinpoint.models import job as job_module | 19 from dashboard.pinpoint.models import job as job_module |
| 20 from dashboard.pinpoint.models import test_config |
| 20 | 21 |
| 21 AUTHORIZED_USER = users.User(email='authorized_person@chromium.org', | 22 AUTHORIZED_USER = users.User(email='authorized_person@chromium.org', |
| 22 _auth_domain='google.com') | 23 _auth_domain='google.com') |
| 23 UNAUTHORIZED_USER = users.User(email='foo@bar.com', _auth_domain='bar.com') | 24 UNAUTHORIZED_USER = users.User(email='foo@bar.com', _auth_domain='bar.com') |
| 24 | 25 |
| 25 | 26 |
| 26 class NewTest(testing_common.TestCase): | 27 class NewTest(testing_common.TestCase): |
| 27 | 28 |
| 28 def setUp(self): | 29 def setUp(self): |
| 29 super(NewTest, self).setUp() | 30 super(NewTest, self).setUp() |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 @mock.patch.object(gitiles_service, 'CommitInfo', mock.MagicMock()) | 82 @mock.patch.object(gitiles_service, 'CommitInfo', mock.MagicMock()) |
| 82 @mock.patch.object(gitiles_service, 'CommitRange') | 83 @mock.patch.object(gitiles_service, 'CommitRange') |
| 83 def testPost(self, mock_commit_range): | 84 def testPost(self, mock_commit_range): |
| 84 mock_commit_range.return_value = [ | 85 mock_commit_range.return_value = [ |
| 85 {'commit': '1'}, | 86 {'commit': '1'}, |
| 86 {'commit': '2'}, | 87 {'commit': '2'}, |
| 87 {'commit': '3'}, | 88 {'commit': '3'}, |
| 88 ] | 89 ] |
| 89 params = { | 90 params = { |
| 90 'configuration': 'chromium-rel-mac11-pro', | 91 'configuration': 'chromium-rel-mac11-pro', |
| 91 'test_suite': 'speedometer', | 92 'target': 'telemetry_perf_tests', |
| 92 'test': '', | 93 'dimensions': '{}', |
| 93 'metric': 'Total', | 94 'benchmark': 'speedometer', |
| 94 'auto_explore': '1', | 95 'auto_explore': '1', |
| 95 'bug_id': 12345, | 96 'bug_id': 12345, |
| 96 'start_repository': 'src', | 97 'start_repository': 'src', |
| 97 'start_git_hash': '1', | 98 'start_git_hash': '1', |
| 98 'end_repository': 'src', | 99 'end_repository': 'src', |
| 99 'end_git_hash': '3' | 100 'end_git_hash': '3' |
| 100 } | 101 } |
| 101 response = self.testapp.post('/api/new', params, status=200) | 102 response = self.testapp.post('/api/new', params, status=200) |
| 102 result = json.loads(response.body) | 103 result = json.loads(response.body) |
| 103 self.assertIn('jobId', result) | 104 self.assertIn('jobId', result) |
| 104 self.assertEqual( | 105 self.assertEqual( |
| 105 result['jobUrl'], | 106 result['jobUrl'], |
| 106 'https://testbed.example.com/job/%s' % result['jobId']) | 107 'https://testbed.example.com/job/%s' % result['jobId']) |
| 107 | 108 |
| 108 def testPost_MetricButNoTestSuite(self): | 109 def testPost_InvalidTestConfig(self): |
| 109 params = { | 110 params = { |
| 110 'configuration': 'chromium-rel-mac11-pro', | 111 'configuration': 'chromium-rel-mac11-pro', |
| 111 'test_suite': '', | 112 'target': 'telemetry_perf_tests', |
| 112 'test': '', | 113 'dimensions': '{}', |
| 113 'metric': 'Total', | 114 # telemetry_perf_tests requires a benchmark field, which is missing. |
| 114 'auto_explore': '1', | 115 'auto_explore': '1', |
| 115 'bug_id': 12345, | 116 'bug_id': 12345, |
| 116 'start_repository': 'src', | 117 'start_repository': 'src', |
| 117 'start_git_hash': '1', | 118 'start_git_hash': '1', |
| 118 'end_repository': 'src', | 119 'end_repository': 'src', |
| 119 'end_git_hash': '3' | 120 'end_git_hash': '3' |
| 120 } | 121 } |
| 121 response = self.testapp.post('/api/new', params, status=200) | 122 response = self.testapp.post('/api/new', params, status=200) |
| 122 self.assertEqual({'error': new._ERROR_METRIC_NO_TEST_SUITE}, | 123 self.assertEqual({'error': test_config._ERROR_NO_BENCHMARK}, |
| 123 json.loads(response.body)) | 124 json.loads(response.body)) |
| 124 | 125 |
| 125 @mock.patch.object( | 126 @mock.patch.object( |
| 126 gitiles_service, 'CommitInfo', | 127 gitiles_service, 'CommitInfo', |
| 127 mock.MagicMock(side_effect=gitiles_service.NotFoundError)) | 128 mock.MagicMock(side_effect=gitiles_service.NotFoundError('message'))) |
| 128 def testPost_InvalidChange(self): | 129 def testPost_InvalidChange(self): |
| 129 params = { | 130 params = { |
| 130 'configuration': 'chromium-rel-mac11-pro', | 131 'configuration': 'chromium-rel-mac11-pro', |
| 131 'test_suite': 'speedometer', | |
| 132 'test': '', | |
| 133 'metric': 'Total', | |
| 134 'auto_explore': '1', | 132 'auto_explore': '1', |
| 135 'bug_id': 12345, | 133 'bug_id': 12345, |
| 136 'start_repository': 'src', | 134 'start_repository': 'src', |
| 137 'start_git_hash': '1', | 135 'start_git_hash': '1', |
| 138 'end_repository': 'src', | 136 'end_repository': 'src', |
| 139 'end_git_hash': '3' | 137 'end_git_hash': '3' |
| 140 } | 138 } |
| 141 response = self.testapp.post('/api/new', params, status=200) | 139 response = self.testapp.post('/api/new', params, status=200) |
| 142 self.assertEqual({'error': 'NotFoundError()'}, | 140 self.assertEqual({'error': 'message'}, |
| 143 json.loads(response.body)) | 141 json.loads(response.body)) |
| 144 | 142 |
| 145 def testPost_InvalidBug(self): | 143 def testPost_InvalidBug(self): |
| 146 params = { | 144 params = { |
| 147 'configuration': 'chromium-rel-mac11-pro', | 145 'configuration': 'chromium-rel-mac11-pro', |
| 148 'test_suite': 'speedometer', | |
| 149 'test': '', | |
| 150 'metric': 'Total', | |
| 151 'auto_explore': '1', | 146 'auto_explore': '1', |
| 152 'bug_id': 'not_an_int', | 147 'bug_id': 'not_an_int', |
| 153 'start_repository': 'src', | 148 'start_repository': 'src', |
| 154 'start_git_hash': '1', | 149 'start_git_hash': '1', |
| 155 'end_repository': 'src', | 150 'end_repository': 'src', |
| 156 'end_git_hash': '3' | 151 'end_git_hash': '3' |
| 157 } | 152 } |
| 158 response = self.testapp.post('/api/new', params, status=200) | 153 response = self.testapp.post('/api/new', params, status=200) |
| 159 self.assertEqual({'error': new._ERROR_BUG_ID}, | 154 self.assertEqual({'error': new._ERROR_BUG_ID}, |
| 160 json.loads(response.body)) | 155 json.loads(response.body)) |
| 161 | 156 |
| 162 @mock.patch( | 157 @mock.patch( |
| 163 'dashboard.services.issue_tracker_service.IssueTrackerService', | 158 'dashboard.services.issue_tracker_service.IssueTrackerService', |
| 164 mock.MagicMock()) | 159 mock.MagicMock()) |
| 165 @mock.patch.object(utils, 'ServiceAccountHttp', mock.MagicMock()) | 160 @mock.patch.object(utils, 'ServiceAccountHttp', mock.MagicMock()) |
| 166 @mock.patch.object(gitiles_service, 'CommitInfo', mock.MagicMock()) | 161 @mock.patch.object(gitiles_service, 'CommitInfo', mock.MagicMock()) |
| 167 @mock.patch.object(gitiles_service, 'CommitRange') | 162 @mock.patch.object(gitiles_service, 'CommitRange') |
| 168 def testPost_EmptyBug(self, mock_commit_range): | 163 def testPost_EmptyBug(self, mock_commit_range): |
| 169 mock_commit_range.return_value = [ | 164 mock_commit_range.return_value = [ |
| 170 {'commit': '1'}, | 165 {'commit': '1'}, |
| 171 {'commit': '2'}, | 166 {'commit': '2'}, |
| 172 {'commit': '3'}, | 167 {'commit': '3'}, |
| 173 ] | 168 ] |
| 174 params = { | 169 params = { |
| 175 'configuration': 'chromium-rel-mac11-pro', | 170 'configuration': 'chromium-rel-mac11-pro', |
| 176 'test_suite': 'speedometer', | |
| 177 'test': '', | |
| 178 'metric': 'Total', | |
| 179 'auto_explore': '1', | 171 'auto_explore': '1', |
| 180 'bug_id': '', | 172 'bug_id': '', |
| 181 'start_repository': 'src', | 173 'start_repository': 'src', |
| 182 'start_git_hash': '1', | 174 'start_git_hash': '1', |
| 183 'end_repository': 'src', | 175 'end_repository': 'src', |
| 184 'end_git_hash': '3' | 176 'end_git_hash': '3' |
| 185 } | 177 } |
| 186 response = self.testapp.post('/api/new', params, status=200) | 178 response = self.testapp.post('/api/new', params, status=200) |
| 187 result = json.loads(response.body) | 179 result = json.loads(response.body) |
| 188 self.assertIn('jobId', result) | 180 self.assertIn('jobId', result) |
| 189 self.assertEqual( | 181 self.assertEqual( |
| 190 result['jobUrl'], | 182 result['jobUrl'], |
| 191 'https://testbed.example.com/job/%s' % result['jobId']) | 183 'https://testbed.example.com/job/%s' % result['jobId']) |
| 192 job = job_module.Job.query().get() | 184 job = job_module.Job.query().get() |
| 193 self.assertEqual(None, job.bug_id) | 185 self.assertEqual(None, job.bug_id) |
| OLD | NEW |