Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / TestResultServer / handlers / buildershandler_unittest.py
1 # Copyright (C) 2012 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
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
12 # distribution.
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.
16 #
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.
28
29 import buildershandler
30 import json
31 import logging
32 import pprint
33 import unittest
34
35 class BuildersHandlerTest(unittest.TestCase):
36     def test_fetch_buildbot_data(self):
37         try:
38             fetched_urls = []
39
40             def fake_fetch_json(url):
41                 fetched_urls.append(url)
42
43                 if url == 'http://chrome-build-extract.appspot.com/get_master/chromium.webkit':
44                     return {
45                         'builders': {
46                             'WebKit Win': None, 'WebKit Linux': None, 'WebKit Mac': None, 'WebKit Empty': None,
47                         }
48                     }
49
50                 if url == 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Linux&master=chromium.webkit&num_builds=1':
51                     return {
52                         'builds': [
53                             {'steps': [{'name': 'foo_tests_only'}, {'name': 'webkit_tests'}, {'name': 'browser_tests'}, {'name': 'mini_installer_test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]},
54                         ],
55                     }
56
57                 if url == 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Win&master=chromium.webkit&num_builds=1':
58                     return {
59                         'builds': [
60                             {'steps': [{'name': 'foo_tests_ignore'}, {'name': 'webkit_tests'}, {'name': 'mini_installer_test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]},
61                         ],
62                     }
63
64                 if url == 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Mac&master=chromium.webkit&num_builds=1':
65                     return {
66                         'builds': [
67                             {'steps': [{'name': 'foo_tests_perf'}, {'name': 'browser_tests'}, {'name': 'mini_installer_test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]},
68                         ],
69                     }
70
71                 if url == 'http://chrome-build-extract.appspot.com/get_builds?builder=WebKit%20Empty&master=chromium.webkit&num_builds=1':
72                     return {'builds': []}
73
74                 logging.error('Cannot fetch fake url: %s' % url)
75
76             old_fetch_json = buildershandler.fetch_json
77             buildershandler.fetch_json = fake_fetch_json
78
79             masters = [
80                 {'name': 'ChromiumWebkit', 'url_name': 'chromium.webkit'},
81             ]
82
83             buildbot_data = buildershandler.fetch_buildbot_data([m['url_name'] for m in masters])
84
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',
91             ]
92             self.assertEqual(set(fetched_urls), set(expected_fetched_urls))
93
94             expected_masters = {
95                 'masters': [{
96                     'tests': {
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'],
103                 }],
104                 "no_upload_test_types": buildershandler.TEST_STEPS_THAT_DO_NOT_UPLOAD_YET,
105             }
106             expected_json = buildershandler.dump_json(expected_masters)
107
108             self.assertEqual(buildbot_data, expected_json)
109         finally:
110             buildershandler.fetch_json = old_fetch_json
111
112     def test_fetch_buildbot_data_failure(self):
113         try:
114             fetched_urls = []
115
116             def fake_fetch_json(url):
117                 fetched_urls.append(url)
118
119                 if url == 'http://chrome-build-extract.appspot.com/get_master/chromium.webkit':
120                     return None
121
122                 if url == 'http://chrome-build-extract.appspot.com/get_master/chromium.gpu':
123                     return {
124                         'builders': {
125                             'Win GPU': None, 'Win Empty': None,
126                         }
127                     }
128
129                 if url == 'http://chrome-build-extract.appspot.com/get_master/chromium.fyi':
130                     return {
131                         'builders': {
132                             'Mac FYI': None,
133                         }
134                     }
135
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'):
138                     return {
139                         'builds': [
140                             {'steps': []},
141                         ],
142                     }
143
144                 logging.error('Cannot fetch fake url: %s' % url)
145
146             old_fetch_json = buildershandler.fetch_json
147             buildershandler.fetch_json = fake_fetch_json
148
149             masters = [
150                 {'name': 'ChromiumGPU', 'url_name': 'chromium.gpu'},
151                 {'name': 'ChromiumWebkit', 'url_name': 'chromium.webkit'},
152                 {'name': 'ChromiumFYI', 'url_name': 'chromium.fyi'},
153             ]
154
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',
160             ]
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))
164
165         finally:
166             buildershandler.fetch_json = old_fetch_json
167
168
169 if __name__ == '__main__':
170     unittest.main()