blob: 6cccb3232a1238b61748161a231c11c09c84b78d [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 Linc61196b2019-08-13 10:37:30 -07009import buildbucket
Xixuan Wuf856ff12019-05-21 14:09:38 -070010import constants
Xixuan Wuf856ff12019-05-21 14:09:38 -070011import rest_client
Xixuan Wuf856ff12019-05-21 14:09:38 -070012import time_converter
Xixuan Wu865fa282017-09-05 15:23:19 -070013
14import webapp2
15
16
Xixuan Wuf856ff12019-05-21 14:09:38 -070017class _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 Linea1efcb2019-12-30 23:46:42 -080029 res = bq_client.get_passed_builds(since_date, utc_now)
Xixuan Wuf856ff12019-05-21 14:09:38 -070030 for r in res:
31 self.response.write(r)
32 self.response.write('\n')
33
34
35class _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 Linea1efcb2019-12-30 23:46:42 -080047 res = bq_client.get_relaxed_passed_builds(since_date, utc_now)
Xixuan Wuf856ff12019-05-21 14:09:38 -070048 for r in res:
49 self.response.write(r)
50 self.response.write('\n')
51
52
Xinan Lin80a9d932019-10-17 09:24:43 -070053class _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 Linc61196b2019-08-13 10:37:30 -070066class _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 Wu865fa282017-09-05 15:23:19 -070078app = webapp2.WSGIApplication([
Xixuan Wuf856ff12019-05-21 14:09:38 -070079 ('/test_push/bq_get_passed', _FakeBigqueryGetPassedHandler),
80 ('/test_push/bq_get_relaxed_passed', _FakeBigqueryGetRelaxedPassedHandler),
Xinan Lin80a9d932019-10-17 09:24:43 -070081 ('/test_push/bq_get_last_hours', _FakeCrOSTestPlatformBigqueryHandler),
Xinan Linc61196b2019-08-13 10:37:30 -070082 ('/test_push/buildbucket_lib_compatibility',
83 _FakeBuildbucketLibCompatibilityHandler)
Xixuan Wu865fa282017-09-05 15:23:19 -070084 ], debug=True)