| OLD | NEW |
| (Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 from datetime import datetime |
| 6 from datetime import timedelta |
| 7 import webapp2 |
| 8 |
| 9 from handlers import try_job_dashboard |
| 10 from model.wf_try_job_data import WfTryJobData |
| 11 |
| 12 from testing_utils import testing |
| 13 |
| 14 |
| 15 class TryJobDashboardTest(testing.AppengineTestCase): |
| 16 app_module = webapp2.WSGIApplication([ |
| 17 ('/try-job-dashboard', try_job_dashboard.TryJobDashboard), |
| 18 ], debug=True) |
| 19 |
| 20 def validateTryJobDisplayData(self, expected_try_job_data_list, |
| 21 actual_try_job_data_list): |
| 22 self.assertEqual( |
| 23 len(expected_try_job_data_list), |
| 24 len(actual_try_job_data_list)) |
| 25 |
| 26 # Validates each field in each expected data dict matches those in each |
| 27 # actual data dict. Note order order matters in each list. Note a direct |
| 28 # list comparison is not possible since try jobs in progress will have |
| 29 # constantly-changing elapsed_time fields depending on the time the tests |
| 30 # are run, so we compare all other fields to avoid this. |
| 31 for i in range(len(expected_try_job_data_list)): |
| 32 expected_try_job_data = expected_try_job_data_list[i] |
| 33 actual_try_job_data = actual_try_job_data_list[i] |
| 34 |
| 35 for field, expected_data in expected_try_job_data.iteritems(): |
| 36 self.assertEqual(expected_data, actual_try_job_data.get(field)) |
| 37 |
| 38 def testRemoveMicrosecondsFromDelta(self): |
| 39 date1 = datetime(2016, 5, 1, 1, 1, 1, 1) |
| 40 date2 = datetime(2016, 5, 1, 1, 1, 1, 2) |
| 41 delta = date2 - date1 |
| 42 |
| 43 self.assertEqual( |
| 44 try_job_dashboard._RemoveMicrosecondsFromDelta(delta).microseconds, |
| 45 0) |
| 46 |
| 47 def testRemoveMicrosecondsFromDatetime(self): |
| 48 date = datetime(2016, 5, 1, 0, 0, 0, 12345) |
| 49 self.assertEqual( |
| 50 try_job_dashboard._RemoveMicrosecondsFromDatetime(date), |
| 51 datetime(2016, 5, 1, 0, 0, 0, 0)) |
| 52 self.assertIsNone(try_job_dashboard._RemoveMicrosecondsFromDatetime(None)) |
| 53 |
| 54 def testFormatTimedelta(self): |
| 55 self.assertIsNone(try_job_dashboard._FormatTimedelta(None)) |
| 56 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 1)), |
| 57 '00:00:01') |
| 58 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 60)), |
| 59 '00:01:00') |
| 60 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 3600)), |
| 61 '01:00:00') |
| 62 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 0, 1)), |
| 63 '00:00:00') |
| 64 |
| 65 def testFormatDatetime(self): |
| 66 self.assertIsNone(try_job_dashboard._FormatDatetime(None)) |
| 67 self.assertEqual( |
| 68 try_job_dashboard._FormatDatetime(datetime(2016, 1, 2, 1, 2, 3)), |
| 69 '2016-01-02 01:02:03 UTC') |
| 70 |
| 71 def testGet(self): |
| 72 try_job_in_progress = WfTryJobData.Create(1) |
| 73 try_job_in_progress.master_name = 'm' |
| 74 try_job_in_progress.builder_name = 'b' |
| 75 try_job_in_progress.build_number = 1 |
| 76 try_job_in_progress.try_job_type = 'compile' |
| 77 try_job_in_progress.start_time = datetime(2016, 5, 4, 0, 0, 1) |
| 78 try_job_in_progress.request_time = datetime(2016, 5, 4, 0, 0, 0) |
| 79 try_job_in_progress.try_job_url = 'url1' |
| 80 try_job_in_progress.put() |
| 81 |
| 82 try_job_with_error = WfTryJobData.Create(2) |
| 83 try_job_with_error.master_name = 'm' |
| 84 try_job_with_error.builder_name = 'b' |
| 85 try_job_with_error.build_number = 2 |
| 86 try_job_with_error.try_job_type = 'compile' |
| 87 try_job_with_error.start_time = datetime(2016, 5, 4, 0, 0, 1) |
| 88 try_job_with_error.request_time = datetime(2016, 5, 4, 0, 0, 0) |
| 89 try_job_with_error.end_time = datetime(2016, 5, 4, 0, 0, 2) |
| 90 try_job_with_error.try_job_url = 'url2' |
| 91 try_job_with_error.error = { |
| 92 'message': 'some error', |
| 93 'reason': 'some reason' |
| 94 } |
| 95 try_job_with_error.put() |
| 96 |
| 97 try_job_completed = WfTryJobData.Create(3) |
| 98 try_job_completed.master_name = 'm' |
| 99 try_job_completed.builder_name = 'b' |
| 100 try_job_completed.build_number = 3 |
| 101 try_job_completed.try_job_type = 'compile' |
| 102 try_job_completed.start_time = datetime(2016, 5, 4, 0, 0, 1) |
| 103 try_job_completed.request_time = datetime(2016, 5, 4, 0, 0, 0) |
| 104 try_job_completed.end_time = datetime(2016, 5, 4, 0, 0, 2) |
| 105 try_job_completed.try_job_url = 'url3' |
| 106 try_job_completed.culprits = { |
| 107 'compile': { |
| 108 '12345': 'failed' |
| 109 } |
| 110 } |
| 111 try_job_completed.put() |
| 112 |
| 113 expected_try_job_in_progress_display_data = { |
| 114 'master_name': 'm', |
| 115 'builder_name': 'b', |
| 116 'build_number': 1, |
| 117 'try_job_type': 'compile', |
| 118 'start_time': '2016-05-04 00:00:01 UTC', |
| 119 'request_time': '2016-05-04 00:00:00 UTC', |
| 120 'try_job_url': 'url1', |
| 121 'status': 'running' |
| 122 } |
| 123 |
| 124 expected_try_job_with_error_display_data = { |
| 125 'master_name': 'm', |
| 126 'builder_name': 'b', |
| 127 'build_number': 2, |
| 128 'try_job_type': 'compile', |
| 129 'start_time': '2016-05-04 00:00:01 UTC', |
| 130 'request_time': '2016-05-04 00:00:00 UTC', |
| 131 'end_time': '2016-05-04 00:00:02 UTC', |
| 132 'try_job_url': 'url2', |
| 133 'error': 'some error', |
| 134 } |
| 135 |
| 136 expected_try_job_completed_display_data = { |
| 137 'master_name': 'm', |
| 138 'builder_name': 'b', |
| 139 'build_number': 3, |
| 140 'try_job_type': 'compile', |
| 141 'start_time': '2016-05-04 00:00:01 UTC', |
| 142 'request_time': '2016-05-04 00:00:00 UTC', |
| 143 'end_time': '2016-05-04 00:00:02 UTC', |
| 144 'try_job_url': 'url3', |
| 145 'culprit_found': True |
| 146 } |
| 147 |
| 148 response = self.test_app.get('/try-job-dashboard?format=json') |
| 149 response_data = response.json_body |
| 150 try_jobs_in_progress = response_data.get('try_jobs_in_progress') |
| 151 try_jobs_with_error = response_data.get('try_jobs_with_error') |
| 152 successfully_completed_try_jobs = response_data.get( |
| 153 'successfully_completed_try_jobs') |
| 154 |
| 155 self.assertEqual(response.status_int, 200) |
| 156 self.validateTryJobDisplayData( |
| 157 [expected_try_job_in_progress_display_data], |
| 158 try_jobs_in_progress) |
| 159 self.validateTryJobDisplayData( |
| 160 [expected_try_job_with_error_display_data], |
| 161 try_jobs_with_error) |
| 162 self.validateTryJobDisplayData( |
| 163 [expected_try_job_completed_display_data], |
| 164 successfully_completed_try_jobs) |
| 165 |
| OLD | NEW |