| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (C) 2012 Google Inc. All rights reserved. | 2 # Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 def test_cached_build_json_url(self): | 44 def test_cached_build_json_url(self): |
| 45 self.assertEqual(buildershandler.cached_build_json_url('http://base', 'd
ummybuilder', 12345), 'http://base/json/builders/dummybuilder/builds/12345') | 45 self.assertEqual(buildershandler.cached_build_json_url('http://base', 'd
ummybuilder', 12345), 'http://base/json/builders/dummybuilder/builds/12345') |
| 46 self.assertEqual(buildershandler.cached_build_json_url('http://base', 'd
ummybuilder', '12345'), 'http://base/json/builders/dummybuilder/builds/12345') | 46 self.assertEqual(buildershandler.cached_build_json_url('http://base', 'd
ummybuilder', '12345'), 'http://base/json/builders/dummybuilder/builds/12345') |
| 47 | 47 |
| 48 def test_get_latest_build(self): | 48 def test_get_latest_build(self): |
| 49 build_data = {'cachedBuilds': ['1', '2', '3'], | 49 build_data = {'cachedBuilds': ['1', '2', '3'], |
| 50 'currentBuilds': ['3'], | 50 'currentBuilds': ['3'], |
| 51 'basedir': 'fake'} | 51 'basedir': 'fake'} |
| 52 latest_build = buildershandler.get_latest_build(build_data) | 52 latest_build = buildershandler.get_latest_build(build_data) |
| 53 | |
| 54 self.assertEqual(latest_build, '2') | 53 self.assertEqual(latest_build, '2') |
| 55 | 54 |
| 56 build_data = {'cachedBuilds': [], | 55 build_data = {'cachedBuilds': [], |
| 57 'currentBuilds': ['1', '2', '3'], | 56 'currentBuilds': ['1', '2', '3'], |
| 58 'basedir': 'fake'} | 57 'basedir': 'fake'} |
| 59 latest_build = buildershandler.get_latest_build(build_data) | 58 latest_build = buildershandler.get_latest_build(build_data) |
| 60 | |
| 61 self.assertEqual(latest_build, '1') | 59 self.assertEqual(latest_build, '1') |
| 62 | 60 |
| 63 build_data = {'cachedBuilds': ['1', '2', '3'], | 61 build_data = {'cachedBuilds': ['1', '2', '3'], |
| 64 'currentBuilds': ['1', '2', '3'], | 62 'currentBuilds': ['1', '2', '3'], |
| 65 'basedir': 'fake'} | 63 'basedir': 'fake'} |
| 66 latest_build = buildershandler.get_latest_build(build_data) | 64 latest_build = buildershandler.get_latest_build(build_data) |
| 67 | |
| 68 self.assertEqual(latest_build, '1') | 65 self.assertEqual(latest_build, '1') |
| 69 | 66 |
| 70 build_data = {'cachedBuilds': [], | 67 build_data = {'cachedBuilds': [], |
| 71 'currentBuilds': [], | 68 'currentBuilds': [], |
| 72 'basedir': 'fake'} | 69 'basedir': 'fake'} |
| 73 latest_build = buildershandler.get_latest_build(build_data) | 70 latest_build = buildershandler.get_latest_build(build_data) |
| 71 self.assertEqual(latest_build, None) |
| 74 | 72 |
| 75 self.assertEqual(latest_build, None) | 73 long_list = map(lambda x: str(x), xrange(1000, 1200)) |
| 74 current_build = long_list[-1] |
| 75 build_data = {'cachedBuilds': long_list[:], |
| 76 'currentBuilds': [current_build], |
| 77 'basedir': 'fake'} |
| 78 latest_build = buildershandler.get_latest_build(build_data) |
| 79 self.assertEqual(latest_build, long_list[-2]) |
| 76 | 80 |
| 77 def test_fetch_buildbot_data(self): | 81 def test_fetch_buildbot_data(self): |
| 78 try: | 82 try: |
| 79 fetched_urls = [] | 83 fetched_urls = [] |
| 80 | 84 |
| 81 def fake_fetch_json(url): | 85 def fake_fetch_json(url): |
| 82 fetched_urls.append(url) | 86 fetched_urls.append(url) |
| 83 if url == 'http://build.chromium.org/p/chromium.webkit/json/buil
ders': | 87 if url == 'http://build.chromium.org/p/chromium.webkit/json/buil
ders': |
| 84 return {'WebKit Win': None, 'WebKit Linux': None, 'WebKit Ma
c': None, 'WebKit Empty': None} | 88 return {'WebKit Win': None, 'WebKit Linux': None, 'WebKit Ma
c': None, 'WebKit Empty': None} |
| 85 | 89 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 expected_json = buildershandler.dump_json(expected_masters) | 137 expected_json = buildershandler.dump_json(expected_masters) |
| 134 | 138 |
| 135 self.assertEqual(buildbot_data, expected_json) | 139 self.assertEqual(buildbot_data, expected_json) |
| 136 | 140 |
| 137 finally: | 141 finally: |
| 138 buildershandler.fetch_json = old_fetch_json | 142 buildershandler.fetch_json = old_fetch_json |
| 139 | 143 |
| 140 | 144 |
| 141 if __name__ == '__main__': | 145 if __name__ == '__main__': |
| 142 unittest.main() | 146 unittest.main() |
| OLD | NEW |