Xixuan Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 1 | # 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 Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 7 | import datetime |
| 8 | |
Xinan Lin | c9f0115 | 2020-02-05 22:05:13 -0800 | [diff] [blame] | 9 | import analytics |
Xinan Lin | c61196b | 2019-08-13 10:37:30 -0700 | [diff] [blame] | 10 | import buildbucket |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 11 | import constants |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 12 | import rest_client |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 13 | import time_converter |
Xinan Lin | c9f0115 | 2020-02-05 22:05:13 -0800 | [diff] [blame] | 14 | import task_config_reader |
Xixuan Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 15 | |
| 16 | import webapp2 |
| 17 | |
| 18 | |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 19 | class _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 Lin | 71eeeb0 | 2020-03-10 17:37:12 -0700 | [diff] [blame] | 30 | since_date = utc_now - datetime.timedelta(days=1) |
| 31 | res = bq_client.get_passed_builds(since_date, utc_now, "NIGHTLY") |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 32 | for r in res: |
| 33 | self.response.write(r) |
| 34 | self.response.write('\n') |
| 35 | |
| 36 | |
| 37 | class _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 Lin | 71eeeb0 | 2020-03-10 17:37:12 -0700 | [diff] [blame] | 46 | # Get passed builds in 23 hours. Set a longer time to make sure |
| 47 | # we can fetch some builds. |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 48 | utc_now = time_converter.utc_now() |
Xinan Lin | 71eeeb0 | 2020-03-10 17:37:12 -0700 | [diff] [blame] | 49 | since_date = utc_now - datetime.timedelta(hours=23) |
| 50 | res = bq_client.get_relaxed_passed_builds(since_date, utc_now, "new_build") |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 51 | for r in res: |
| 52 | self.response.write(r) |
| 53 | self.response.write('\n') |
| 54 | |
| 55 | |
Xinan Lin | 80a9d93 | 2019-10-17 09:24:43 -0700 | [diff] [blame] | 56 | class _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 Lin | c61196b | 2019-08-13 10:37:30 -0700 | [diff] [blame] | 69 | class _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 Lin | c9f0115 | 2020-02-05 22:05:13 -0800 | [diff] [blame] | 81 | class _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 Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 103 | app = webapp2.WSGIApplication([ |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 104 | ('/test_push/bq_get_passed', _FakeBigqueryGetPassedHandler), |
| 105 | ('/test_push/bq_get_relaxed_passed', _FakeBigqueryGetRelaxedPassedHandler), |
Xinan Lin | 80a9d93 | 2019-10-17 09:24:43 -0700 | [diff] [blame] | 106 | ('/test_push/bq_get_last_hours', _FakeCrOSTestPlatformBigqueryHandler), |
Xinan Lin | c61196b | 2019-08-13 10:37:30 -0700 | [diff] [blame] | 107 | ('/test_push/buildbucket_lib_compatibility', |
Xinan Lin | c9f0115 | 2020-02-05 22:05:13 -0800 | [diff] [blame] | 108 | _FakeBuildbucketLibCompatibilityHandler), |
| 109 | ('/test_push/fake_scheduler_job_section', _FakeScheduleJobSectionHandler) |
Xixuan Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 110 | ], debug=True) |