def test_format_response_with_request_id(self): req = FakeRequest() Service.set_request_id(req, 'req0') response = Service.format_response({'foo': 'bar'}, req) assert req.headers == {'content-type': ['application/json']} assert json.loads(response) == { 'request_id': 'req0', 'foo': 'bar', }
def test_format_error_with_status_code(self): req = FakeRequest() Service.set_request_id(req, 'req0') response = Service.format_error(APIError('teapot', 418), req) assert req.code == 418 assert req.headers == {'content-type': ['application/json']} assert json.loads(response) == { 'request_id': 'req0', 'error': 'teapot', }
def test_format_error_with_request_id(self): req = FakeRequest() Service.set_request_id(req, 'req0') response = Service.format_error(APIError('bad thing'), req) assert req.code == 500 assert req.headers == {'content-type': ['application/json']} assert json.loads(response) == { 'request_id': 'req0', 'error': 'bad thing', }
def test_request_id(self): req = FakeRequest() assert Service.get_request_id(req) is None Service.set_request_id(req, 'foo') assert Service.get_request_id(req) == 'foo'
def hello(slf, request, request_id): Service.set_request_id(request, request_id) params = Service.get_json_params(request, ['who']) return {'hello': params['who']}