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 | c61196b | 2019-08-13 10:37:30 -0700 | [diff] [blame] | 9 | import buildbucket |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 10 | import constants |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 11 | import rest_client |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 12 | import time_converter |
Xixuan Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 13 | |
| 14 | import webapp2 |
| 15 | |
| 16 | |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 17 | class _FakeBigqueryGetPassedHandler(webapp2.RequestHandler): |
| 18 | |
| 19 | def get(self): |
| 20 | bq_client = rest_client.BuildBucketBigqueryClient( |
| 21 | rest_client.BaseRestClient( |
| 22 | constants.RestClient.BIGQUERY_CLIENT.scopes, |
| 23 | constants.RestClient.BIGQUERY_CLIENT.service_name, |
| 24 | constants.RestClient.BIGQUERY_CLIENT.service_version)) |
| 25 | |
| 26 | # Get passed builds in 3 days. |
| 27 | utc_now = time_converter.utc_now() |
| 28 | since_date = utc_now - datetime.timedelta(days=3) |
Xinan Lin | ea1efcb | 2019-12-30 23:46:42 -0800 | [diff] [blame] | 29 | res = bq_client.get_passed_builds(since_date, utc_now) |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 30 | for r in res: |
| 31 | self.response.write(r) |
| 32 | self.response.write('\n') |
| 33 | |
| 34 | |
| 35 | class _FakeBigqueryGetRelaxedPassedHandler(webapp2.RequestHandler): |
| 36 | |
| 37 | def get(self): |
| 38 | bq_client = rest_client.BuildBucketBigqueryClient( |
| 39 | rest_client.BaseRestClient( |
| 40 | constants.RestClient.BIGQUERY_CLIENT.scopes, |
| 41 | constants.RestClient.BIGQUERY_CLIENT.service_name, |
| 42 | constants.RestClient.BIGQUERY_CLIENT.service_version)) |
| 43 | |
| 44 | # Get passed builds in 3 days. |
| 45 | utc_now = time_converter.utc_now() |
| 46 | since_date = utc_now - datetime.timedelta(days=3) |
Xinan Lin | ea1efcb | 2019-12-30 23:46:42 -0800 | [diff] [blame] | 47 | res = bq_client.get_relaxed_passed_builds(since_date, utc_now) |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 48 | for r in res: |
| 49 | self.response.write(r) |
| 50 | self.response.write('\n') |
| 51 | |
| 52 | |
Xinan Lin | 80a9d93 | 2019-10-17 09:24:43 -0700 | [diff] [blame] | 53 | class _FakeCrOSTestPlatformBigqueryHandler(webapp2.RequestHandler): |
| 54 | |
| 55 | def get(self): |
| 56 | bq_client = rest_client.CrOSTestPlatformBigqueryClient( |
| 57 | rest_client.BaseRestClient( |
| 58 | constants.RestClient.BIGQUERY_CLIENT.scopes, |
| 59 | constants.RestClient.BIGQUERY_CLIENT.service_name, |
| 60 | constants.RestClient.BIGQUERY_CLIENT.service_version)) |
| 61 | res = bq_client.get_past_job_nums(72) |
| 62 | if res > 0: |
| 63 | self.response.write('ok') |
| 64 | |
| 65 | |
Xinan Lin | c61196b | 2019-08-13 10:37:30 -0700 | [diff] [blame] | 66 | class _FakeBuildbucketLibCompatibilityHandler(webapp2.RequestHandler): |
| 67 | |
| 68 | def get(self): |
| 69 | test_platform_client = buildbucket.TestPlatformClient( |
| 70 | constants.Buildbucket.HOST, |
| 71 | constants.Buildbucket.PROJECT, |
| 72 | constants.Buildbucket.BUCKET, |
| 73 | constants.Buildbucket.STAGING_BUILDER) |
| 74 | res = test_platform_client.dummy_run() |
| 75 | self.response.write(res) |
| 76 | |
| 77 | |
Xixuan Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 78 | app = webapp2.WSGIApplication([ |
Xixuan Wu | f856ff1 | 2019-05-21 14:09:38 -0700 | [diff] [blame] | 79 | ('/test_push/bq_get_passed', _FakeBigqueryGetPassedHandler), |
| 80 | ('/test_push/bq_get_relaxed_passed', _FakeBigqueryGetRelaxedPassedHandler), |
Xinan Lin | 80a9d93 | 2019-10-17 09:24:43 -0700 | [diff] [blame] | 81 | ('/test_push/bq_get_last_hours', _FakeCrOSTestPlatformBigqueryHandler), |
Xinan Lin | c61196b | 2019-08-13 10:37:30 -0700 | [diff] [blame] | 82 | ('/test_push/buildbucket_lib_compatibility', |
| 83 | _FakeBuildbucketLibCompatibilityHandler) |
Xixuan Wu | 865fa28 | 2017-09-05 15:23:19 -0700 | [diff] [blame] | 84 | ], debug=True) |