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)
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')
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_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, )
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)
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]
def http_client(): return FidoClient()
def test_equality_of_different_http_clients_with_different_configurations( http_client): class CustomAdapter(FidoFutureAdapter): pass assert http_client != FidoClient(future_adapter_class=CustomAdapter)
def test_equality_of_different_http_clients_with_the_same_configurations( http_client): assert http_client == FidoClient()
def setup_class(cls): cls.PORT = get_hopefully_free_port() launch_threaded_http_server(cls.PORT) cls.fido_client = FidoClient()
def setup_class(cls): cls.http_client = FidoClient()