Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: appengine/cr-buildbucket/test/api_test.py

Issue 1877083003: buildbucket: add retry API. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: retry_of as an attribute Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/cr-buildbucket/service.py ('k') | appengine/cr-buildbucket/test/service_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import datetime 5 import datetime
6 import json 6 import json
7 7
8 from components import auth 8 from components import auth
9 from components import utils 9 from components import utils
10 from google.appengine.ext import ndb 10 from google.appengine.ext import ndb
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 def test_get_nonexistent_build(self): 69 def test_get_nonexistent_build(self):
70 service.get.return_value = None 70 service.get.return_value = None
71 self.expect_error('get', {'id': 1}, 'BUILD_NOT_FOUND') 71 self.expect_error('get', {'id': 1}, 'BUILD_NOT_FOUND')
72 72
73 ##################################### PUT #################################### 73 ##################################### PUT ####################################
74 74
75 def test_put(self): 75 def test_put(self):
76 self.test_build.tags = ['owner:ivan'] 76 self.test_build.tags = ['owner:ivan']
77 service.add.return_value = self.test_build 77 service.add.return_value = self.test_build
78 req = { 78 req = {
79 'client_operation_id': '42',
79 'bucket': self.test_build.bucket, 80 'bucket': self.test_build.bucket,
80 'tags': self.test_build.tags, 81 'tags': self.test_build.tags,
81 'pubsub_callback': { 82 'pubsub_callback': {
82 'topic': 'projects/foo/topic/bar', 83 'topic': 'projects/foo/topic/bar',
83 'user_data': 'hello', 84 'user_data': 'hello',
84 'auth_token': 'secret', 85 'auth_token': 'secret',
85 } 86 }
86 } 87 }
87 resp = self.call_api('put', req).json_body 88 resp = self.call_api('put', req).json_body
88 service.add.assert_called_once_with( 89 service.add.assert_called_once_with(
89 bucket=self.test_build.bucket, 90 bucket=self.test_build.bucket,
90 tags=req['tags'], 91 tags=req['tags'],
91 parameters=None, 92 parameters=None,
92 lease_expiration_date=None, 93 lease_expiration_date=None,
93 client_operation_id=None, 94 client_operation_id='42',
94 pubsub_callback=model.PubSubCallback( 95 pubsub_callback=model.PubSubCallback(
95 topic='projects/foo/topic/bar', 96 topic='projects/foo/topic/bar',
96 user_data='hello', 97 user_data='hello',
97 auth_token='secret', 98 auth_token='secret',
98 ), 99 ),
99 ) 100 )
100 self.assertEqual(resp['build']['id'], str(self.test_build.key.id())) 101 self.assertEqual(resp['build']['id'], str(self.test_build.key.id()))
101 self.assertEqual(resp['build']['bucket'], req['bucket']) 102 self.assertEqual(resp['build']['bucket'], req['bucket'])
102 self.assertEqual(resp['build']['tags'], req['tags']) 103 self.assertEqual(resp['build']['tags'], req['tags'])
103 104
(...skipping 25 matching lines...) Expand all
129 self.assertEqual( 130 self.assertEqual(
130 resp['build']['lease_expiration_ts'], req['lease_expiration_ts']) 131 resp['build']['lease_expiration_ts'], req['lease_expiration_ts'])
131 132
132 def test_put_with_malformed_parameters_json(self): 133 def test_put_with_malformed_parameters_json(self):
133 req = { 134 req = {
134 'bucket': 'chromium', 135 'bucket': 'chromium',
135 'parameters_json': '}non-json', 136 'parameters_json': '}non-json',
136 } 137 }
137 self.expect_error('put', req, 'INVALID_INPUT') 138 self.expect_error('put', req, 'INVALID_INPUT')
138 139
140 #################################### RETRY ###################################
141
142 def test_retry(self):
143 build = model.Build(
144 bucket='chromium',
145 parameters={'builder_name': 'debug'},
146 tags = ['a:b'],
147 retry_of=2,
148 )
149 build.put()
150 service.retry.return_value = build
151
152 req = {
153 'id': build.key.id(),
154 'client_operation_id': '42',
155 'pubsub_callback': {
156 'topic': 'projects/foo/topic/bar',
157 'user_data': 'hello',
158 'auth_token': 'secret',
159 }
160 }
161 resp = self.call_api('retry', req).json_body
162 service.retry.assert_called_once_with(
163 build.key.id(),
164 client_operation_id='42',
165 lease_expiration_date=None,
166 pubsub_callback=model.PubSubCallback(
167 topic='projects/foo/topic/bar',
168 user_data='hello',
169 auth_token='secret',
170 ),
171 )
172 self.assertEqual(resp['build']['id'], str(build.key.id()))
173 self.assertEqual(resp['build']['bucket'], build.bucket)
174 self.assertEqual(
175 json.loads(resp['build']['parameters_json']), build.parameters)
176 self.assertEqual(resp['build']['retry_of'], '2')
177
178 def test_retry_not_found(self):
179 service.retry.side_effect = errors.BuildNotFoundError
180 self.expect_error('retry', {'id': 42}, 'BUILD_NOT_FOUND')
181
139 ################################## PUT_BATCH ################################# 182 ################################## PUT_BATCH #################################
140 183
141 def test_put_batch(self): 184 def test_put_batch(self):
142 self.test_build.tags = ['owner:ivan'] 185 self.test_build.tags = ['owner:ivan']
143 build1_future = ndb.Future() 186 build1_future = ndb.Future()
144 build1_future.set_result(self.test_build) 187 build1_future.set_result(self.test_build)
145 188
146 build2 = model.Build(id=2, bucket='v8') 189 build2 = model.Build(id=2, bucket='v8')
147 build2_future = ndb.Future() 190 build2_future = ndb.Future()
148 build2_future.set_result(build2) 191 build2_future.set_result(build2)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 def test_search(self): 252 def test_search(self):
210 self.test_build.put() 253 self.test_build.put()
211 service.search.return_value = ([self.test_build], 'the cursor') 254 service.search.return_value = ([self.test_build], 'the cursor')
212 req = { 255 req = {
213 'bucket': ['chromium'], 256 'bucket': ['chromium'],
214 'cancelation_reason': 'CANCELED_EXPLICITLY', 257 'cancelation_reason': 'CANCELED_EXPLICITLY',
215 'created_by': 'user:x@chromium.org', 258 'created_by': 'user:x@chromium.org',
216 'result': 'CANCELED', 259 'result': 'CANCELED',
217 'status': 'COMPLETED', 260 'status': 'COMPLETED',
218 'tag': ['important'], 261 'tag': ['important'],
262 'retry_of': '42',
219 } 263 }
220 264
221 res = self.call_api('search', req).json_body 265 res = self.call_api('search', req).json_body
222 266
223 service.search.assert_called_once_with( 267 service.search.assert_called_once_with(
224 buckets=req['bucket'], 268 buckets=req['bucket'],
225 tags=req['tag'], 269 tags=req['tag'],
226 status=model.BuildStatus.COMPLETED, 270 status=model.BuildStatus.COMPLETED,
227 result=model.BuildResult.CANCELED, 271 result=model.BuildResult.CANCELED,
228 failure_reason=None, 272 failure_reason=None,
229 cancelation_reason=model.CancelationReason.CANCELED_EXPLICITLY, 273 cancelation_reason=model.CancelationReason.CANCELED_EXPLICITLY,
230 created_by='user:x@chromium.org', 274 created_by='user:x@chromium.org',
231 max_builds=None, 275 max_builds=None,
232 start_cursor=None) 276 start_cursor=None,
277 retry_of=42,
278 )
233 self.assertEqual(len(res['builds']), 1) 279 self.assertEqual(len(res['builds']), 1)
234 self.assertEqual(res['builds'][0]['id'], str(self.test_build.key.id())) 280 self.assertEqual(res['builds'][0]['id'], str(self.test_build.key.id()))
235 self.assertEqual(res['next_cursor'], 'the cursor') 281 self.assertEqual(res['next_cursor'], 'the cursor')
236 282
237 ##################################### PEEK ################################### 283 ##################################### PEEK ###################################
238 284
239 def test_peek(self): 285 def test_peek(self):
240 self.test_build.put() 286 self.test_build.put()
241 service.peek.return_value = ([self.test_build], 'the cursor') 287 service.peek.return_value = ([self.test_build], 'the cursor')
242 req = {'bucket': [self.test_build.bucket]} 288 req = {'bucket': [self.test_build.bucket]}
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 def test_invalid_input_error(self): 553 def test_invalid_input_error(self):
508 self.error_test(errors.InvalidInputError, 'INVALID_INPUT') 554 self.error_test(errors.InvalidInputError, 'INVALID_INPUT')
509 555
510 def test_lease_expired_error(self): 556 def test_lease_expired_error(self):
511 self.error_test(errors.LeaseExpiredError, 'LEASE_EXPIRED') 557 self.error_test(errors.LeaseExpiredError, 'LEASE_EXPIRED')
512 558
513 def test_auth_error(self): 559 def test_auth_error(self):
514 with self.call_should_fail(403): 560 with self.call_should_fail(403):
515 service.get.side_effect = auth.AuthorizationError 561 service.get.side_effect = auth.AuthorizationError
516 self.call_api('get', {'id': 123}) 562 self.call_api('get', {'id': 123})
OLDNEW
« no previous file with comments | « appengine/cr-buildbucket/service.py ('k') | appengine/cr-buildbucket/test/service_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698