generate_builders_json_unittest.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. import logging
  30. import unittest
  31. import generate_builders_json
  32. class GenerateBuildersJsonTest(unittest.TestCase):
  33. def test_master_json_url(self):
  34. self.assertEqual(generate_builders_json.master_json_url('http://base'), 'http://base/json/builders')
  35. def test_builder_json_url(self):
  36. self.assertEqual(generate_builders_json.builder_json_url('http://base', 'dummybuilder'), 'http://base/json/builders/dummybuilder')
  37. def test_cached_build_json_url(self):
  38. self.assertEqual(generate_builders_json.cached_build_json_url('http://base', 'dummybuilder', 12345), 'http://base/json/builders/dummybuilder/builds/12345')
  39. self.assertEqual(generate_builders_json.cached_build_json_url('http://base', 'dummybuilder', '12345'), 'http://base/json/builders/dummybuilder/builds/12345')
  40. def test_generate_json_data(self):
  41. try:
  42. old_fetch_json = generate_builders_json.fetch_json
  43. fetched_urls = []
  44. def dummy_fetch_json(url):
  45. fetched_urls.append(url)
  46. if url == 'http://build.webkit.org/json/builders':
  47. return {'Apple Mac SnowLeopard Tests': None, 'EFL Linux Builder': None, 'GTK Linux Tests': None}
  48. if url == 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests':
  49. return {'cachedBuilds': [1, 2], 'currentBuilds': []}
  50. if url == 'http://build.webkit.org/json/builders/EFL%20Linux%20Builder':
  51. return {'cachedBuilds': [1, 2, 3], 'currentBuilds': [3]}
  52. if url == 'http://build.webkit.org/json/builders/GTK%20Linux%20Tests':
  53. return {'cachedBuilds': [2], 'currentBuilds': []}
  54. if url == 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests/builds/2':
  55. return {'steps': [{'name': 'layout-test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]}
  56. if url == 'http://build.webkit.org/json/builders/EFL%20Linux%20Builder/builds/2':
  57. return {'steps': [{'name': 'compile'}]}
  58. if url == 'http://build.webkit.org/json/builders/GTK%20Linux%20Tests/builds/2':
  59. return {'steps': [{'name': 'layout-test'}, {'name': 'archive_test_results'}, {'name': 'compile'}]}
  60. logging.error('Cannot fetch fake url: %s' % url)
  61. generate_builders_json.fetch_json = dummy_fetch_json
  62. masters = [
  63. {'name': 'webkit.org', 'url': 'http://build.webkit.org'},
  64. ]
  65. generate_builders_json.insert_builder_and_test_data(masters)
  66. expected_fetched_urls = [
  67. 'http://build.webkit.org/json/builders',
  68. 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests',
  69. 'http://build.webkit.org/json/builders/Apple%20Mac%20SnowLeopard%20Tests/builds/2',
  70. 'http://build.webkit.org/json/builders/GTK%20Linux%20Tests',
  71. 'http://build.webkit.org/json/builders/GTK%20Linux%20Tests/builds/2',
  72. 'http://build.webkit.org/json/builders/EFL%20Linux%20Builder',
  73. 'http://build.webkit.org/json/builders/EFL%20Linux%20Builder/builds/2']
  74. self.assertEqual(fetched_urls, expected_fetched_urls)
  75. expected_masters = [
  76. {
  77. 'url': 'http://build.webkit.org',
  78. 'tests': {
  79. 'layout-tests': {'builders': ['Apple Mac SnowLeopard Tests', 'GTK Linux Tests']},
  80. },
  81. 'name': 'webkit.org'
  82. },
  83. ]
  84. self.assertEqual(masters, expected_masters)
  85. finally:
  86. generate_builders_json.fetch_json = old_fetch_json
  87. if __name__ == '__main__':
  88. unittest.main()