| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 mock |
| 5 import textwrap | 6 import textwrap |
| 6 | 7 |
| 7 import webapp2 | 8 import webapp2 |
| 8 | 9 |
| 9 from common import constants | 10 from common import constants |
| 10 from common.http_client_appengine import RetryHttpClient | 11 from common.http_client_appengine import RetryHttpClient |
| 11 from handlers import monitor_alerts | 12 from handlers import monitor_alerts |
| 12 from waterfall import build_failure_analysis_pipelines | 13 from waterfall import build_failure_analysis_pipelines |
| 13 from waterfall.test import wf_testcase | 14 from waterfall.test import wf_testcase |
| 14 | 15 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 'builder_name': 'b3', | 139 'builder_name': 'b3', |
| 139 'build_number': 4, | 140 'build_number': 4, |
| 140 'failed_steps': ['s1', 's2'], | 141 'failed_steps': ['s1', 's2'], |
| 141 }, | 142 }, |
| 142 ] | 143 ] |
| 143 | 144 |
| 144 http_client = _MockedHttpClient(200, alerts_content) | 145 http_client = _MockedHttpClient(200, alerts_content) |
| 145 build_failures = monitor_alerts._GetLatestBuildFailures(http_client) | 146 build_failures = monitor_alerts._GetLatestBuildFailures(http_client) |
| 146 self.assertEqual(expected_build_failures, build_failures) | 147 self.assertEqual(expected_build_failures, build_failures) |
| 147 | 148 |
| 148 def testAnalysisScheduled(self): | 149 @mock.patch.object(monitor_alerts, '_GetLatestBuildFailures') |
| 150 @mock.patch.object(monitor_alerts, 'build_failure_analysis_pipelines') |
| 151 def testAnalysisScheduled(self, mock_module, mock_fn): |
| 149 build_failures = [ | 152 build_failures = [ |
| 150 { | 153 { |
| 151 'master_name': 'm3', | 154 'master_name': 'm3', |
| 152 'builder_name': 'b3', | 155 'builder_name': 'b3', |
| 153 'build_number': 3, | 156 'build_number': 3, |
| 154 'failed_steps': ['s3'], | 157 'failed_steps': ['s3'], |
| 155 }, | 158 }, |
| 156 ] | 159 ] |
| 157 | 160 |
| 158 def MockGetLatestBuildFailures(*_): | 161 mock_fn.return_value = build_failures |
| 159 return build_failures | |
| 160 self.mock( | |
| 161 monitor_alerts, '_GetLatestBuildFailures', MockGetLatestBuildFailures) | |
| 162 | |
| 163 expected_scheduled_analyses = [ | |
| 164 ('m3', 'b3', 3, ['s3'], False, | |
| 165 constants.WATERFALL_ANALYSIS_QUEUE), | |
| 166 ] | |
| 167 | |
| 168 scheduled_analyses = [] | |
| 169 def MockScheduleAnalysisIfNeeded(master_name, builder_name, build_number, | |
| 170 failed_steps, force, queue_name): | |
| 171 scheduled_analyses.append( | |
| 172 (master_name, builder_name, build_number, | |
| 173 failed_steps, force, queue_name)) | |
| 174 | |
| 175 self.mock(build_failure_analysis_pipelines, 'ScheduleAnalysisIfNeeded', | |
| 176 MockScheduleAnalysisIfNeeded) | |
| 177 | 162 |
| 178 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | 163 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
| 179 response = self.test_app.get('/monitor-alerts') | 164 response = self.test_app.get('/monitor-alerts') |
| 180 self.assertEqual(200, response.status_int) | 165 self.assertEqual(200, response.status_int) |
| 181 | 166 |
| 182 self.assertEqual(expected_scheduled_analyses, scheduled_analyses) | 167 mock_module.ScheduleAnalysisIfNeeded.assert_called_with( |
| 168 'm3', 'b3', 3, failed_steps=['s3'], force=False, |
| 169 queue_name=constants.WATERFALL_ANALYSIS_QUEUE) |
| OLD | NEW |