| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import logging | 6 import logging |
| 7 import unittest | 7 import unittest |
| 8 import urllib2 | 8 import urllib2 |
| 9 | 9 |
| 10 from webkitpy.common.net.rietveld import filter_latest_jobs | 10 from webkitpy.common.net.rietveld import filter_latest_jobs |
| 11 from webkitpy.common.net.rietveld import get_latest_try_job_results | 11 from webkitpy.common.net.rietveld import get_latest_try_job_results |
| 12 from webkitpy.common.net.rietveld import latest_try_jobs | 12 from webkitpy.common.net.rietveld import latest_try_jobs |
| 13 from webkitpy.common.net.rietveld import TryJob | 13 from webkitpy.common.net.buildbot import Build |
| 14 from webkitpy.common.net.web_mock import MockWeb | 14 from webkitpy.common.net.web_mock import MockWeb |
| 15 from webkitpy.common.system.outputcapture import OutputCapture | 15 from webkitpy.common.system.outputcapture import OutputCapture |
| 16 | 16 |
| 17 | 17 |
| 18 _log = logging.getLogger(__name__) | 18 _log = logging.getLogger(__name__) |
| 19 | 19 |
| 20 | 20 |
| 21 class RietveldTest(unittest.TestCase): | 21 class RietveldTest(unittest.TestCase): |
| 22 | 22 |
| 23 def setUp(self): | 23 def setUp(self): |
| (...skipping 28 matching lines...) Expand all Loading... |
| 52 'result': 0 | 52 'result': 0 |
| 53 }, | 53 }, |
| 54 ], | 54 ], |
| 55 }), | 55 }), |
| 56 'https://codereview.chromium.org/api/11113333': 'my non-JSON content
s', | 56 'https://codereview.chromium.org/api/11113333': 'my non-JSON content
s', |
| 57 }) | 57 }) |
| 58 | 58 |
| 59 def test_latest_try_jobs(self): | 59 def test_latest_try_jobs(self): |
| 60 self.assertEqual( | 60 self.assertEqual( |
| 61 latest_try_jobs(11112222, ('bar-builder', 'other-builder'), self.web
), | 61 latest_try_jobs(11112222, ('bar-builder', 'other-builder'), self.web
), |
| 62 [TryJob('bar-builder', 60)]) | 62 [Build('bar-builder', 60)]) |
| 63 | 63 |
| 64 def test_latest_try_jobs_http_error(self): | 64 def test_latest_try_jobs_http_error(self): |
| 65 def raise_error(_): | 65 def raise_error(_): |
| 66 raise urllib2.URLError('Some request error message') | 66 raise urllib2.URLError('Some request error message') |
| 67 self.web.get_binary = raise_error | 67 self.web.get_binary = raise_error |
| 68 oc = OutputCapture() | 68 oc = OutputCapture() |
| 69 try: | 69 try: |
| 70 oc.capture_output() | 70 oc.capture_output() |
| 71 self.assertEqual(latest_try_jobs(11112222, ('bar-builder',), self.we
b), []) | 71 self.assertEqual(latest_try_jobs(11112222, ('bar-builder',), self.we
b), []) |
| 72 finally: | 72 finally: |
| 73 _, _, logs = oc.restore_output() | 73 _, _, logs = oc.restore_output() |
| 74 self.assertEqual(logs, 'Request failed to URL: https://codereview.chromi
um.org/api/11112222\n') | 74 self.assertEqual(logs, 'Request failed to URL: https://codereview.chromi
um.org/api/11112222\n') |
| 75 | 75 |
| 76 def test_latest_try_jobs_non_json_response(self): | 76 def test_latest_try_jobs_non_json_response(self): |
| 77 oc = OutputCapture() | 77 oc = OutputCapture() |
| 78 try: | 78 try: |
| 79 oc.capture_output() | 79 oc.capture_output() |
| 80 self.assertEqual(latest_try_jobs(11113333, ('bar-builder',), self.we
b), []) | 80 self.assertEqual(latest_try_jobs(11113333, ('bar-builder',), self.we
b), []) |
| 81 finally: | 81 finally: |
| 82 _, _, logs = oc.restore_output() | 82 _, _, logs = oc.restore_output() |
| 83 self.assertEqual(logs, 'Invalid JSON: my non-JSON contents\n') | 83 self.assertEqual(logs, 'Invalid JSON: my non-JSON contents\n') |
| 84 | 84 |
| 85 def test_latest_try_jobs_with_patchset(self): | 85 def test_latest_try_jobs_with_patchset(self): |
| 86 self.assertEqual( | 86 self.assertEqual( |
| 87 latest_try_jobs(11112222, ('bar-builder', 'other-builder'), self.web
, patchset_number=2), | 87 latest_try_jobs(11112222, ('bar-builder', 'other-builder'), self.web
, patchset_number=2), |
| 88 [TryJob('bar-builder', 50)]) | 88 [Build('bar-builder', 50)]) |
| 89 | 89 |
| 90 def test_latest_try_jobs_no_relevant_builders(self): | 90 def test_latest_try_jobs_no_relevant_builders(self): |
| 91 self.assertEqual(latest_try_jobs(11112222, ('foo', 'bar'), self.web), []
) | 91 self.assertEqual(latest_try_jobs(11112222, ('foo', 'bar'), self.web), []
) |
| 92 | 92 |
| 93 def test_get_latest_try_job_results(self): | 93 def test_get_latest_try_job_results(self): |
| 94 self.assertEqual(get_latest_try_job_results(11112222, self.web), {'foo-b
uilder': 1, 'bar-builder': 0}) | 94 self.assertEqual(get_latest_try_job_results(11112222, self.web), {'foo-b
uilder': 1, 'bar-builder': 0}) |
| 95 | 95 |
| 96 def test_filter_latest_jobs_empty(self): | 96 def test_filter_latest_jobs_empty(self): |
| 97 self.assertEqual(filter_latest_jobs([]), []) | 97 self.assertEqual(filter_latest_jobs([]), []) |
| 98 | 98 |
| 99 def test_filter_latest_jobs_higher_build_first(self): | 99 def test_filter_latest_jobs_higher_build_first(self): |
| 100 self.assertEqual( | 100 self.assertEqual( |
| 101 filter_latest_jobs([ | 101 filter_latest_jobs([ |
| 102 TryJob('foo', 5), | 102 Build('foo', 5), |
| 103 TryJob('foo', 3), | 103 Build('foo', 3), |
| 104 TryJob('bar', 5), | 104 Build('bar', 5), |
| 105 ]), | 105 ]), |
| 106 [ | 106 [ |
| 107 TryJob('foo', 5), | 107 Build('foo', 5), |
| 108 TryJob('bar', 5), | 108 Build('bar', 5), |
| 109 ]) | 109 ]) |
| 110 | 110 |
| 111 def test_filter_latest_jobs_higher_build_last(self): | 111 def test_filter_latest_jobs_higher_build_last(self): |
| 112 self.assertEqual( | 112 self.assertEqual( |
| 113 filter_latest_jobs([ | 113 filter_latest_jobs([ |
| 114 TryJob('foo', 3), | 114 Build('foo', 3), |
| 115 TryJob('bar', 5), | 115 Build('bar', 5), |
| 116 TryJob('foo', 5), | 116 Build('foo', 5), |
| 117 ]), | 117 ]), |
| 118 [ | 118 [ |
| 119 TryJob('bar', 5), | 119 Build('bar', 5), |
| 120 TryJob('foo', 5), | 120 Build('foo', 5), |
| 121 ]) | 121 ]) |
| OLD | NEW |