[Flakiness Dashboard] Remove everything Chromium from the builders.json-generating...
[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.webkit.org/json/builders':
58                     return {'Apple Mac SnowLeopard Tests': None, 'EFL Linux Builder': None, 'GTK Linux Tests': None}
59
60                 if url == 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests':
61                     return {'cachedBuilds': [1, 2], 'currentBuilds': []}
62                 if url == 'http://build.webkit.org/json/builders/EFL%20Linux%20Builder':
63                     return {'cachedBuilds': [1, 2, 3], 'currentBuilds': [3]}
64                 if url == 'http://build.webkit.org/json/builders/GTK%20Linux%20Tests':
65                     return {'cachedBuilds': [2], 'currentBuilds': []}
66
67                 if url == 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests/builds/2':
68                     return {'steps': [{'name': 'layout-test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]}
69                 if url == 'http://build.webkit.org/json/builders/EFL%20Linux%20Builder/builds/2':
70                     return {'steps': [{'name': 'compile'}]}
71                 if url == 'http://build.webkit.org/json/builders/GTK%20Linux%20Tests/builds/2':
72                     return {'steps': [{'name': 'layout-test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]}
73
74                 logging.error('Cannot fetch fake url: %s' % url)
75
76             generate_builders_json.fetch_json = dummy_fetch_json
77
78             masters = [
79                 {'name': 'webkit.org', 'url': 'http://build.webkit.org'},
80             ]
81
82             generate_builders_json.insert_builder_and_test_data(masters)
83
84             expected_fetched_urls = [
85                 'http://build.webkit.org/json/builders',
86                 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests',
87                 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests/builds/2',
88                 'http://build.webkit.org/json/builders/GTK%20Linux%20Tests',
89                 'http://build.webkit.org/json/builders/GTK%20Linux%20Tests/builds/2',
90                 'http://build.webkit.org/json/builders/EFL%20Linux%20Builder',
91                 'http://build.webkit.org/json/builders/EFL%20Linux%20Builder/builds/2']
92             self.assertEqual(fetched_urls, expected_fetched_urls)
93
94             expected_masters = [
95                 {
96                     'url': 'http://build.webkit.org',
97                     'tests': {
98                         'layout-tests': {'builders': ['Apple Mac SnowLeopard Tests', 'GTK Linux Tests']},
99                     },
100                     'name': 'webkit.org'
101                 },
102             ]
103             self.assertEqual(masters, expected_masters)
104
105         finally:
106             generate_builders_json.fetch_json = old_fetch_json
107
108 if __name__ == '__main__':
109     unittest.main()