Beispiel #1
0
def test_timeout_passed_to_fido():
    with patch('bravado.fido_client.fido.fetch') as fetch:
        fido_client = FidoClient()
        request_params = dict(url='http://foo.com/', timeout=1)
        fido_client.request(request_params, response_callback=None)
        assert fetch.call_args == call(
            'http://foo.com/?', body='', headers={}, method='GET', timeout=1)
Beispiel #2
0
def test_no_timeouts_passed_to_fido():
    with patch('bravado.fido_client.fido.fetch') as fetch:
        fido_client = FidoClient()
        request_params = dict(url='http://foo.com/')
        fido_client.request(request_params)
        assert fetch.call_args == mock.call(
            'http://foo.com/?', body='', headers={}, method='GET')
Beispiel #3
0
    def test_multiple_requests_against_fido_client(self):
        port = get_hopefully_free_port()
        launch_threaded_http_server(port)

        client = FidoClient()

        request_one_params = {
            'method': 'GET',
            'headers': {},
            'url': "http://localhost:{0}/1".format(port),
            'params': {},
        }

        request_two_params = {
            'method': 'GET',
            'headers': {},
            'url': "http://localhost:{0}/2".format(port),
            'params': {},
        }

        eventual_one = client.request(request_one_params)
        eventual_two = client.request(request_two_params)
        resp_one = eventual_one.result(timeout=1)
        resp_two = eventual_two.result(timeout=1)

        self.assertEqual(resp_one.text, ROUTE_1_RESPONSE)
        self.assertEqual(resp_two.text, ROUTE_2_RESPONSE)
Beispiel #4
0
def test_connect_timeout_and_timeout_passed_to_fido():
    with patch("bravado.fido_client.fido.fetch") as fetch:
        fido_client = FidoClient()
        request_params = dict(url="http://foo.com/", connect_timeout=1, timeout=2)
        fido_client.request(request_params, response_callback=None)
        assert fetch.call_args == mock.call(
            "http://foo.com/?", body="", headers={}, method="GET", connect_timeout=1, timeout=2
        )
Beispiel #5
0
def test_no_timeouts_passed_to_fido():
    with patch('bravado.fido_client.fido.fetch') as fetch:
        fido_client = FidoClient()
        request_params = dict(url='http://foo.com/')
        fido_client.request(request_params)
        assert fetch.call_args == mock.call('http://foo.com/?',
                                            body='',
                                            headers={},
                                            method='GET')
Beispiel #6
0
def test_connect_timeout_passed_to_fido():
    with patch('bravado.fido_client.fido.fetch') as fetch:
        fido_client = FidoClient()
        request_params = dict(url='http://foo.com/', connect_timeout=1)
        fido_client.request(request_params, response_callback=None)
        assert fetch.call_args == call('http://foo.com/?',
                                       body='',
                                       headers={},
                                       method='GET',
                                       connect_timeout=1)
def test_prepare_request_for_twisted_get():
    request_params = {'url': 'http://example.com/api-docs'}
    request_for_twisted = FidoClient.prepare_request_for_twisted(
        request_params)

    assert request_for_twisted == {
        'body': None,
        'headers': {},
        'method': 'GET',
        'url': 'http://example.com/api-docs',
    }
Beispiel #8
0
def test_request_connect_timeout_passed_to_fido():
    with patch('bravado.fido_client.fido.fetch') as fetch:
        request_params = dict(url='http://foo.com/', connect_timeout=1)
        FidoClient().request(request_params)
        assert fetch.call_args == mock.call(
            url='http://foo.com/',
            body=None,
            headers={},
            method='GET',
            connect_timeout=1,
        )
def test_prepare_request_for_twisted_get():
    request_params = {
        'url': 'http://example.com/api-docs'
    }
    request_for_twisted = FidoClient.prepare_request_for_twisted(request_params)

    assert request_for_twisted == {
        'body': None,
        'headers': {},
        'method': 'GET',
        'url': 'http://example.com/api-docs',
    }
def test_prepare_request_for_twisted_timeouts_added():
    request_params = dict(
        url='http://example.com/api-docs', timeout=15, connect_timeout=15)
    request_for_twisted = FidoClient.prepare_request_for_twisted(request_params)

    assert request_for_twisted == {
        'body': None,
        'headers': {},
        'method': 'GET',
        'url': 'http://example.com/api-docs',
        'timeout': 15,
        'connect_timeout': 15,
    }
def test_prepare_request_for_twisted_header_values_are_bytes():
    request_params = {
        'url': 'http://example.com/api-docs',
        'headers': {b'X-Foo': b'hi'},
        'method': 'GET',
    }
    request_for_twisted = FidoClient.prepare_request_for_twisted(request_params)

    assert request_for_twisted == {
        'body': None,
        'headers': {'X-Foo': b'hi'},
        'method': 'GET',
        'url': 'http://example.com/api-docs'
    }
def test_prepare_request_for_twisted():
    request_params = dict(
        url='http://example.com/api-docs',
        method='POST',
        data=42,
        params={'username': '******'},
    )
    request_for_twisted = FidoClient.prepare_request_for_twisted(request_params)

    assert request_for_twisted == {
        'body': 42,
        'headers': {'Content-Type': 'application/x-www-form-urlencoded'},
        'method': 'POST',
        'url': 'http://example.com/api-docs?username=yelp'
    }
def test_prepare_request_for_twisted_body_is_bytes():
    request_params = {
        'url': 'http://example.com/api-docs',
        'method': 'POST',
        'data': 42,
        'params': {'username': '******'},
    }
    request_for_twisted = FidoClient.prepare_request_for_twisted(request_params)

    assert request_for_twisted == {
        'body': b'42',
        'headers': {'Content-Type': 'application/x-www-form-urlencoded'},
        'method': 'POST',
        'url': 'http://example.com/api-docs?username=yelp'
    }
def test_prepare_request_for_twisted_timeouts_added():
    request_params = {
        'url': 'http://example.com/api-docs',
        'timeout': 15,
        'connect_timeout': 15
    }
    request_for_twisted = FidoClient.prepare_request_for_twisted(
        request_params)

    assert request_for_twisted == {
        'body': None,
        'headers': {},
        'method': 'GET',
        'url': 'http://example.com/api-docs',
        'timeout': 15,
        'connect_timeout': 15,
    }
def test_prepare_request_for_twisted_header_values_are_bytes():
    request_params = {
        'url': 'http://example.com/api-docs',
        'headers': {
            b'X-Foo': b'hi'
        },
        'method': 'GET',
    }
    request_for_twisted = FidoClient.prepare_request_for_twisted(
        request_params)

    assert request_for_twisted == {
        'body': None,
        'headers': {
            'X-Foo': b'hi'
        },
        'method': 'GET',
        'url': 'http://example.com/api-docs'
    }
def test_prepare_request_for_twisted_body_is_bytes():
    request_params = {
        'url': 'http://example.com/api-docs',
        'method': 'POST',
        'data': 42,
        'params': {
            'username': '******'
        },
    }
    request_for_twisted = FidoClient.prepare_request_for_twisted(
        request_params)

    assert request_for_twisted == {
        'body': b'42',
        'headers': {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        'method': 'POST',
        'url': 'http://example.com/api-docs?username=yelp'
    }
Beispiel #17
0
def test_equality_of_different_http_clients_with_the_same_configurations(
        http_client):
    assert http_client == FidoClient()
Beispiel #18
0
import mock
import pytest
import typing

from bravado.client import SwaggerClient
from bravado.config import CONFIG_DEFAULTS
from bravado.http_client import HttpClient
from bravado.requests_client import RequestsClient
from bravado.swagger_model import load_file

_HTTP_CLIENTS = [None, RequestsClient()
                 ]  # type: typing.List[typing.Optional[HttpClient]]
try:
    from bravado.fido_client import FidoClient
    _HTTP_CLIENTS.append(FidoClient())
except ImportError:
    pass


@pytest.fixture
def mock_spec():
    with mock.patch('bravado.client.Spec') as _mock:
        yield _mock


def test_remove_bravado_configs(mock_spec, processed_default_config):
    config = CONFIG_DEFAULTS.copy()
    config['validate_swagger_spec'] = False  # bravado_core config

    SwaggerClient.from_spec({}, config=config)
Beispiel #19
0
 def setup_class(cls):
     cls.PORT = get_hopefully_free_port()
     launch_threaded_http_server(cls.PORT)
     cls.fido_client = FidoClient()
Beispiel #20
0
from bravado.fido_client import FidoClient
from bravado.swagger_model import load_file
from bravado.exception import HTTPServerError, HTTPNotFound, HTTPForbidden, HTTPUnauthorized, HTTPError, HTTPClientError
from xml.etree import cElementTree as ET
from pprint import PrettyPrinter

from config import *

pprinter = PrettyPrinter()

for retry in range(5):
    try:
        esi_client = SwaggerClient.from_spec(
            load_file('esi.json'),
            config={'also_return_response': True},
            http_client=FidoClient())
        xml_client = requests.Session()
        break
    except (HTTPServerError, HTTPNotFound), e:
        if retry < 4:
            print('Attempt #{} - {}'.format(retry, e))
            time.sleep(60)
            continue
        raise


def name_to_id(name, name_type):
    name_id = esi_api('Search.get_search',
                      categories=[name_type],
                      search=name,
                      strict=True).get(name_type)[0]
Beispiel #21
0
def http_client():
    return FidoClient()
Beispiel #22
0
def test_equality_of_different_http_clients_with_different_configurations(
        http_client):
    class CustomAdapter(FidoFutureAdapter):
        pass

    assert http_client != FidoClient(future_adapter_class=CustomAdapter)
Beispiel #23
0
 def setup_class(cls):
     cls.http_client = FidoClient()