| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 import re | 6 import re |
| 7 | 7 |
| 8 from google.appengine.ext import testbed | 8 from google.appengine.ext import testbed |
| 9 import webapp2 | 9 import webapp2 |
| 10 import webtest | 10 import webtest |
| 11 | 11 |
| 12 from testing_utils import testing | 12 from testing_utils import testing |
| 13 | 13 |
| 14 from model.wf_build import WfBuild | 14 from model.wf_build import WfBuild |
| 15 from handlers import trigger_analyses | 15 from handlers import process_failure_analysis_requests |
| 16 from waterfall import buildbot | 16 from waterfall import buildbot |
| 17 from waterfall import build_util | 17 from waterfall import build_util |
| 18 from waterfall import build_failure_analysis_pipelines | 18 from waterfall import build_failure_analysis_pipelines |
| 19 from waterfall.build_info import BuildInfo | 19 from waterfall.build_info import BuildInfo |
| 20 | 20 |
| 21 | 21 |
| 22 class TriggerAnalyseseTest(testing.AppengineTestCase): | 22 class ProcessFailureAnalysisRequestsTest(testing.AppengineTestCase): |
| 23 app_module = webapp2.WSGIApplication([ | 23 app_module = webapp2.WSGIApplication([ |
| 24 ('/trigger-analyses', trigger_analyses.TriggerAnalyses), | 24 ('/process-failure-analysis-requests', |
| 25 process_failure_analysis_requests.ProcessFailureAnalysisRequests), |
| 25 ], debug=True) | 26 ], debug=True) |
| 26 | 27 |
| 27 def _MockDownloadBuildData(self, build): | 28 def _MockDownloadBuildData(self, build): |
| 28 def Mocked_DownloadBuildData(*_): | 29 def Mocked_DownloadBuildData(*_): |
| 29 return build | 30 return build |
| 30 self.mock(build_util, 'DownloadBuildData', Mocked_DownloadBuildData) | 31 self.mock(build_util, 'DownloadBuildData', Mocked_DownloadBuildData) |
| 31 | 32 |
| 32 def _MockExtractBuildInfo(self, build_info): | 33 def _MockExtractBuildInfo(self, build_info): |
| 33 def Mocked_ExtractBuildInfo(*_): | 34 def Mocked_ExtractBuildInfo(*_): |
| 34 return build_info | 35 return build_info |
| (...skipping 13 matching lines...) Expand all Loading... |
| 48 | 49 |
| 49 builds = [ | 50 builds = [ |
| 50 { | 51 { |
| 51 'master_name': 'm', | 52 'master_name': 'm', |
| 52 'builder_name': 'b', | 53 'builder_name': 'b', |
| 53 'build_number': 1, | 54 'build_number': 1, |
| 54 'failed_steps': [], | 55 'failed_steps': [], |
| 55 }, | 56 }, |
| 56 ] | 57 ] |
| 57 | 58 |
| 58 trigger_analyses._TriggerNewAnalysesOnDemand(builds) | 59 process_failure_analysis_requests._TriggerNewAnalysesOnDemand(builds) |
| 59 self.assertEqual(0, len(requests)) | 60 self.assertEqual(0, len(requests)) |
| 60 | 61 |
| 61 def testWhenBuildDataIsNotAvailable(self): | 62 def testWhenBuildDataIsNotAvailable(self): |
| 62 build = WfBuild.Create('m', 'b', 1) | 63 build = WfBuild.Create('m', 'b', 1) |
| 63 build.data = None | 64 build.data = None |
| 64 self._MockDownloadBuildData(build) | 65 self._MockDownloadBuildData(build) |
| 65 | 66 |
| 66 self._MockExtractBuildInfo(None) | 67 self._MockExtractBuildInfo(None) |
| 67 requests = [] | 68 requests = [] |
| 68 self._MockScheduleAnalysisIfNeeded(requests) | 69 self._MockScheduleAnalysisIfNeeded(requests) |
| 69 | 70 |
| 70 builds = [ | 71 builds = [ |
| 71 { | 72 { |
| 72 'master_name': 'm', | 73 'master_name': 'm', |
| 73 'builder_name': 'b', | 74 'builder_name': 'b', |
| 74 'build_number': 1, | 75 'build_number': 1, |
| 75 'failed_steps': [], | 76 'failed_steps': [], |
| 76 }, | 77 }, |
| 77 ] | 78 ] |
| 78 | 79 |
| 79 trigger_analyses._TriggerNewAnalysesOnDemand(builds) | 80 process_failure_analysis_requests._TriggerNewAnalysesOnDemand(builds) |
| 80 self.assertEqual(0, len(requests)) | 81 self.assertEqual(0, len(requests)) |
| 81 | 82 |
| 82 def testWhenBuildDataIsDownloadedSuccessfully(self): | 83 def testWhenBuildDataIsDownloadedSuccessfully(self): |
| 83 build = WfBuild.Create('m', 'b', 1) | 84 build = WfBuild.Create('m', 'b', 1) |
| 84 build.data = '{}' | 85 build.data = '{}' |
| 85 self._MockDownloadBuildData(build) | 86 self._MockDownloadBuildData(build) |
| 86 | 87 |
| 87 build_info = BuildInfo('m', 'b', 1) | 88 build_info = BuildInfo('m', 'b', 1) |
| 88 build_info.completed = False | 89 build_info.completed = False |
| 89 self._MockExtractBuildInfo(build_info) | 90 self._MockExtractBuildInfo(build_info) |
| 90 | 91 |
| 91 requests = [] | 92 requests = [] |
| 92 self._MockScheduleAnalysisIfNeeded(requests) | 93 self._MockScheduleAnalysisIfNeeded(requests) |
| 93 | 94 |
| 94 builds = [ | 95 builds = [ |
| 95 { | 96 { |
| 96 'master_name': 'm', | 97 'master_name': 'm', |
| 97 'builder_name': 'b', | 98 'builder_name': 'b', |
| 98 'build_number': 1, | 99 'build_number': 1, |
| 99 'failed_steps': [], | 100 'failed_steps': [], |
| 100 }, | 101 }, |
| 101 ] | 102 ] |
| 102 trigger_analyses._TriggerNewAnalysesOnDemand(builds) | 103 process_failure_analysis_requests._TriggerNewAnalysesOnDemand(builds) |
| 103 self.assertEqual(1, len(requests)) | 104 self.assertEqual(1, len(requests)) |
| 104 self.assertFalse(requests[0][1]['build_completed']) | 105 self.assertFalse(requests[0][1]['build_completed']) |
| 105 | 106 |
| 106 def testNonAdminCanNotSendRequest(self): | 107 def testNonAdminCanNotSendRequest(self): |
| 107 self.assertRaisesRegexp( | 108 self.assertRaisesRegexp( |
| 108 webtest.app.AppError, | 109 webtest.app.AppError, |
| 109 re.compile('.*401 Unauthorized.*' | 110 re.compile('.*401 Unauthorized.*' |
| 110 'Error: Either not login or no permission.*', | 111 'Error: Either not login or no permission.*', |
| 111 re.MULTILINE | re.DOTALL), | 112 re.MULTILINE | re.DOTALL), |
| 112 self.test_app.post, | 113 self.test_app.post, |
| 113 '/trigger-analyses', | 114 '/process-failure-analysis-requests', |
| 114 params=json.dumps({'builds': []})) | 115 params=json.dumps({'builds': []})) |
| 115 | 116 |
| 116 def testAdminCanRequestAnalysisOfFailureOnUnsupportedMaster(self): | 117 def testAdminCanRequestAnalysisOfFailureOnUnsupportedMaster(self): |
| 117 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | 118 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
| 118 | 119 |
| 119 build = WfBuild.Create('m', 'b', 1) | 120 build = WfBuild.Create('m', 'b', 1) |
| 120 build.data = '{}' | 121 build.data = '{}' |
| 121 self._MockDownloadBuildData(build) | 122 self._MockDownloadBuildData(build) |
| 122 | 123 |
| 123 build_info = BuildInfo('m', 'b', 1) | 124 build_info = BuildInfo('m', 'b', 1) |
| 124 build_info.completed = True | 125 build_info.completed = True |
| 125 self._MockExtractBuildInfo(build_info) | 126 self._MockExtractBuildInfo(build_info) |
| 126 | 127 |
| 127 requests = [] | 128 requests = [] |
| 128 self._MockScheduleAnalysisIfNeeded(requests) | 129 self._MockScheduleAnalysisIfNeeded(requests) |
| 129 | 130 |
| 130 builds = [ | 131 builds = [ |
| 131 { | 132 { |
| 132 'master_name': 'm', | 133 'master_name': 'm', |
| 133 'builder_name': 'b', | 134 'builder_name': 'b', |
| 134 'build_number': 1, | 135 'build_number': 1, |
| 135 'failed_steps': [], | 136 'failed_steps': [], |
| 136 }, | 137 }, |
| 137 ] | 138 ] |
| 138 | 139 |
| 139 response = self.test_app.post( | 140 response = self.test_app.post( |
| 140 '/trigger-analyses', | 141 '/process-failure-analysis-requests', |
| 141 params=json.dumps({'builds': builds})) | 142 params=json.dumps({'builds': builds})) |
| 142 self.assertEquals(200, response.status_int) | 143 self.assertEquals(200, response.status_int) |
| 143 self.assertEqual(1, len(requests)) | 144 self.assertEqual(1, len(requests)) |
| 144 self.assertTrue(requests[0][1]['build_completed']) | 145 self.assertTrue(requests[0][1]['build_completed']) |
| OLD | NEW |