Use xcrun to find path to make for Mac port
[WebKit-https.git] / Tools / TestResultServer / generate_builders_json_unittest.py
1 #!/usr/bin/env python
2 # Copyright (C) 2012 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #     * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 import logging
31 import unittest
32
33 import generate_builders_json
34
35
36 class GenerateBuildersJsonTest(unittest.TestCase):
37
38     def test_master_json_url(self):
39         self.assertEqual(generate_builders_json.master_json_url('http://base'), 'http://base/json/builders')
40
41     def test_builder_json_url(self):
42         self.assertEqual(generate_builders_json.builder_json_url('http://base', 'dummybuilder'), 'http://base/json/builders/dummybuilder')
43
44     def test_cached_build_json_url(self):
45         self.assertEqual(generate_builders_json.cached_build_json_url('http://base', 'dummybuilder', 12345), 'http://base/json/builders/dummybuilder/builds/12345')
46         self.assertEqual(generate_builders_json.cached_build_json_url('http://base', 'dummybuilder', '12345'), 'http://base/json/builders/dummybuilder/builds/12345')
47
48     def test_generate_json_data(self):
49         try:
50             old_fetch_json = generate_builders_json.fetch_json
51
52             fetched_urls = []
53
54             def dummy_fetch_json(url):
55                 fetched_urls.append(url)
56
57                 if url == 'http://build.chromium.org/p/chromium.webkit/json/builders':
58                     return {'WebKit Win': None, 'WebKit Linux': None, 'WebKit Mac': None}
59                 if url == 'http://build.webkit.org/json/builders':
60                     return {'Apple Mac SnowLeopard Tests': None, 'Chromium Mac Builder': None, 'GTK': None}
61
62                 if url == 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Linux':
63                     return {'cachedBuilds': [1, 2], 'currentBuilds': []}
64                 if url == 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Win':
65                     return {'cachedBuilds': [1, 2], 'currentBuilds': []}
66                 if url == 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Mac':
67                     return {'cachedBuilds': [1, 2], 'currentBuilds': []}
68                 if url == 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests':
69                     return {'cachedBuilds': [1, 2], 'currentBuilds': []}
70                 if url == 'http://build.webkit.org/json/builders/Chromium%20Mac%20Builder':
71                     return {'cachedBuilds': [1, 2, 3], 'currentBuilds': [3]}
72                 if url == 'http://build.webkit.org/json/builders/GTK':
73                     return {'cachedBuilds': [2], 'currentBuilds': []}
74
75                 if url == 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Linux/builds/2':
76                     return {'steps': [{'name': 'webkit_tests'}, {'name': 'browser_tests'}, {'name': 'mini_installer_test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]}
77                 if url == 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Win/builds/2':
78                     return {'steps': [{'name': 'webkit_tests'}, {'name': 'mini_installer_test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]}
79                 if url == 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Mac/builds/2':
80                     return {'steps': [{'name': 'browser_tests'}, {'name': 'mini_installer_test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]}
81                 if url == 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests/builds/2':
82                     return {'steps': [{'name': 'layout-test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]}
83                 if url == 'http://build.webkit.org/json/builders/Chromium%20Mac%20Builder/builds/2':
84                     return {'steps': [{'name': 'compile'}]}
85                 if url == 'http://build.webkit.org/json/builders/GTK/builds/2':
86                     return {'steps': [{'name': 'layout-test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]}
87
88                 logging.error('Cannot fetch fake url: %s' % url)
89
90             generate_builders_json.fetch_json = dummy_fetch_json
91
92             masters = [
93                 {'name': 'ChromiumWebkit', 'url': 'http://build.chromium.org/p/chromium.webkit'},
94                 {'name': 'webkit.org', 'url': 'http://build.webkit.org'},
95             ]
96
97             generate_builders_json.insert_builder_and_test_data(masters)
98
99             expected_fetched_urls = [
100                 'http://build.chromium.org/p/chromium.webkit/json/builders',
101                 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Linux',
102                 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Linux/builds/2',
103                 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Mac',
104                 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Mac/builds/2',
105                 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Win',
106                 'http://build.chromium.org/p/chromium.webkit/json/builders/WebKit%20Win/builds/2',
107                 'http://build.webkit.org/json/builders',
108                 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests',
109                 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests/builds/2',
110                 'http://build.webkit.org/json/builders/GTK',
111                 'http://build.webkit.org/json/builders/GTK/builds/2',
112                 'http://build.webkit.org/json/builders/Chromium%20Mac%20Builder',
113                 'http://build.webkit.org/json/builders/Chromium%20Mac%20Builder/builds/2']
114             self.assertEqual(fetched_urls, expected_fetched_urls)
115
116             expected_masters = [
117                 {
118                     'url': 'http://build.chromium.org/p/chromium.webkit',
119                     'tests': {
120                         'browser_tests': {'builders': ['WebKit Linux', 'WebKit Mac']},
121                         'mini_installer_test': {'builders': ['WebKit Linux', 'WebKit Mac', 'WebKit Win']},
122                         'layout-tests': {'builders': ['WebKit Linux', 'WebKit Win']}},
123                     'name': 'ChromiumWebkit'},
124                 {
125                     'url': 'http://build.webkit.org',
126                     'tests': {
127                         'layout-tests': {'builders': ['Apple Mac SnowLeopard Tests', 'GTK']}},
128                     'name': 'webkit.org'}]
129             self.assertEqual(masters, expected_masters)
130
131         finally:
132             generate_builders_json.fetch_json = old_fetch_json
133
134 if __name__ == '__main__':
135     unittest.main()