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

Side by Side Diff: appengine/findit/waterfall/test/buildbot_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
« no previous file with comments | « appengine/findit/waterfall/test/build_failure_analysis_pipelines_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 from datetime import datetime 5 from datetime import datetime
6 import mock
6 import os 7 import os
7 import unittest 8 import unittest
8 9
9 from common.retry_http_client import RetryHttpClient 10 from common.retry_http_client import RetryHttpClient
10 from waterfall import buildbot 11 from waterfall import buildbot
11 12
12 13
13 class DummyHttpClient(RetryHttpClient): 14 class DummyHttpClient(RetryHttpClient):
14 15
15 def __init__(self, status_code, response_content): 16 def __init__(self, status_code, response_content):
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 expected_stdio_log_url, 140 expected_stdio_log_url,
140 buildbot.CreateGtestResultPath( 141 buildbot.CreateGtestResultPath(
141 master_name, builder_name, build_number, step_name)) 142 master_name, builder_name, build_number, step_name))
142 143
143 def testGetBuildDataFromArchiveSuccess(self): 144 def testGetBuildDataFromArchiveSuccess(self):
144 master_name = 'a' 145 master_name = 'a'
145 builder_name = 'b c' 146 builder_name = 'b c'
146 build_number = 1 147 build_number = 1
147 expected_url = ('https://chrome-build-extract.appspot.com/p/a/builders/' 148 expected_url = ('https://chrome-build-extract.appspot.com/p/a/builders/'
148 'b%20c/builds/1?json=1') 149 'b%20c/builds/1?json=1')
149 http_client = DummyHttpClient(200, 'abc') 150 http_client = mock.create_autospec(RetryHttpClient)
151 http_client.Get.return_value = (200, 'abc')
150 data = buildbot.GetBuildDataFromArchive( 152 data = buildbot.GetBuildDataFromArchive(
151 master_name, builder_name, build_number, http_client) 153 master_name, builder_name, build_number, http_client)
152 self.assertEqual(http_client.response_content, data) 154 self.assertEqual('abc', data)
153 self.assertEqual(1, len(http_client.requests)) 155 http_client.assert_has_calls([mock.call.Get(expected_url)])
154 self.assertEqual(expected_url, http_client.requests[0])
155 156
156 def testGetBuildDataFromArchiveFailure(self): 157 def testGetBuildDataFromArchiveFailure(self):
157 master_name = 'a' 158 master_name = 'a'
158 builder_name = 'b c' 159 builder_name = 'b c'
159 build_number = 1 160 build_number = 1
160 expected_url = ('https://chrome-build-extract.appspot.com/p/a/builders/' 161 expected_url = ('https://chrome-build-extract.appspot.com/p/a/builders/'
161 'b%20c/builds/1?json=1') 162 'b%20c/builds/1?json=1')
162 http_client = DummyHttpClient(404, 'Not Found') 163 http_client = DummyHttpClient(404, 'Not Found')
163 data = buildbot.GetBuildDataFromArchive( 164 data = buildbot.GetBuildDataFromArchive(
164 master_name, builder_name, build_number, http_client) 165 master_name, builder_name, build_number, http_client)
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 417
417 expected_blame_list = [ 418 expected_blame_list = [
418 '449cdbd05616de91fcf7e8b4282e300336d6d7c5', 419 '449cdbd05616de91fcf7e8b4282e300336d6d7c5',
419 '6addffac2601ab1083a55d085847d9bf8e66da02' 420 '6addffac2601ab1083a55d085847d9bf8e66da02'
420 ] 421 ]
421 422
422 build_info = buildbot.ExtractBuildInfo( 423 build_info = buildbot.ExtractBuildInfo(
423 master_name, builder_name, build_number, build_data) 424 master_name, builder_name, build_number, build_data)
424 425
425 self.assertEqual(expected_blame_list, build_info.blame_list) 426 self.assertEqual(expected_blame_list, build_info.blame_list)
OLDNEW
« no previous file with comments | « appengine/findit/waterfall/test/build_failure_analysis_pipelines_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698