blob: caab1dff8f3eace2f3b82ff0585b82c680e3b321 [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()
Xinan Lin71eeeb02020-03-10 17:37:12 -070030 since_date = utc_now - datetime.timedelta(days=1)
31 res = bq_client.get_passed_builds(since_date, utc_now, "NIGHTLY")
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
Xinan Lin71eeeb02020-03-10 17:37:12 -070046 # Get passed builds in 23 hours. Set a longer time to make sure
47 # we can fetch some builds.
Xixuan Wuf856ff12019-05-21 14:09:38 -070048 utc_now = time_converter.utc_now()
Xinan Lin71eeeb02020-03-10 17:37:12 -070049 since_date = utc_now - datetime.timedelta(hours=23)
50 res = bq_client.get_relaxed_passed_builds(since_date, utc_now, "new_build")
Xixuan Wuf856ff12019-05-21 14:09:38 -070051 for r in res:
52 self.response.write(r)
53 self.response.write('\n')
54
55
Xinan Lin80a9d932019-10-17 09:24:43 -070056class _FakeCrOSTestPlatformBigqueryHandler(webapp2.RequestHandler):
57
58 def get(self):
59 bq_client = rest_client.CrOSTestPlatformBigqueryClient(
60 rest_client.BaseRestClient(
61 constants.RestClient.BIGQUERY_CLIENT.scopes,
62 constants.RestClient.BIGQUERY_CLIENT.service_name,
63 constants.RestClient.BIGQUERY_CLIENT.service_version))
64 res = bq_client.get_past_job_nums(72)
65 if res > 0:
66 self.response.write('ok')
67
68
Xinan Linc61196b2019-08-13 10:37:30 -070069class _FakeBuildbucketLibCompatibilityHandler(webapp2.RequestHandler):
70
71 def get(self):
72 test_platform_client = buildbucket.TestPlatformClient(
73 constants.Buildbucket.HOST,
74 constants.Buildbucket.PROJECT,
75 constants.Buildbucket.BUCKET,
76 constants.Buildbucket.STAGING_BUILDER)
77 res = test_platform_client.dummy_run()
78 self.response.write(res)
79
80
Xinan Linc9f01152020-02-05 22:05:13 -080081class _FakeScheduleJobSectionHandler(webapp2.RequestHandler):
82
83 def get(self):
84 job = analytics.ScheduleJobSection(task_config_reader.TaskInfo(
85 name='fake_board',
86 suite='fake_suite',
87 branch_specs=[],
88 pool='fake_pool',
89 num=1,
90 boards='foo',
91 priority=50,
92 timeout=600))
93 job.add_board('foo')
94 job.add_model('foo')
95 job.add_matched_build('foo', 'release', '80', '12345.0.0')
96 job.add_schedule_job('foo', 'foo', task_id='local_integration_test')
97 res = ''
98 if job.upload():
99 res = 'ok'
100 self.response.write(res)
101
102
Xixuan Wu865fa282017-09-05 15:23:19 -0700103app = webapp2.WSGIApplication([
Xixuan Wuf856ff12019-05-21 14:09:38 -0700104 ('/test_push/bq_get_passed', _FakeBigqueryGetPassedHandler),
105 ('/test_push/bq_get_relaxed_passed', _FakeBigqueryGetRelaxedPassedHandler),
Xinan Lin80a9d932019-10-17 09:24:43 -0700106 ('/test_push/bq_get_last_hours', _FakeCrOSTestPlatformBigqueryHandler),
Xinan Linc61196b2019-08-13 10:37:30 -0700107 ('/test_push/buildbucket_lib_compatibility',
Xinan Linc9f01152020-02-05 22:05:13 -0800108 _FakeBuildbucketLibCompatibilityHandler),
109 ('/test_push/fake_scheduler_job_section', _FakeScheduleJobSectionHandler)
Xixuan Wu865fa282017-09-05 15:23:19 -0700110 ], debug=True)