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 textwrap | 5 import textwrap |
6 | 6 |
7 import webapp2 | 7 import webapp2 |
8 | 8 |
9 from testing_utils import testing | |
10 | |
11 from common.http_client_appengine import RetryHttpClient | 9 from common.http_client_appengine import RetryHttpClient |
12 from handlers import monitor_alerts | 10 from handlers import monitor_alerts |
13 from waterfall import build_failure_analysis_pipelines | 11 from waterfall import build_failure_analysis_pipelines |
14 from waterfall import waterfall_config | 12 from waterfall.test import wf_testcase |
15 | 13 |
16 | 14 |
17 class _MockedHttpClient(RetryHttpClient): | 15 class _MockedHttpClient(RetryHttpClient): |
18 | 16 |
19 def __init__(self, status_code, content): | 17 def __init__(self, status_code, content): |
20 self.status_code = status_code | 18 self.status_code = status_code |
21 self.content = content | 19 self.content = content |
22 | 20 |
23 def _Get(self, *_): | 21 def _Get(self, *_): |
24 return self.status_code, self.content | 22 return self.status_code, self.content |
25 | 23 |
26 def _Post(self, *_): # pragma: no cover | 24 def _Post(self, *_): # pragma: no cover |
27 pass | 25 pass |
28 | 26 |
29 def _Put(self, *_): # pragma: no cover | 27 def _Put(self, *_): # pragma: no cover |
30 pass | 28 pass |
31 | 29 |
32 | 30 |
33 class MonitorAlertsTest(testing.AppengineTestCase): | 31 class MonitorAlertsTest(wf_testcase.WaterfallTestCase): |
34 app_module = webapp2.WSGIApplication([ | 32 app_module = webapp2.WSGIApplication([ |
35 ('/monitor-alerts', monitor_alerts.MonitorAlerts), | 33 ('/monitor-alerts', monitor_alerts.MonitorAlerts), |
36 ], debug=True) | 34 ], debug=True) |
37 | 35 |
38 def setUp(self): | 36 def setUp(self): |
39 super(MonitorAlertsTest, self).setUp() | 37 super(MonitorAlertsTest, self).setUp() |
40 | 38 |
41 def MockMasterIsSupported(master_name): | |
42 return master_name != 'm0' | |
43 | |
44 self.mock(waterfall_config, 'MasterIsSupported', MockMasterIsSupported) | |
45 | |
46 def testGetLatestBuildFailuresWhenFailedToPullAlerts(self): | 39 def testGetLatestBuildFailuresWhenFailedToPullAlerts(self): |
47 http_client = _MockedHttpClient(404, 'Not Found') | 40 http_client = _MockedHttpClient(404, 'Not Found') |
48 self.assertEqual([], monitor_alerts._GetLatestBuildFailures(http_client)) | 41 self.assertEqual([], monitor_alerts._GetLatestBuildFailures(http_client)) |
49 | 42 |
50 def testGetLatestBuildFailuresWhenIllegalMasterUrl(self): | 43 def testGetLatestBuildFailuresWhenIllegalMasterUrl(self): |
51 alerts_content = textwrap.dedent(""" | 44 alerts_content = textwrap.dedent(""" |
52 { | 45 { |
53 "last_posted": 1434668974, | 46 "last_posted": 1434668974, |
54 "alerts": [ | 47 "alerts": [ |
55 { | 48 { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 failed_steps, force, queue_name)) | 172 failed_steps, force, queue_name)) |
180 | 173 |
181 self.mock(build_failure_analysis_pipelines, 'ScheduleAnalysisIfNeeded', | 174 self.mock(build_failure_analysis_pipelines, 'ScheduleAnalysisIfNeeded', |
182 MockScheduleAnalysisIfNeeded) | 175 MockScheduleAnalysisIfNeeded) |
183 | 176 |
184 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | 177 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
185 response = self.test_app.get('/monitor-alerts') | 178 response = self.test_app.get('/monitor-alerts') |
186 self.assertEqual(200, response.status_int) | 179 self.assertEqual(200, response.status_int) |
187 | 180 |
188 self.assertEqual(expected_scheduled_analyses, scheduled_analyses) | 181 self.assertEqual(expected_scheduled_analyses, scheduled_analyses) |
OLD | NEW |