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() |
| 30 | since_date = utc_now - datetime.timedelta(days=3) |
Xinan Lin | ea1efcb | 2019-12-30 23:46:42 -0800 | [diff] [blame] | 31 | res = bq_client.get_passed_builds(since_date, utc_now) |
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 | |
| 46 | # Get passed builds in 3 days. |
| 47 | utc_now = time_converter.utc_now() |
| 48 | since_date = utc_now - datetime.timedelta(days=3) |
Xinan Lin | ea1efcb | 2019-12-30 23:46:42 -0800 | [diff] [blame] | 49 | res = bq_client.get_relaxed_passed_builds(since_date, utc_now) |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 50 | for r in res: |
| 51 | self.response.write(r) |
| 52 | self.response.write('\n') |
| 53 | |
| 54 | |
Xinan Lin | 80a9d93 | 2019-10-17 09:24:43 -0700 | [diff] [blame] | 55 | class _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 Lin | c61196b | 2019-08-13 10:37:30 -0700 | [diff] [blame] | 68 | class _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 Lin | c9f0115 | 2020-02-05 22:05:13 -0800 | [diff] [blame] | 80 | class _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 Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 102 | app = webapp2.WSGIApplication([ |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 103 | ('/test_push/bq_get_passed', _FakeBigqueryGetPassedHandler), |
| 104 | ('/test_push/bq_get_relaxed_passed', _FakeBigqueryGetRelaxedPassedHandler), |
Xinan Lin | 80a9d93 | 2019-10-17 09:24:43 -0700 | [diff] [blame] | 105 | ('/test_push/bq_get_last_hours', _FakeCrOSTestPlatformBigqueryHandler), |
Xinan Lin | c61196b | 2019-08-13 10:37:30 -0700 | [diff] [blame] | 106 | ('/test_push/buildbucket_lib_compatibility', |
Xinan Lin | c9f0115 | 2020-02-05 22:05:13 -0800 | [diff] [blame] | 107 | _FakeBuildbucketLibCompatibilityHandler), |
| 108 | ('/test_push/fake_scheduler_job_section', _FakeScheduleJobSectionHandler) |
Xixuan Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 109 | ], debug=True) |