1 # Copyright (C) 2012 Google Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 import buildershandler
35 class BuildersHandlerTest(unittest.TestCase):
36 def test_fetch_buildbot_data(self):
40 def fake_fetch_json(url):
41 fetched_urls.append(url)
43 if url == 'http://chrome-build-extract.appspot.com/get_master/chromium.webkit':
46 'WebKit Win': None, 'WebKit Linux': None, 'WebKit Mac': None, 'WebKit Empty': None,
50 if url == 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Linux&master=chromium.webkit&num_builds=1':
53 {'steps': [{'name': 'foo_tests_only'}, {'name': 'webkit_tests'}, {'name': 'browser_tests'}, {'name': 'mini_installer_test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]},
57 if url == 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Win&master=chromium.webkit&num_builds=1':
60 {'steps': [{'name': 'foo_tests_ignore'}, {'name': 'webkit_tests'}, {'name': 'mini_installer_test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]},
64 if url == 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Mac&master=chromium.webkit&num_builds=1':
67 {'steps': [{'name': 'foo_tests_perf'}, {'name': 'browser_tests'}, {'name': 'mini_installer_test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]},
71 if url == 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Empty&master=chromium.webkit&num_builds=1':
74 logging.error('Cannot fetch fake url: %s' % url)
76 old_fetch_json = buildershandler.fetch_json
77 buildershandler.fetch_json = fake_fetch_json
80 {'name': 'ChromiumWebkit', 'url_name': 'chromium.webkit'},
83 buildbot_data = buildershandler.fetch_buildbot_data([m['url_name'] for m in masters])
85 expected_fetched_urls = [
86 'http://chrome-build-extract.appspot.com/get_master/chromium.webkit',
87 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Win&master=chromium.webkit&num_builds=1',
88 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Mac&master=chromium.webkit&num_builds=1',
89 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Empty&master=chromium.webkit&num_builds=1',
90 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Linux&master=chromium.webkit&num_builds=1',
92 self.assertEqual(set(fetched_urls), set(expected_fetched_urls))
97 'browser_tests': {'builders': ['WebKit Linux', 'WebKit Mac']},
98 'mini_installer_test': {'builders': ['WebKit Linux', 'WebKit Mac', 'WebKit Win']},
99 'layout-tests': {'builders': ['WebKit Linux', 'WebKit Win']}},
100 'name': 'ChromiumWebkit',
101 'url_name': 'chromium.webkit',
102 'groups': ['@ToT Chromium', '@ToT Blink'],
104 "no_upload_test_types": buildershandler.TEST_STEPS_THAT_DO_NOT_UPLOAD_YET,
106 expected_json = buildershandler.dump_json(expected_masters)
108 self.assertEqual(buildbot_data, expected_json)
110 buildershandler.fetch_json = old_fetch_json
112 def test_fetch_buildbot_data_failure(self):
116 def fake_fetch_json(url):
117 fetched_urls.append(url)
119 if url == 'http://chrome-build-extract.appspot.com/get_master/chromium.webkit':
122 if url == 'http://chrome-build-extract.appspot.com/get_master/chromium.gpu':
125 'Win GPU': None, 'Win Empty': None,
129 if url == 'http://chrome-build-extract.appspot.com/get_master/chromium.fyi':
136 if (url == 'http://chrome-build-extract.appspot.com/get_builds?builder=Win%20Empty&master=chromium.gpu&num_builds=1'
137 or url == 'http://chrome-build-extract.appspot.com/get_builds?builder=Win%20GPU&master=chromium.gpu&num_builds=1'):
144 logging.error('Cannot fetch fake url: %s' % url)
146 old_fetch_json = buildershandler.fetch_json
147 buildershandler.fetch_json = fake_fetch_json
150 {'name': 'ChromiumGPU', 'url_name': 'chromium.gpu'},
151 {'name': 'ChromiumWebkit', 'url_name': 'chromium.webkit'},
152 {'name': 'ChromiumFYI', 'url_name': 'chromium.fyi'},
155 expected_fetched_urls = [
156 'http://chrome-build-extract.appspot.com/get_master/chromium.webkit',
157 'http://chrome-build-extract.appspot.com/get_master/chromium.gpu',
158 'http://chrome-build-extract.appspot.com/get_builds?builder=Win%20GPU&master=chromium.gpu&num_builds=1',
159 'http://chrome-build-extract.appspot.com/get_builds?builder=Win%20Empty&master=chromium.gpu&num_builds=1',
161 with self.assertRaises(buildershandler.FetchBuildersException):
162 buildbot_data = buildershandler.fetch_buildbot_data([m['url_name'] for m in masters])
163 self.assertEqual(set(expected_fetched_urls), set(fetched_urls))
166 buildershandler.fetch_json = old_fetch_json
169 if __name__ == '__main__':