| 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 from datetime import datetime | 5 from datetime import datetime |
| 6 from datetime import timedelta | 6 from datetime import timedelta |
| 7 import json |
| 8 |
| 7 import webapp2 | 9 import webapp2 |
| 8 | 10 |
| 9 from handlers import try_job_dashboard | 11 from handlers import try_job_dashboard |
| 10 from model.wf_try_job_data import WfTryJobData | 12 from model.wf_try_job_data import WfTryJobData |
| 11 | 13 |
| 12 from testing_utils import testing | 14 from testing_utils import testing |
| 13 | 15 |
| 14 | 16 |
| 15 class TryJobDashboardTest(testing.AppengineTestCase): | 17 class TryJobDashboardTest(testing.AppengineTestCase): |
| 16 app_module = webapp2.WSGIApplication([ | 18 app_module = webapp2.WSGIApplication([ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 41 try_job_dashboard._FormatDuration(datetime(2016, 1, 2, 1, 2, 3), None), | 43 try_job_dashboard._FormatDuration(datetime(2016, 1, 2, 1, 2, 3), None), |
| 42 try_job_dashboard.NOT_AVAILABLE) | 44 try_job_dashboard.NOT_AVAILABLE) |
| 43 self.assertEqual( | 45 self.assertEqual( |
| 44 try_job_dashboard._FormatDuration(None, datetime(2016, 1, 2, 1, 2, 3)), | 46 try_job_dashboard._FormatDuration(None, datetime(2016, 1, 2, 1, 2, 3)), |
| 45 try_job_dashboard.NOT_AVAILABLE) | 47 try_job_dashboard.NOT_AVAILABLE) |
| 46 self.assertEqual( | 48 self.assertEqual( |
| 47 try_job_dashboard._FormatDuration(datetime(2016, 1, 2, 1, 2, 3), | 49 try_job_dashboard._FormatDuration(datetime(2016, 1, 2, 1, 2, 3), |
| 48 datetime(2016, 1, 2, 1, 2, 4)), | 50 datetime(2016, 1, 2, 1, 2, 4)), |
| 49 '00:00:01') | 51 '00:00:01') |
| 50 | 52 |
| 53 def testPrepareBuildbucketResponseForDisplayNoData(self): |
| 54 self.assertEqual( |
| 55 try_job_dashboard._PrepareBuildbucketResponseForDisplay(None), |
| 56 None) |
| 57 self.assertEqual( |
| 58 try_job_dashboard._PrepareBuildbucketResponseForDisplay({}), |
| 59 {}) |
| 60 |
| 61 def testPrepareBuildbucketResponseForDisplayWithJson(self): |
| 62 properties = { |
| 63 'a': 1, |
| 64 'b': 2 |
| 65 } |
| 66 buildbucket_response = { |
| 67 'has_json': json.dumps(properties), |
| 68 'blabla': 'blabla' |
| 69 } |
| 70 self.assertEqual( |
| 71 try_job_dashboard._PrepareBuildbucketResponseForDisplay( |
| 72 buildbucket_response), |
| 73 { |
| 74 'blabla': 'blabla', |
| 75 'has_json': properties |
| 76 }) |
| 77 |
| 51 def testGet(self): | 78 def testGet(self): |
| 52 try_job_in_progress = WfTryJobData.Create(1) | 79 try_job_in_progress = WfTryJobData.Create(1) |
| 53 try_job_in_progress.master_name = 'm' | 80 try_job_in_progress.master_name = 'm' |
| 54 try_job_in_progress.builder_name = 'b' | 81 try_job_in_progress.builder_name = 'b' |
| 55 try_job_in_progress.build_number = 1 | 82 try_job_in_progress.build_number = 1 |
| 56 try_job_in_progress.try_job_type = 'compile' | 83 try_job_in_progress.try_job_type = 'compile' |
| 57 try_job_in_progress.start_time = datetime(2016, 5, 4, 0, 0, 1) | 84 try_job_in_progress.start_time = datetime(2016, 5, 4, 0, 0, 1) |
| 58 try_job_in_progress.request_time = datetime(2016, 5, 4, 0, 0, 0) | 85 try_job_in_progress.request_time = datetime(2016, 5, 4, 0, 0, 0) |
| 59 try_job_in_progress.try_job_url = 'url1' | 86 try_job_in_progress.try_job_url = 'url1' |
| 87 try_job_in_progress.last_buildbucket_response = {'status': 'STARTED'} |
| 60 try_job_in_progress.put() | 88 try_job_in_progress.put() |
| 61 | 89 |
| 62 try_job_with_error = WfTryJobData.Create(2) | 90 try_job_with_error = WfTryJobData.Create(2) |
| 63 try_job_with_error.master_name = 'm' | 91 try_job_with_error.master_name = 'm' |
| 64 try_job_with_error.builder_name = 'b' | 92 try_job_with_error.builder_name = 'b' |
| 65 try_job_with_error.build_number = 2 | 93 try_job_with_error.build_number = 2 |
| 66 try_job_with_error.try_job_type = 'compile' | 94 try_job_with_error.try_job_type = 'compile' |
| 67 try_job_with_error.start_time = datetime(2016, 5, 4, 0, 0, 1) | 95 try_job_with_error.start_time = datetime(2016, 5, 4, 0, 0, 1) |
| 68 try_job_with_error.request_time = datetime(2016, 5, 4, 0, 0, 0) | 96 try_job_with_error.request_time = datetime(2016, 5, 4, 0, 0, 0) |
| 69 try_job_with_error.end_time = datetime(2016, 5, 4, 0, 0, 2) | 97 try_job_with_error.end_time = datetime(2016, 5, 4, 0, 0, 2) |
| 70 try_job_with_error.try_job_url = 'url2' | 98 try_job_with_error.try_job_url = 'url2' |
| 71 try_job_with_error.error = { | 99 try_job_with_error.error = { |
| 72 'message': 'some error', | 100 'message': 'some error', |
| 73 'reason': 'some reason' | 101 'reason': 'some reason' |
| 74 } | 102 } |
| 103 try_job_with_error.last_buildbucket_response = { |
| 104 'failure_reason': 'INFRA_FAILURE' |
| 105 } |
| 75 try_job_with_error.put() | 106 try_job_with_error.put() |
| 76 | 107 |
| 77 try_job_completed = WfTryJobData.Create(3) | 108 try_job_completed = WfTryJobData.Create(3) |
| 78 try_job_completed.master_name = 'm' | 109 try_job_completed.master_name = 'm' |
| 79 try_job_completed.builder_name = 'b' | 110 try_job_completed.builder_name = 'b' |
| 80 try_job_completed.build_number = 3 | 111 try_job_completed.build_number = 3 |
| 81 try_job_completed.try_job_type = 'compile' | 112 try_job_completed.try_job_type = 'compile' |
| 82 try_job_completed.start_time = datetime(2016, 5, 4, 0, 0, 1) | 113 try_job_completed.start_time = datetime(2016, 5, 4, 0, 0, 1) |
| 83 try_job_completed.request_time = datetime(2016, 5, 4, 0, 0, 0) | 114 try_job_completed.request_time = datetime(2016, 5, 4, 0, 0, 0) |
| 84 try_job_completed.end_time = datetime(2016, 5, 4, 0, 0, 2) | 115 try_job_completed.end_time = datetime(2016, 5, 4, 0, 0, 2) |
| 85 try_job_completed.try_job_url = 'url3' | 116 try_job_completed.try_job_url = 'url3' |
| 86 try_job_completed.culprits = { | 117 try_job_completed.culprits = { |
| 87 'compile': { | 118 'compile': { |
| 88 '12345': 'failed' | 119 '12345': 'failed' |
| 89 } | 120 } |
| 90 } | 121 } |
| 122 try_job_completed.last_buildbucket_response = { |
| 123 'status': 'COMPLETED' |
| 124 } |
| 91 try_job_completed.put() | 125 try_job_completed.put() |
| 92 | 126 |
| 93 expected_try_job_in_progress_display_data = { | 127 expected_try_job_in_progress_display_data = { |
| 94 'master_name': 'm', | 128 'master_name': 'm', |
| 95 'builder_name': 'b', | 129 'builder_name': 'b', |
| 96 'build_number': 1, | 130 'build_number': 1, |
| 97 'try_job_type': 'compile', | 131 'try_job_type': 'compile', |
| 98 'request_time': '2016-05-04 00:00:00 UTC', | 132 'request_time': '2016-05-04 00:00:00 UTC', |
| 99 'try_job_url': 'url1', | 133 'try_job_url': 'url1', |
| 100 'status': 'running' | 134 'status': 'running', |
| 135 'last_buildbucket_response': '{"status": "STARTED"}' |
| 101 } | 136 } |
| 102 | 137 |
| 103 expected_try_job_with_error_display_data = { | 138 expected_try_job_with_error_display_data = { |
| 104 'master_name': 'm', | 139 'master_name': 'm', |
| 105 'builder_name': 'b', | 140 'builder_name': 'b', |
| 106 'build_number': 2, | 141 'build_number': 2, |
| 107 'try_job_type': 'compile', | 142 'try_job_type': 'compile', |
| 108 'request_time': '2016-05-04 00:00:00 UTC', | 143 'request_time': '2016-05-04 00:00:00 UTC', |
| 109 'try_job_url': 'url2', | 144 'try_job_url': 'url2', |
| 110 'error': 'some error', | 145 'error': 'some error', |
| 146 'last_buildbucket_response': '{"failure_reason": "INFRA_FAILURE"}' |
| 111 } | 147 } |
| 112 | 148 |
| 113 expected_try_job_completed_display_data = { | 149 expected_try_job_completed_display_data = { |
| 114 'master_name': 'm', | 150 'master_name': 'm', |
| 115 'builder_name': 'b', | 151 'builder_name': 'b', |
| 116 'build_number': 3, | 152 'build_number': 3, |
| 117 'try_job_type': 'compile', | 153 'try_job_type': 'compile', |
| 118 'request_time': '2016-05-04 00:00:00 UTC', | 154 'request_time': '2016-05-04 00:00:00 UTC', |
| 119 'try_job_url': 'url3', | 155 'try_job_url': 'url3', |
| 120 'culprit_found': True | 156 'culprit_found': True, |
| 157 'last_buildbucket_response': '{"status": "COMPLETED"}' |
| 121 } | 158 } |
| 122 | 159 |
| 123 response = self.test_app.get( | 160 response = self.test_app.get( |
| 124 '/try-job-dashboard?format=json&start_date=2016-05-03') | 161 '/try-job-dashboard?format=json&start_date=2016-05-03') |
| 125 response_data = response.json_body | 162 response_data = response.json_body |
| 126 try_jobs_in_progress = response_data.get('try_jobs_in_progress') | 163 try_jobs_in_progress = response_data.get('try_jobs_in_progress') |
| 127 try_jobs_with_error = response_data.get('try_jobs_with_error') | 164 try_jobs_with_error = response_data.get('try_jobs_with_error') |
| 128 successfully_completed_try_jobs = response_data.get( | 165 successfully_completed_try_jobs = response_data.get( |
| 129 'successfully_completed_try_jobs') | 166 'successfully_completed_try_jobs') |
| 130 | 167 |
| 131 self.assertEqual(response.status_int, 200) | 168 self.assertEqual(response.status_int, 200) |
| 132 self.validateTryJobDisplayData( | 169 self.validateTryJobDisplayData( |
| 133 [expected_try_job_in_progress_display_data], | 170 [expected_try_job_in_progress_display_data], |
| 134 try_jobs_in_progress) | 171 try_jobs_in_progress) |
| 135 self.validateTryJobDisplayData( | 172 self.validateTryJobDisplayData( |
| 136 [expected_try_job_with_error_display_data], | 173 [expected_try_job_with_error_display_data], |
| 137 try_jobs_with_error) | 174 try_jobs_with_error) |
| 138 self.validateTryJobDisplayData( | 175 self.validateTryJobDisplayData( |
| 139 [expected_try_job_completed_display_data], | 176 [expected_try_job_completed_display_data], |
| 140 successfully_completed_try_jobs) | 177 successfully_completed_try_jobs) |
| 141 | |
| OLD | NEW |