def test_process_result_multiple_types(response_transmute_func): result = Response("foo", 401) output = process_result(response_transmute_func, default_context, result, None, CONTENT_TYPE) assert json.loads(output["body"].decode()) == "foo" assert output["code"] == 401 result = Response(False, 201) output = process_result(response_transmute_func, default_context, result, None, CONTENT_TYPE) assert json.loads(output["body"].decode()) is False assert output["code"] == 201
def wrapper(*args, **kwargs): if kwargs['Authorization'] is not None: token_tokens = kwargs['Authorization'].split(" ") token_value = token_tokens[1] if len( token_tokens) > 1 else token_tokens[0] kwargs.update({'auth_token': token.decode(token_value)}) del kwargs['Authorization'] result = handler(*args, **kwargs) if result[1] != 200: log.debug(f'Error response: {result}') return Response(result[0], result[1]) return result[0]
def create_if_authorized(username): if username != "im the boss": return Response("this is unauthorized!", 201) else: return Response(True, 401)