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 |
| 10 class UrlTestApi(recipe_test_api.RecipeTestApi): # pragma: no cover |
| 11 |
| 12 def _response(self, step_name, data, size, status_code, error_body): |
| 13 step_data = [ |
| 14 self.m.json.output({ |
| 15 'status_code': status_code, |
| 16 'success': status_code in (httplib.OK, httplib.NO_CONTENT), |
| 17 'size': size, |
| 18 'error_body': error_body, |
| 19 }, name='status_json'), |
| 20 ] |
| 21 if data: |
| 22 step_data.append(data) |
| 23 return self.step_data(step_name, *step_data) |
| 24 |
| 25 def error(self, step_name, status_code, body=None): |
| 26 body = body or 'HTTP Error (%d)' % (status_code,) |
| 27 return self._response( |
| 28 step_name, |
| 29 None, |
| 30 len(body), |
| 31 status_code, |
| 32 body) |
| 33 |
| 34 def text(self, step_name, v): |
| 35 return self._response( |
| 36 step_name, |
| 37 self.m.raw_io.output_text(v, name='output'), |
| 38 len(v), |
| 39 200, |
| 40 None) |
| 41 |
| 42 def json(self, step_name, obj): |
| 43 return self._response( |
| 44 step_name, |
| 45 self.m.json.output(obj, name='output'), |
| 46 len(self.m.json.dumps(obj)), |
| 47 200, |
| 48 None) |
OLD | NEW |