| 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 webapp2 | 7 import webapp2 |
| 8 | 8 |
| 9 from handlers import try_job_dashboard | 9 from handlers import try_job_dashboard |
| 10 from model.wf_try_job_data import WfTryJobData | 10 from model.wf_try_job_data import WfTryJobData |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 def testRemoveMicrosecondsFromDelta(self): | 37 def testRemoveMicrosecondsFromDelta(self): |
| 38 date1 = datetime(2016, 5, 1, 1, 1, 1, 1) | 38 date1 = datetime(2016, 5, 1, 1, 1, 1, 1) |
| 39 date2 = datetime(2016, 5, 1, 1, 1, 1, 2) | 39 date2 = datetime(2016, 5, 1, 1, 1, 1, 2) |
| 40 delta = date2 - date1 | 40 delta = date2 - date1 |
| 41 | 41 |
| 42 self.assertEqual( | 42 self.assertEqual( |
| 43 try_job_dashboard._RemoveMicrosecondsFromDelta(delta).microseconds, | 43 try_job_dashboard._RemoveMicrosecondsFromDelta(delta).microseconds, |
| 44 0) | 44 0) |
| 45 | 45 |
| 46 def testFormatDuration(self): |
| 47 self.assertEqual(try_job_dashboard._FormatDuration(None, None), |
| 48 try_job_dashboard.NOT_AVAILABLE) |
| 49 self.assertEqual( |
| 50 try_job_dashboard._FormatDuration(datetime(2016, 1, 2, 1, 2, 3), None), |
| 51 try_job_dashboard.NOT_AVAILABLE) |
| 52 self.assertEqual( |
| 53 try_job_dashboard._FormatDuration(None, datetime(2016, 1, 2, 1, 2, 3)), |
| 54 try_job_dashboard.NOT_AVAILABLE) |
| 55 self.assertEqual( |
| 56 try_job_dashboard._FormatDuration(datetime(2016, 1, 2, 1, 2, 3), |
| 57 datetime(2016, 1, 2, 1, 2, 4)), |
| 58 '00:00:01') |
| 59 |
| 46 def testFormatTimedelta(self): | 60 def testFormatTimedelta(self): |
| 47 self.assertIsNone(try_job_dashboard._FormatTimedelta(None)) | |
| 48 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 1)), | 61 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 1)), |
| 49 '00:00:01') | 62 '00:00:01') |
| 50 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 60)), | 63 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 60)), |
| 51 '00:01:00') | 64 '00:01:00') |
| 52 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 3600)), | 65 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 3600)), |
| 53 '01:00:00') | 66 '01:00:00') |
| 54 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 0, 1)), | 67 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 0, 1)), |
| 55 '00:00:00') | 68 '00:00:00') |
| 56 | 69 |
| 57 def testFormatDatetime(self): | 70 def testFormatDatetime(self): |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 '12345': 'failed' | 113 '12345': 'failed' |
| 101 } | 114 } |
| 102 } | 115 } |
| 103 try_job_completed.put() | 116 try_job_completed.put() |
| 104 | 117 |
| 105 expected_try_job_in_progress_display_data = { | 118 expected_try_job_in_progress_display_data = { |
| 106 'master_name': 'm', | 119 'master_name': 'm', |
| 107 'builder_name': 'b', | 120 'builder_name': 'b', |
| 108 'build_number': 1, | 121 'build_number': 1, |
| 109 'try_job_type': 'compile', | 122 'try_job_type': 'compile', |
| 110 'start_time': '2016-05-04 00:00:01 UTC', | |
| 111 'request_time': '2016-05-04 00:00:00 UTC', | 123 'request_time': '2016-05-04 00:00:00 UTC', |
| 112 'try_job_url': 'url1', | 124 'try_job_url': 'url1', |
| 113 'status': 'running' | 125 'status': 'running' |
| 114 } | 126 } |
| 115 | 127 |
| 116 expected_try_job_with_error_display_data = { | 128 expected_try_job_with_error_display_data = { |
| 117 'master_name': 'm', | 129 'master_name': 'm', |
| 118 'builder_name': 'b', | 130 'builder_name': 'b', |
| 119 'build_number': 2, | 131 'build_number': 2, |
| 120 'try_job_type': 'compile', | 132 'try_job_type': 'compile', |
| 121 'start_time': '2016-05-04 00:00:01 UTC', | |
| 122 'request_time': '2016-05-04 00:00:00 UTC', | 133 'request_time': '2016-05-04 00:00:00 UTC', |
| 123 'end_time': '2016-05-04 00:00:02 UTC', | |
| 124 'try_job_url': 'url2', | 134 'try_job_url': 'url2', |
| 125 'error': 'some error', | 135 'error': 'some error', |
| 126 } | 136 } |
| 127 | 137 |
| 128 expected_try_job_completed_display_data = { | 138 expected_try_job_completed_display_data = { |
| 129 'master_name': 'm', | 139 'master_name': 'm', |
| 130 'builder_name': 'b', | 140 'builder_name': 'b', |
| 131 'build_number': 3, | 141 'build_number': 3, |
| 132 'try_job_type': 'compile', | 142 'try_job_type': 'compile', |
| 133 'start_time': '2016-05-04 00:00:01 UTC', | |
| 134 'request_time': '2016-05-04 00:00:00 UTC', | 143 'request_time': '2016-05-04 00:00:00 UTC', |
| 135 'end_time': '2016-05-04 00:00:02 UTC', | |
| 136 'try_job_url': 'url3', | 144 'try_job_url': 'url3', |
| 137 'culprit_found': True | 145 'culprit_found': True |
| 138 } | 146 } |
| 139 | 147 |
| 140 response = self.test_app.get( | 148 response = self.test_app.get( |
| 141 '/try-job-dashboard?format=json&start_date=2016-05-03') | 149 '/try-job-dashboard?format=json&start_date=2016-05-03') |
| 142 response_data = response.json_body | 150 response_data = response.json_body |
| 143 try_jobs_in_progress = response_data.get('try_jobs_in_progress') | 151 try_jobs_in_progress = response_data.get('try_jobs_in_progress') |
| 144 try_jobs_with_error = response_data.get('try_jobs_with_error') | 152 try_jobs_with_error = response_data.get('try_jobs_with_error') |
| 145 successfully_completed_try_jobs = response_data.get( | 153 successfully_completed_try_jobs = response_data.get( |
| 146 'successfully_completed_try_jobs') | 154 'successfully_completed_try_jobs') |
| 147 | 155 |
| 148 self.assertEqual(response.status_int, 200) | 156 self.assertEqual(response.status_int, 200) |
| 149 self.validateTryJobDisplayData( | 157 self.validateTryJobDisplayData( |
| 150 [expected_try_job_in_progress_display_data], | 158 [expected_try_job_in_progress_display_data], |
| 151 try_jobs_in_progress) | 159 try_jobs_in_progress) |
| 152 self.validateTryJobDisplayData( | 160 self.validateTryJobDisplayData( |
| 153 [expected_try_job_with_error_display_data], | 161 [expected_try_job_with_error_display_data], |
| 154 try_jobs_with_error) | 162 try_jobs_with_error) |
| 155 self.validateTryJobDisplayData( | 163 self.validateTryJobDisplayData( |
| 156 [expected_try_job_completed_display_data], | 164 [expected_try_job_completed_display_data], |
| 157 successfully_completed_try_jobs) | 165 successfully_completed_try_jobs) |
| 158 | 166 |
| OLD | NEW |