| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 datetime | 5 import datetime |
| 6 import json | 6 import json |
| 7 import mock | 7 import mock |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 from infra_libs import ts_mon |
| 10 from infra.services.builder_alerts import crbug_issues | 11 from infra.services.builder_alerts import crbug_issues |
| 11 | 12 |
| 12 from apiclient.errors import HttpError | 13 from apiclient.errors import HttpError |
| 13 | 14 |
| 14 | 15 |
| 15 CRBUG_ISSUES_LIST_TEST_REPLY = [ | 16 CRBUG_ISSUES_LIST_TEST_REPLY = [ |
| 16 { | 17 { |
| 17 'kind': 'projecthosting#issue', | 18 'kind': 'projecthosting#issue', |
| 18 'id': 123456, | 19 'id': 123456, |
| 19 'title': 'TestTitle', | 20 'title': 'TestTitle', |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 'canEdit': True, | 77 'canEdit': True, |
| 77 } | 78 } |
| 78 ] | 79 ] |
| 79 | 80 |
| 80 | 81 |
| 81 | 82 |
| 82 class CrbugIssuesQueryTest(unittest.TestCase): | 83 class CrbugIssuesQueryTest(unittest.TestCase): |
| 83 def setUp(self): | 84 def setUp(self): |
| 84 list_issues_mock = mock.Mock() | 85 list_issues_mock = mock.Mock() |
| 85 list_issues_mock.return_value = CRBUG_ISSUES_LIST_TEST_REPLY | 86 list_issues_mock.return_value = CRBUG_ISSUES_LIST_TEST_REPLY |
| 87 ts_mon.reset_for_unittest() |
| 86 | 88 |
| 87 self._patchers = [ | 89 self._patchers = [ |
| 88 mock.patch.object(crbug_issues, '_list_issues', list_issues_mock), | 90 mock.patch.object(crbug_issues, '_list_issues', list_issues_mock), |
| 89 mock.patch.object(crbug_issues, 'WHITELISTED_LABELS', | 91 mock.patch.object(crbug_issues, 'WHITELISTED_LABELS', |
| 90 {'sheriff-chromium': 'chromium', | 92 {'sheriff-chromium': 'chromium', |
| 91 'infra-troopers': 'trooper', | 93 'infra-troopers': 'trooper', |
| 92 'sheriff-foobar': 'foobar'}), | 94 'sheriff-foobar': 'foobar'}), |
| 93 ] | 95 ] |
| 94 for patcher in self._patchers: | 96 for patcher in self._patchers: |
| 95 patcher.start() | 97 patcher.start() |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 def test_correctly_deduplicates_results(self): | 194 def test_correctly_deduplicates_results(self): |
| 193 self.list_mock.execute.side_effect = [ | 195 self.list_mock.execute.side_effect = [ |
| 194 {'items': [{'id': 1}, {'id': 2}, {'id': 3}]}, | 196 {'items': [{'id': 1}, {'id': 2}, {'id': 3}]}, |
| 195 {'items': [{'id': 2}, {'id': 3}, {'id': 4}]}, | 197 {'items': [{'id': 2}, {'id': 3}, {'id': 4}]}, |
| 196 {}, | 198 {}, |
| 197 ] | 199 ] |
| 198 | 200 |
| 199 issues = crbug_issues._list_issues('test-account.json') | 201 issues = crbug_issues._list_issues('test-account.json') |
| 200 self.assertEqual(len(issues), 4) | 202 self.assertEqual(len(issues), 4) |
| 201 self.assertEqual([1, 2, 3, 4], [issue['id'] for issue in issues]) | 203 self.assertEqual([1, 2, 3, 4], [issue['id'] for issue in issues]) |
| OLD | NEW |