OLD | NEW |
(Empty) | |
| 1 # Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. |
| 4 |
| 5 import httplib |
| 6 |
| 7 from recipe_engine import recipe_test_api |
| 8 |
| 9 class UrlTestApi(recipe_test_api.RecipeTestApi): # pragma: no cover |
| 10 |
| 11 def _response(self, step_name, data, size, status_code, error_body): |
| 12 step_data = [ |
| 13 self.m.json.output({ |
| 14 'status_code': status_code, |
| 15 'success': status_code in (httplib.OK, httplib.NO_CONTENT), |
| 16 'size': size, |
| 17 'error_body': error_body, |
| 18 }, name='status_json'), |
| 19 ] |
| 20 if data: |
| 21 step_data.append(data) |
| 22 return self.step_data(step_name, *step_data) |
| 23 |
| 24 def error(self, step_name, status_code, body=None): |
| 25 body = body or 'HTTP Error (%d)' % (status_code,) |
| 26 return self._response( |
| 27 step_name, |
| 28 None, |
| 29 len(body), |
| 30 status_code, |
| 31 body) |
| 32 |
| 33 def text(self, step_name, v): |
| 34 return self._response( |
| 35 step_name, |
| 36 self.m.raw_io.output_text(v, name='output'), |
| 37 len(v), |
| 38 200, |
| 39 None) |
| 40 |
| 41 def json(self, step_name, obj): |
| 42 return self._response( |
| 43 step_name, |
| 44 self.m.json.output(obj, name='output'), |
| 45 len(self.m.json.dumps(obj)), |
| 46 200, |
| 47 None) |
OLD | NEW |