OLD | NEW |
(Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import unittest |
| 6 |
| 7 import mock |
| 8 import webapp2 |
| 9 import webtest |
| 10 |
| 11 # pylint: disable=unused-import |
| 12 from dashboard import mock_oauth2_decorator |
| 13 # pylint: enable=unused-import |
| 14 |
| 15 from dashboard import bug_details |
| 16 from dashboard.common import testing_common |
| 17 from dashboard.models import try_job |
| 18 from dashboard.services import issue_tracker_service |
| 19 |
| 20 |
| 21 GET_ISSUE_DATA = { |
| 22 'owner': {'name': 'sullivan@chromium.org'}, |
| 23 'state': 'open', |
| 24 'status': 'Untriaged', |
| 25 'summary': 'Regression in sunspider', |
| 26 'published': '2017-02-17T23:08:44', |
| 27 } |
| 28 |
| 29 GET_COMMENTS_DATA = [ |
| 30 { |
| 31 'author': 'foo@chromium.org', |
| 32 'content': 'This is the first comment', |
| 33 'published': '2017-02-17T09:59:55', |
| 34 }, { |
| 35 'author': 'bar@chromium.org', |
| 36 'content': 'This is the second comment', |
| 37 'published': '2017-02-17T10:00:0', |
| 38 }, { |
| 39 'author': 'bugdroid1@chromium.org', |
| 40 'content': 'The following revision refers to this bug:\n' |
| 41 ' https://chromium.googlesource.com/chromium/src.git/+/' |
| 42 '9ac6e6466cc0df7e1a3ad4488c5c8bdc2db4da36\n\n' |
| 43 'Review-Url: https://codereview.chromium.org/2707483002\n\n', |
| 44 'published': '2017-02-17T23:08:44', |
| 45 } |
| 46 ] |
| 47 |
| 48 |
| 49 class BugDetailsHandlerTest(testing_common.TestCase): |
| 50 |
| 51 def setUp(self): |
| 52 super(BugDetailsHandlerTest, self).setUp() |
| 53 app = webapp2.WSGIApplication([( |
| 54 '/bug_details', bug_details.BugDetailsHandler)]) |
| 55 self.testapp = webtest.TestApp(app) |
| 56 |
| 57 # Mocks fetching bugs from issue tracker. |
| 58 @mock.patch('services.issue_tracker_service.discovery.build', |
| 59 mock.MagicMock()) |
| 60 @mock.patch.object( |
| 61 issue_tracker_service.IssueTrackerService, 'GetIssue', |
| 62 mock.MagicMock(return_value=GET_ISSUE_DATA)) |
| 63 @mock.patch.object( |
| 64 issue_tracker_service.IssueTrackerService, 'GetIssueComments', |
| 65 mock.MagicMock(return_value=GET_COMMENTS_DATA)) |
| 66 def testPost(self): |
| 67 try_job.TryJob( |
| 68 bug_id=12345, status='started', bot='win_perf', |
| 69 results_data={}).put() |
| 70 try_job.TryJob( |
| 71 bug_id=12345, status='failed', bot='android_bisect', |
| 72 results_data={'metric': 'foo'}).put() |
| 73 try_job.TryJob( |
| 74 bug_id=99999, status='failed', bot='win_perf', |
| 75 results_data={'metric': 'foo'}).put() |
| 76 response = self.testapp.post('/bug_details', {'bug_id': '12345'}) |
| 77 self.assertEqual( |
| 78 'Regression in sunspider', |
| 79 self.GetJsonValue(response, 'summary')) |
| 80 self.assertEqual( |
| 81 'sullivan@chromium.org', |
| 82 self.GetJsonValue(response, 'owner')) |
| 83 self.assertEqual( |
| 84 '2017-02-17T23:08:44', |
| 85 self.GetJsonValue(response, 'published')) |
| 86 self.assertEqual( |
| 87 'open', |
| 88 self.GetJsonValue(response, 'state')) |
| 89 self.assertEqual( |
| 90 'Untriaged', |
| 91 self.GetJsonValue(response, 'status')) |
| 92 comments = self.GetJsonValue(response, 'comments') |
| 93 self.assertEqual(3, len(comments)) |
| 94 self.assertEqual('This is the second comment', comments[1]['content']) |
| 95 self.assertItemsEqual( |
| 96 ['https://codereview.chromium.org/2707483002'], |
| 97 self.GetJsonValue(response, 'review_urls')) |
| 98 bisects = self.GetJsonValue(response, 'bisects') |
| 99 self.assertEqual(2, len(bisects)) |
| 100 self.assertEqual('started', bisects[0]['status']) |
| 101 self.assertIsNone(bisects[0]['metric']) |
| 102 self.assertEqual('failed', bisects[1]['status']) |
| 103 self.assertEqual('foo', bisects[1]['metric']) |
| 104 self.assertEqual('android_bisect', bisects[1]['bot']) |
| 105 |
| 106 |
| 107 if __name__ == '__main__': |
| 108 unittest.main() |
OLD | NEW |