OLD | NEW |
1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
4 | 4 |
5 import base64 | 5 import base64 |
6 import contextlib | 6 import contextlib |
7 import datetime | 7 import datetime |
8 import json | 8 import json |
9 import logging | 9 import logging |
10 import time | 10 import time |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if eta >= time.time(): | 145 if eta >= time.time(): |
146 continue | 146 continue |
147 self.assertEqual('POST', task['method']) | 147 self.assertEqual('POST', task['method']) |
148 logging.info('Task: %s', task['url']) | 148 logging.info('Task: %s', task['url']) |
149 | 149 |
150 # Not 100% sure why the Content-Length hack is needed: | 150 # Not 100% sure why the Content-Length hack is needed: |
151 body = base64.b64decode(task['body']) | 151 body = base64.b64decode(task['body']) |
152 headers = dict(task['headers']) | 152 headers = dict(task['headers']) |
153 headers['Content-Length'] = str(len(body)) | 153 headers['Content-Length'] = str(len(body)) |
154 try: | 154 try: |
155 response = self.app.post( | 155 self.app.post(task['url'], body, headers=headers, **kwargs) |
156 task['url'], body, headers=headers, **kwargs) | |
157 except: | 156 except: |
158 logging.error(task) | 157 logging.error(task) |
159 raise | 158 raise |
160 # TODO(maruel): Implement task failure. | |
161 self.assertEqual(200, response.status_code) | |
162 self._taskqueue_stub.DeleteTask(queue['name'], task['name']) | 159 self._taskqueue_stub.DeleteTask(queue['name'], task['name']) |
163 ran += 1 | 160 ran += 1 |
164 if not ran: | 161 if not ran: |
165 return ran_total | 162 return ran_total |
166 ran_total += ran | 163 ran_total += ran |
167 | 164 |
168 | 165 |
169 class Endpoints(object): | 166 class Endpoints(object): |
170 """Handles endpoints API calls.""" | 167 """Handles endpoints API calls.""" |
171 def __init__(self, api_service_cls, source_ip='127.0.0.1'): | 168 def __init__(self, api_service_cls, source_ip='127.0.0.1'): |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 self.api_service_cls.api_info.version, | 286 self.api_service_cls.api_info.version, |
290 method_path, | 287 method_path, |
291 urllib.urlencode(url_params, doseq=True) | 288 urllib.urlencode(url_params, doseq=True) |
292 ) | 289 ) |
293 | 290 |
294 return self._app.request( | 291 return self._app.request( |
295 url, | 292 url, |
296 method=method.method_info.http_method, | 293 method=method.method_info.http_method, |
297 body=json.dumps(body), | 294 body=json.dumps(body), |
298 status=status) | 295 status=status) |
OLD | NEW |