Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: appengine/findit/waterfall/test/build_failure_analysis_pipelines_test.py

Issue 2158533002: [Findit] Use unittest.mock for testing and create a shared method to mock pipeline. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 logging 5 import mock
6 6
7 from testing_utils import testing 7 from testing_utils import testing
8 8
9 from common import constants 9 from common import constants
10 from common.pipeline_wrapper import pipeline_handlers 10 from common.pipeline_wrapper import pipeline_handlers
11 from model import analysis_status 11 from model import analysis_status
12 from model.wf_analysis import WfAnalysis 12 from model.wf_analysis import WfAnalysis
13 from waterfall import build_failure_analysis_pipelines 13 from waterfall import build_failure_analysis_pipelines
14 14
15 15
16 class _MockRootPipeline(object):
17 STARTED = False
18
19 def __init__(self, master_name, builder_name, build_number, build_completed,
20 force_try_job):
21 pass
22
23 def pipeline_status_path(self):
24 return ''
25
26 def start(self, queue_name):
27 _MockRootPipeline.STARTED = True
28 logging.info(queue_name)
29
30
31 class BuildFailureAnalysisPipelinesTest(testing.AppengineTestCase): 16 class BuildFailureAnalysisPipelinesTest(testing.AppengineTestCase):
32 app_module = pipeline_handlers._APP 17 app_module = pipeline_handlers._APP
33 18
34 def _CreateAndSaveWfAnalysis( 19 def _CreateAndSaveWfAnalysis(
35 self, master_name, builder_name, build_number, not_passed_steps, status, 20 self, master_name, builder_name, build_number, not_passed_steps, status,
36 build_completed=True): 21 build_completed=True):
37 analysis = WfAnalysis.Create(master_name, builder_name, build_number) 22 analysis = WfAnalysis.Create(master_name, builder_name, build_number)
38 analysis.not_passed_steps = not_passed_steps 23 analysis.not_passed_steps = not_passed_steps
39 analysis.status = status 24 analysis.status = status
40 analysis.build_completed = build_completed 25 analysis.build_completed = build_completed
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 self._CreateAndSaveWfAnalysis( 133 self._CreateAndSaveWfAnalysis(
149 master_name, builder_name, build_number, 134 master_name, builder_name, build_number,
150 not_passed_steps, analysis_status.COMPLETED, build_completed=False) 135 not_passed_steps, analysis_status.COMPLETED, build_completed=False)
151 136
152 failed_steps = ['a'] 137 failed_steps = ['a']
153 need_analysis = build_failure_analysis_pipelines.NeedANewAnalysis( 138 need_analysis = build_failure_analysis_pipelines.NeedANewAnalysis(
154 master_name, builder_name, build_number, failed_steps, True, False) 139 master_name, builder_name, build_number, failed_steps, True, False)
155 140
156 self.assertTrue(need_analysis) 141 self.assertTrue(need_analysis)
157 142
158 def testStartPipelineForNewAnalysis(self): 143 @mock.patch(
144 'waterfall.build_failure_analysis_pipelines.AnalyzeBuildFailurePipeline')
145 def testStartPipelineForNewAnalysis(self, mocked_pipeline):
159 master_name = 'm' 146 master_name = 'm'
160 builder_name = 'b' 147 builder_name = 'b'
161 build_number = 124 148 build_number = 124
162 149
163 self.mock(build_failure_analysis_pipelines.analyze_build_failure_pipeline,
164 'AnalyzeBuildFailurePipeline',
165 _MockRootPipeline)
166 _MockRootPipeline.STARTED = False
167
168 build_failure_analysis_pipelines.ScheduleAnalysisIfNeeded( 150 build_failure_analysis_pipelines.ScheduleAnalysisIfNeeded(
169 master_name, builder_name, build_number, failed_steps=['a'], 151 master_name, builder_name, build_number, failed_steps=['a'],
170 build_completed=False, force=False, force_try_job=False, 152 build_completed=False, force=False, force_try_job=False,
171 queue_name=constants.DEFAULT_QUEUE) 153 queue_name=constants.DEFAULT_QUEUE)
172 154
173 analysis = WfAnalysis.Get(master_name, builder_name, build_number) 155 analysis = WfAnalysis.Get(master_name, builder_name, build_number)
156 self.assertIsNotNone(analysis)
157 mocked_pipeline.assert_has_calls(
158 [mock.call().start(queue_name=constants.DEFAULT_QUEUE)])
174 159
175 self.assertTrue(_MockRootPipeline.STARTED) 160 @mock.patch(
176 self.assertIsNotNone(analysis) 161 'waterfall.build_failure_analysis_pipelines.AnalyzeBuildFailurePipeline')
177 162 def testNotStartPipelineForNewAnalysis(self, mocked_pipeline):
178 def testNotStartPipelineForNewAnalysis(self):
179 master_name = 'm' 163 master_name = 'm'
180 builder_name = 'b' 164 builder_name = 'b'
181 build_number = 123 165 build_number = 123
182 not_passed_steps = ['a'] 166 not_passed_steps = ['a']
183 167
184 self._CreateAndSaveWfAnalysis( 168 self._CreateAndSaveWfAnalysis(
185 master_name, builder_name, build_number, 169 master_name, builder_name, build_number,
186 not_passed_steps, analysis_status.RUNNING) 170 not_passed_steps, analysis_status.RUNNING)
187 171
188 self.mock(build_failure_analysis_pipelines.analyze_build_failure_pipeline,
189 'AnalyzeBuildFailurePipeline',
190 _MockRootPipeline)
191 _MockRootPipeline.STARTED = False
192
193 build_failure_analysis_pipelines.ScheduleAnalysisIfNeeded( 172 build_failure_analysis_pipelines.ScheduleAnalysisIfNeeded(
194 master_name, builder_name, build_number, failed_steps=['a'], 173 master_name, builder_name, build_number, failed_steps=['a'],
195 build_completed=True, force=False, queue_name=constants.DEFAULT_QUEUE) 174 build_completed=True, force=False, queue_name=constants.DEFAULT_QUEUE)
196 175
197 self.assertFalse(_MockRootPipeline.STARTED) 176 self.assertFalse(mocked_pipeline.called)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698