Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: appengine/findit/handlers/test/try_job_dashboard_test.py

Issue 1949763002: [Findit] Adding try job dashboard (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Addressing nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | appengine/findit/handlers/try_job_dashboard.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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), len(actual_try_job_data_list))
24
25 # Validates each field in each expected data dict matches those in each
26 # actual data dict. Note order matters in each list. Note a direct list
27 # comparison is not possible since try jobs in progress will have
28 # constantly-changing elapsed_time fields depending on the time the tests
29 # are run, so we compare all other fields to avoid this.
30 for i in range(len(expected_try_job_data_list)):
31 expected_try_job_data = expected_try_job_data_list[i]
32 actual_try_job_data = actual_try_job_data_list[i]
33
34 for field, expected_data in expected_try_job_data.iteritems():
35 self.assertEqual(expected_data, actual_try_job_data.get(field))
36
37 def testRemoveMicrosecondsFromDelta(self):
38 date1 = datetime(2016, 5, 1, 1, 1, 1, 1)
39 date2 = datetime(2016, 5, 1, 1, 1, 1, 2)
40 delta = date2 - date1
41
42 self.assertEqual(
43 try_job_dashboard._RemoveMicrosecondsFromDelta(delta).microseconds,
44 0)
45
46 def testFormatTimedelta(self):
47 self.assertIsNone(try_job_dashboard._FormatTimedelta(None))
48 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 1)),
49 '00:00:01')
50 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 60)),
51 '00:01:00')
52 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 3600)),
53 '01:00:00')
54 self.assertEqual(try_job_dashboard._FormatTimedelta(timedelta(0, 0, 1)),
55 '00:00:00')
56
57 def testFormatDatetime(self):
58 self.assertIsNone(try_job_dashboard._FormatDatetime(None))
59 self.assertEqual(
60 try_job_dashboard._FormatDatetime(datetime(2016, 1, 2, 1, 2, 3)),
61 '2016-01-02 01:02:03 UTC')
62
63 def testGet(self):
64 try_job_in_progress = WfTryJobData.Create(1)
65 try_job_in_progress.master_name = 'm'
66 try_job_in_progress.builder_name = 'b'
67 try_job_in_progress.build_number = 1
68 try_job_in_progress.try_job_type = 'compile'
69 try_job_in_progress.start_time = datetime(2016, 5, 4, 0, 0, 1)
70 try_job_in_progress.request_time = datetime(2016, 5, 4, 0, 0, 0)
71 try_job_in_progress.try_job_url = 'url1'
72 try_job_in_progress.put()
73
74 try_job_with_error = WfTryJobData.Create(2)
75 try_job_with_error.master_name = 'm'
76 try_job_with_error.builder_name = 'b'
77 try_job_with_error.build_number = 2
78 try_job_with_error.try_job_type = 'compile'
79 try_job_with_error.start_time = datetime(2016, 5, 4, 0, 0, 1)
80 try_job_with_error.request_time = datetime(2016, 5, 4, 0, 0, 0)
81 try_job_with_error.end_time = datetime(2016, 5, 4, 0, 0, 2)
82 try_job_with_error.try_job_url = 'url2'
83 try_job_with_error.error = {
84 'message': 'some error',
85 'reason': 'some reason'
86 }
87 try_job_with_error.put()
88
89 try_job_completed = WfTryJobData.Create(3)
90 try_job_completed.master_name = 'm'
91 try_job_completed.builder_name = 'b'
92 try_job_completed.build_number = 3
93 try_job_completed.try_job_type = 'compile'
94 try_job_completed.start_time = datetime(2016, 5, 4, 0, 0, 1)
95 try_job_completed.request_time = datetime(2016, 5, 4, 0, 0, 0)
96 try_job_completed.end_time = datetime(2016, 5, 4, 0, 0, 2)
97 try_job_completed.try_job_url = 'url3'
98 try_job_completed.culprits = {
99 'compile': {
100 '12345': 'failed'
101 }
102 }
103 try_job_completed.put()
104
105 expected_try_job_in_progress_display_data = {
106 'master_name': 'm',
107 'builder_name': 'b',
108 'build_number': 1,
109 'try_job_type': 'compile',
110 'start_time': '2016-05-04 00:00:01 UTC',
111 'request_time': '2016-05-04 00:00:00 UTC',
112 'try_job_url': 'url1',
113 'status': 'running'
114 }
115
116 expected_try_job_with_error_display_data = {
117 'master_name': 'm',
118 'builder_name': 'b',
119 'build_number': 2,
120 'try_job_type': 'compile',
121 'start_time': '2016-05-04 00:00:01 UTC',
122 'request_time': '2016-05-04 00:00:00 UTC',
123 'end_time': '2016-05-04 00:00:02 UTC',
124 'try_job_url': 'url2',
125 'error': 'some error',
126 }
127
128 expected_try_job_completed_display_data = {
129 'master_name': 'm',
130 'builder_name': 'b',
131 'build_number': 3,
132 'try_job_type': 'compile',
133 'start_time': '2016-05-04 00:00:01 UTC',
134 'request_time': '2016-05-04 00:00:00 UTC',
135 'end_time': '2016-05-04 00:00:02 UTC',
136 'try_job_url': 'url3',
137 'culprit_found': True
138 }
139
140 response = self.test_app.get('/try-job-dashboard?format=json')
141 response_data = response.json_body
142 try_jobs_in_progress = response_data.get('try_jobs_in_progress')
143 try_jobs_with_error = response_data.get('try_jobs_with_error')
144 successfully_completed_try_jobs = response_data.get(
145 'successfully_completed_try_jobs')
146
147 self.assertEqual(response.status_int, 200)
148 self.validateTryJobDisplayData(
149 [expected_try_job_in_progress_display_data],
150 try_jobs_in_progress)
151 self.validateTryJobDisplayData(
152 [expected_try_job_with_error_display_data],
153 try_jobs_with_error)
154 self.validateTryJobDisplayData(
155 [expected_try_job_completed_display_data],
156 successfully_completed_try_jobs)
157
OLDNEW
« no previous file with comments | « no previous file | appengine/findit/handlers/try_job_dashboard.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698