blob: 750fe92ded2ee98710c714768f90dd913e9a9e5b [file] [log] [blame]
Xixuan Wu865fa282017-09-05 15:23:19 -07001# Copyright 2017 The Chromium OS 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"""Module for tests for handlers."""
6
Xixuan Wuf856ff12019-05-21 14:09:38 -07007import datetime
8
Xinan Linc9f01152020-02-05 22:05:13 -08009import analytics
Xinan Linc61196b2019-08-13 10:37:30 -070010import buildbucket
Xixuan Wuf856ff12019-05-21 14:09:38 -070011import constants
Xixuan Wuf856ff12019-05-21 14:09:38 -070012import rest_client
Xixuan Wuf856ff12019-05-21 14:09:38 -070013import time_converter
Xinan Linc9f01152020-02-05 22:05:13 -080014import task_config_reader
Xixuan Wu865fa282017-09-05 15:23:19 -070015
16import webapp2
17
18
Xixuan Wuf856ff12019-05-21 14:09:38 -070019class _FakeBigqueryGetPassedHandler(webapp2.RequestHandler):
20
21 def get(self):
22 bq_client = rest_client.BuildBucketBigqueryClient(
23 rest_client.BaseRestClient(
24 constants.RestClient.BIGQUERY_CLIENT.scopes,
25 constants.RestClient.BIGQUERY_CLIENT.service_name,
26 constants.RestClient.BIGQUERY_CLIENT.service_version))
27
28 # Get passed builds in 3 days.
29 utc_now = time_converter.utc_now()
30 since_date = utc_now - datetime.timedelta(days=3)
Xinan Linea1efcb2019-12-30 23:46:42 -080031 res = bq_client.get_passed_builds(since_date, utc_now)
Xixuan Wuf856ff12019-05-21 14:09:38 -070032 for r in res:
33 self.response.write(r)
34 self.response.write('\n')
35
36
37class _FakeBigqueryGetRelaxedPassedHandler(webapp2.RequestHandler):
38
39 def get(self):
40 bq_client = rest_client.BuildBucketBigqueryClient(
41 rest_client.BaseRestClient(
42 constants.RestClient.BIGQUERY_CLIENT.scopes,
43 constants.RestClient.BIGQUERY_CLIENT.service_name,
44 constants.RestClient.BIGQUERY_CLIENT.service_version))
45
46 # Get passed builds in 3 days.
47 utc_now = time_converter.utc_now()
48 since_date = utc_now - datetime.timedelta(days=3)
Xinan Linea1efcb2019-12-30 23:46:42 -080049 res = bq_client.get_relaxed_passed_builds(since_date, utc_now)
Xixuan Wuf856ff12019-05-21 14:09:38 -070050 for r in res:
51 self.response.write(r)
52 self.response.write('\n')
53
54
Xinan Lin80a9d932019-10-17 09:24:43 -070055class _FakeCrOSTestPlatformBigqueryHandler(webapp2.RequestHandler):
56
57 def get(self):
58 bq_client = rest_client.CrOSTestPlatformBigqueryClient(
59 rest_client.BaseRestClient(
60 constants.RestClient.BIGQUERY_CLIENT.scopes,
61 constants.RestClient.BIGQUERY_CLIENT.service_name,
62 constants.RestClient.BIGQUERY_CLIENT.service_version))
63 res = bq_client.get_past_job_nums(72)
64 if res > 0:
65 self.response.write('ok')
66
67
Xinan Linc61196b2019-08-13 10:37:30 -070068class _FakeBuildbucketLibCompatibilityHandler(webapp2.RequestHandler):
69
70 def get(self):
71 test_platform_client = buildbucket.TestPlatformClient(
72 constants.Buildbucket.HOST,
73 constants.Buildbucket.PROJECT,
74 constants.Buildbucket.BUCKET,
75 constants.Buildbucket.STAGING_BUILDER)
76 res = test_platform_client.dummy_run()
77 self.response.write(res)
78
79
Xinan Linc9f01152020-02-05 22:05:13 -080080class _FakeScheduleJobSectionHandler(webapp2.RequestHandler):
81
82 def get(self):
83 job = analytics.ScheduleJobSection(task_config_reader.TaskInfo(
84 name='fake_board',
85 suite='fake_suite',
86 branch_specs=[],
87 pool='fake_pool',
88 num=1,
89 boards='foo',
90 priority=50,
91 timeout=600))
92 job.add_board('foo')
93 job.add_model('foo')
94 job.add_matched_build('foo', 'release', '80', '12345.0.0')
95 job.add_schedule_job('foo', 'foo', task_id='local_integration_test')
96 res = ''
97 if job.upload():
98 res = 'ok'
99 self.response.write(res)
100
101
Xixuan Wu865fa282017-09-05 15:23:19 -0700102app = webapp2.WSGIApplication([
Xixuan Wuf856ff12019-05-21 14:09:38 -0700103 ('/test_push/bq_get_passed', _FakeBigqueryGetPassedHandler),
104 ('/test_push/bq_get_relaxed_passed', _FakeBigqueryGetRelaxedPassedHandler),
Xinan Lin80a9d932019-10-17 09:24:43 -0700105 ('/test_push/bq_get_last_hours', _FakeCrOSTestPlatformBigqueryHandler),
Xinan Linc61196b2019-08-13 10:37:30 -0700106 ('/test_push/buildbucket_lib_compatibility',
Xinan Linc9f01152020-02-05 22:05:13 -0800107 _FakeBuildbucketLibCompatibilityHandler),
108 ('/test_push/fake_scheduler_job_section', _FakeScheduleJobSectionHandler)
Xixuan Wu865fa282017-09-05 15:23:19 -0700109 ], debug=True)