-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
tox | ||
mock | ||
pytest | ||
pytest-cov | ||
pytest-httpbin | ||
|
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,48 @@ | ||
import mock | ||
from pytest import raises | ||
from requests import Request, Timeout | ||
from requests.exceptions import ConnectionError | ||
|
||
from httpie.core import main | ||
|
||
error_msg = None | ||
|
||
|
||
@mock.patch('httpie.core.get_response') | ||
def test_error(get_response): | ||
def error(msg, *args, **kwargs): | ||
global error_msg | ||
error_msg = msg % args | ||
|
||
exc = ConnectionError('Connection aborted') | ||
exc.request = Request(method='GET', url='http://www.google.com') | ||
get_response.side_effect = exc | ||
ret = main(['--ignore-stdin', 'www.google.com'], error=error) | ||
assert ret == 1 | ||
assert error_msg == ( | ||
'ConnectionError: ' | ||
'Connection aborted while doing GET request to URL: ' | ||
'http://www.google.com') | ||
|
||
|
||
@mock.patch('httpie.core.get_response') | ||
def test_error_traceback(get_response): | ||
exc = ConnectionError('Connection aborted') | ||
exc.request = Request(method='GET', url='http://www.google.com') | ||
get_response.side_effect = exc | ||
with raises(ConnectionError): | ||
ret = main(['--ignore-stdin', '--traceback', 'www.google.com']) | ||
|
||
|
||
@mock.patch('httpie.core.get_response') | ||
def test_timeout(get_response): | ||
def error(msg, *args, **kwargs): | ||
global error_msg | ||
error_msg = msg % args | ||
|
||
exc = Timeout('Request timed out') | ||
exc.request = Request(method='GET', url='http://www.google.com') | ||
get_response.side_effect = exc | ||
ret = main(['--ignore-stdin', 'www.google.com'], error=error) | ||
assert ret == 2 | ||
assert error_msg == 'Request timed out (30s).' |