Example #1
0
 def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
     self.logger.debug("Making request HTTP. URI: %s, Method: %s",
                       self.endpoint_uri, method)
     request_data = self.encode_rpc_request(method, params)
     raw_response = make_post_request(self.endpoint_uri, request_data,
                                      **self.get_request_kwargs())
     response = self.decode_rpc_response(raw_response)
     self.logger.debug(
         "Getting response HTTP. URI: %s, "
         "Method: %s, Response: %s", self.endpoint_uri, method, response)
     return response
Example #2
0
 def make_batch_request(self, text):
     self.logger.debug("Making request HTTP. URI: %s, Request: %s",
                       self.endpoint_uri, text)
     request_data = text.encode('utf-8')
     raw_response = make_post_request(self.endpoint_uri, request_data,
                                      **self.get_request_kwargs())
     response = self.decode_rpc_response(raw_response)
     self.logger.debug(
         "Getting response HTTP. URI: %s, "
         "Request: %s, Response: %s", self.endpoint_uri, text, response)
     return response
Example #3
0
 def make_request(self, method, params):
     self.logger.debug("Making request HTTP. URI: %s, Method: %s",
                       self.endpoint_uri, method)
     request_data = self.encode_rpc_request(method, params)
     raw_response = make_post_request(
         self.endpoint_uri,
         request_data,
         **self.get_request_kwargs()
     )
     response = self.decode_rpc_response(raw_response)
     self.logger.debug("Getting response HTTP. URI: %s, "
                       "Method: %s, Response: %s",
                       self.endpoint_uri, method, response)
     return response
def test_make_post_request_no_args(mocker):
    mocker.patch("requests.Session.post", return_value=MockedResponse())
    request._session_cache.clear()

    # Submit a first request to create a session with default parameters
    assert len(request._session_cache) == 0
    response = request.make_post_request(URI, b'request')
    assert response == "content"
    assert len(request._session_cache) == 1
    session = request._session_cache.values()[0]
    session.post.assert_called_once_with(URI, data=b'request', timeout=10)

    # Ensure the adapter was created with default values
    check_adapters_mounted(session)
    adapter = session.get_adapter(URI)
    assert isinstance(adapter, HTTPAdapter)
    assert adapter._pool_connections == DEFAULT_POOLSIZE
    assert adapter._pool_maxsize == DEFAULT_POOLSIZE