-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from analogue/pass_timeouts
Support timeouts in _request_options
- Loading branch information
Showing
9 changed files
with
259 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from mock import patch, call, Mock | ||
import pytest | ||
import six | ||
|
||
|
||
try: | ||
from bravado.fido_client import FidoClient | ||
except ImportError: | ||
FidoClient = Mock() | ||
|
||
|
||
@pytest.mark.skipif(six.PY3, reason="twisted doesnt support py3 yet") | ||
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, response_callback=None) | ||
assert fetch.call_args == call( | ||
'http://foo.com/?', body='', headers={}, method='GET') | ||
|
||
|
||
@pytest.mark.skipif(six.PY3, reason="twisted doesnt support py3 yet") | ||
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) | ||
|
||
|
||
@pytest.mark.skipif(six.PY3, reason="twisted doesnt support py3 yet") | ||
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) | ||
|
||
|
||
@pytest.mark.skipif(six.PY3, reason="twisted doesnt support py3 yet") | ||
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 == call( | ||
'http://foo.com/?', body='', headers={}, method='GET', | ||
connect_timeout=1, timeout=2) |
12 changes: 12 additions & 0 deletions
12
tests/requests_client/RequestsClient/separate_params_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from bravado.requests_client import RequestsClient | ||
|
||
|
||
def test_separate_params(): | ||
request_params = { | ||
'url': 'http://foo.com', | ||
'connect_timeout': 1, | ||
'timeout': 2 | ||
} | ||
sanitized, misc = RequestsClient.separate_params(request_params) | ||
assert sanitized == {'url': 'http://foo.com'} | ||
assert misc == {'connect_timeout': 1, 'timeout': 2} |
75 changes: 75 additions & 0 deletions
75
tests/requests_client/RequestsFutureAdapter/build_timeout_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from mock import Mock | ||
import pytest | ||
from requests.sessions import Session | ||
|
||
from bravado.requests_client import RequestsFutureAdapter | ||
|
||
|
||
@pytest.fixture | ||
def request(): | ||
return dict(url='http://foo.com') | ||
|
||
|
||
@pytest.fixture | ||
def session(): | ||
return Mock(spec=Session) | ||
|
||
|
||
def test_no_timeouts(session, request): | ||
misc_options = {} | ||
future = RequestsFutureAdapter(session, request, misc_options) | ||
assert future.build_timeout(result_timeout=None) is None | ||
|
||
|
||
def test_service_timeout_and_result_timeout_None(session, request): | ||
misc_options = dict(timeout=1) | ||
future = RequestsFutureAdapter(session, request, misc_options) | ||
assert future.build_timeout(result_timeout=None) == 1 | ||
|
||
|
||
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 | ||
|
||
|
||
def test_service_timeout_lt_result_timeout(session, request): | ||
misc_options = dict(timeout=10) | ||
future = RequestsFutureAdapter(session, request, misc_options) | ||
assert future.build_timeout(result_timeout=11) == 11 | ||
|
||
|
||
def test_service_timeout_gt_result_timeout(session, request): | ||
misc_options = dict(timeout=11) | ||
future = RequestsFutureAdapter(session, request, misc_options) | ||
assert future.build_timeout(result_timeout=10) == 11 | ||
|
||
|
||
def test_service_timeout_None_result_timeout_not_None(session, request): | ||
misc_options = dict(timeout=None) | ||
future = RequestsFutureAdapter(session, request, misc_options) | ||
assert future.build_timeout(result_timeout=10) == 10 | ||
|
||
|
||
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 | ||
|
||
|
||
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 | ||
|
||
|
||
def test_connect_timeout_and_idle_timeout(session, request): | ||
misc_options = dict(connect_timeout=1, timeout=11) | ||
future = RequestsFutureAdapter(session, request, misc_options) | ||
assert future.build_timeout(result_timeout=None) == (1, 11) | ||
|
||
|
||
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) |