Esempio n. 1
0
    def request(self, request_params, operation=None, response_callbacks=None,
                request_config=None, authorization_token=None):
        sanitized_params, misc_options = self.separate_params(request_params)
        session = requests.Session()
        if authorization_token:
            session.headers.update({
                'Authorization': 'Bearer {}'.format(authorization_token)
            })
        session.headers.update({
            'User-Agent': self.user_agent
        })

        requests_future = RequestsFutureAdapter(
            session,
            self.authenticated_request(sanitized_params),
            misc_options,
        )

        if operation is not None and 'page' in operation.params:
            return ESIPageGenerator(requests_future,
                                    RequestsResponseAdapter,
                                    operation,
                                    response_callbacks,
                                    request_config=request_config,
                                    cache=self.cache)
        else:
            data = ESIPageGenerator(requests_future,
                                    RequestsResponseAdapter,
                                    operation,
                                    response_callbacks,
                                    request_config=request_config,
                                    cache=self.cache).get()
            session.close()
            return data
Esempio n. 2
0
def test_result_header_values_are_bytes(session, request):
    request.headers = {b'X-Foo': b'hi'}
    RequestsFutureAdapter(session, request, misc_options={}).result()

    # prepare_request should be called with a request containing correctly
    # casted headers (bytestrings should be preserved)
    prepared_headers = session.prepare_request.call_args[0][0].headers
    assert prepared_headers == {b'X-Foo': b'hi'}
def test_result_header_values_are_bytes(session_mock, request_mock):
    session_mock.merge_environment_settings.return_value = {}
    request_mock.headers = {b'X-Foo': b'hi'}
    RequestsFutureAdapter(session_mock, request_mock, misc_options={'ssl_verify': True, 'ssl_cert': None}).result()

    # prepare_request should be called with a request containing correctly
    # casted headers (bytestrings should be preserved)
    prepared_headers = session_mock.prepare_request.call_args[0][0].headers
    assert prepared_headers == {b'X-Foo': b'hi'}
Esempio n. 4
0
def test_connect_timeout_only(session, request):
    misc_options = dict(connect_timeout=1)
    future = RequestsFutureAdapter(session, request, misc_options)
    assert future.build_timeout(result_timeout=None) == (1, None)
Esempio n. 5
0
def test_both_timeouts_the_same(session, request):
    misc_options = dict(timeout=10)
    future = RequestsFutureAdapter(session, request, misc_options)
    assert future.build_timeout(result_timeout=10) == 10
Esempio n. 6
0
def test_service_timeout_not_None_result_timeout_None(session, request):
    misc_options = dict(timeout=10)
    future = RequestsFutureAdapter(session, request, misc_options)
    assert future.build_timeout(result_timeout=None) == 10
Esempio n. 7
0
def test_no_timeouts(session, request):
    misc_options = {}
    future = RequestsFutureAdapter(session, request, misc_options)
    assert future.build_timeout(result_timeout=None) is None
Esempio n. 8
0
def test_no_service_timeout_and_result_timeout_not_None(session, request):
    misc_options = {}
    future = RequestsFutureAdapter(session, request, misc_options)
    assert future.build_timeout(result_timeout=1) == 1