def httpretty_callback(request, uri, headers): """httpretty request handler. converts a call intercepted by httpretty to the stack-in-a-box infrastructure :param request: request object :param uri: the uri of the request :param headers: headers for the response :returns: tuple - (int, dict, string) containing: int - the http response status code dict - the headers for the http response string - http string response """ method = request.method response_headers = CaseInsensitiveDict() response_headers.update(headers) request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers return StackInABox.call_into(method, request, uri, response_headers)
def httpretty_callback(request, uri, headers): """httpretty request handler. converts a call intercepted by httpretty to the stack-in-a-box infrastructure :param request: request object :param uri: the uri of the request :param headers: headers for the response :returns: tuple - (int, dict, string) containing: int - the http response status code dict - the headers for the http response string - http string response """ method = request.method response_headers = CaseInsensitiveDict() response_headers.update(headers) request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers return StackInABox.call_into(method, request, uri, response_headers)
def httpretty_callback(request, uri, headers): method = request.method response_headers = CaseInsensitiveDict() response_headers.update(headers) request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers return StackInABox.call_into(method, request, uri, response_headers)
def responses_callback(request): method = request.method headers = CaseInsensitiveDict() request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers uri = request.url return StackInABox.call_into(method, request, uri, headers)
def handle(self, request, uri): """Request handler interface. :param request: Python requests Request object :param uri: URI of the request """ # Convert the call over to Stack-In-A-Box method = request.method headers = CaseInsensitiveDict() request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers stackinabox_result = StackInABox.call_into(method, request, uri, headers) # reformat the result for easier use status_code, output_headers, body = stackinabox_result json_data = None text_data = None content_data = None body_data = None # if the body is a string-type... if isinstance(body, six.string_types): # Try to convert it to JSON text_data = body try: json_data = json.dumps(text_data) text_data = json_data except Exception: json_data = None text_data = body # if the body is binary, then it's the content elif isinstance(body, six.binary_type): content_data = body # by default, it's just body data else: # default to body data body_data = body # build the Python requests' Response object return requests_mock.response.create_response( request, headers=output_headers, status_code=status_code, body=body_data, json=json_data, text=text_data, content=content_data )
def handle(self, request, uri): """Request handler interface. :param request: Python requests Request object :param uri: URI of the request """ # Convert the call over to Stack-In-A-Box method = request.method headers = CaseInsensitiveDict() request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers stackinabox_result = StackInABox.call_into(method, request, uri, headers) # reformat the result for easier use status_code, output_headers, body = stackinabox_result json_data = None text_data = None content_data = None body_data = None # if the body is a string-type... if isinstance(body, six.string_types): # Try to convert it to JSON text_data = body try: json_data = json.dumps(text_data) text_data = json_data except Exception: json_data = None text_data = body # if the body is binary, then it's the content elif isinstance(body, six.binary_type): content_data = body # by default, it's just body data else: # default to body data body_data = body # build the Python requests' Response object return requests_mock.response.create_response( request, headers=output_headers, status_code=status_code, body=body_data, json=json_data, text=text_data, content=content_data )
def httpretty_callback(request, uri, headers): method = request.method response_headers = CaseInsensitiveDict() response_headers.update(headers) request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers return StackInABox.call_into(method, request, uri, response_headers)
def responses_callback(request): method = request.method headers = CaseInsensitiveDict() request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers uri = request.url return StackInABox.call_into(method, request, uri, headers)
def handle(self, request, uri): """Request handler interface. :param request: Python requests Request object :param uri: URI of the request """ # Convert the call over to Stack-In-A-Box method = request.method headers = CaseInsensitiveDict() request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers stackinabox_result = StackInABox.call_into(method, request, uri, headers) # reformat the result for easier use status_code, output_headers, body = stackinabox_result text_data = None content_data = None body_data = None # if the body is a string-type... if isinstance(body, six.string_types): logger.debug('running text result') # Try to convert it to JSON text_data = body # if the body is binary, then it's the content elif isinstance(body, six.binary_type): logger.debug('running binary result') content_data = body # by default, it's just body data else: # default to body data logger.debug('running default result') body_data = body # build the Python requests' Response object # `raw` and `json` parameters shouldn't be used return requests_mock.response.create_response( request, headers=output_headers, status_code=status_code, body=body_data, text=text_data, content=content_data )
def handle(self, request, uri): method = request.method headers = CaseInsensitiveDict() request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers stackinabox_result = StackInABox.call_into(method, request, uri, headers) status_code, output_headers, body = stackinabox_result json_data = None text_data = None content_data = None body_data = None if isinstance(body, six.string_types): text_data = body try: json_data = json.dumps(text_data) text_data = json_data except: json_data = None text_data = body elif isinstance(body, six.binary_type): content_data = body else: # default to body data body_data = body return requests_mock.response.create_response( request, headers=output_headers, status_code=status_code, body=body_data, json=json_data, text=text_data, content=content_data )
def responses_callback(request): """Responses Request Handler. Converts a call intercepted by Responses to the Stack-In-A-Box infrastructure :param request: request object :returns: tuple - (int, dict, string) containing: int - the HTTP response status code dict - the headers for the HTTP response string - HTTP string response """ method = request.method headers = CaseInsensitiveDict() request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers uri = request.url return StackInABox.call_into(method, request, uri, headers)
def responses_callback(request): """Responses Request Handler. Converts a call intercepted by Responses to the Stack-In-A-Box infrastructure :param request: request object :returns: tuple - (int, dict, string) containing: int - the HTTP response status code dict - the headers for the HTTP response string - HTTP string response """ method = request.method headers = CaseInsensitiveDict() request_headers = CaseInsensitiveDict() request_headers.update(request.headers) request.headers = request_headers uri = request.url return StackInABox.call_into(method, request, uri, headers)