def test_get_url_params_no_request_id(self): req = FakeRequest(args={'foo': ['hello', 'bye'], 'bar': ['world']}) assert Service.get_url_params(req, ['foo'], ['bar', 'baz']) == { 'foo': 'hello', 'bar': 'world', } assert Service.get_request_id(req) is None
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_get_url_params_with_request_id(self): req = FakeRequest(args={ 'request_id': ['req0'], 'foo': ['hello', 'bye'], 'bar': ['world'], }) assert Service.get_url_params(req, ['request_id', 'foo', 'bar']) == { 'request_id': 'req0', 'foo': 'hello', 'bar': 'world', } assert Service.get_request_id(req) == 'req0'
def test_get_params_optional(self): params = { 'foo': 'hello', 'bar': 'world', } assert Service.get_params(params, ['foo'], ['bar']) == { 'foo': 'hello', 'bar': 'world', } assert Service.get_params(params, ['foo'], ['bar', 'baz']) == { 'foo': 'hello', 'bar': 'world', }
def test_get_params_mandatory(self): params = { 'foo': 'hello', 'bar': 'world', } assert Service.get_params(params, ['foo', 'bar']) == { 'foo': 'hello', 'bar': 'world', }
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']}
def hello(slf, request): params = Service.get_url_params(request, ['request_id', 'who']) return {'hello': params['who']}
def test_get_json_params(self): req = FakeRequest(content=json.dumps({'foo': 'hello', 'bar': 'world'})) assert Service.get_json_params(req, ['foo'], ['bar', 'baz']) == { 'foo': 'hello', 'bar': 'world', }