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, status_code): |
| 13 step_data = [ |
| 14 self.m.json.output({ |
| 15 'status_code': status_code, |
| 16 'success': status_code in (httplib.OK, httplib.NO_CONTENT), |
| 17 }, name='status_json'), |
| 18 ] |
| 19 if data: |
| 20 step_data.append(data) |
| 21 return self.step_data(step_name, *step_data) |
| 22 |
| 23 def error(self, step_name, status_code): |
| 24 return self._response( |
| 25 step_name, |
| 26 None, |
| 27 status_code) |
| 28 |
| 29 def text(self, step_name, v): |
| 30 return self._response( |
| 31 step_name, |
| 32 self.m.raw_io.output_text(v, name='output'), |
| 33 200) |
| 34 |
| 35 def json(self, step_name, obj): |
| 36 return self._response( |
| 37 step_name, |
| 38 self.m.json.output(obj, name='output'), |
| 39 200) |
OLD | NEW |