2015-02-08 18:17:35 +02:00
|
|
|
import mock
|
|
|
|
from pytest import raises
|
2019-09-03 17:14:39 +02:00
|
|
|
from requests import Request
|
2015-02-08 18:17:35 +02:00
|
|
|
from requests.exceptions import ConnectionError
|
|
|
|
|
2019-09-16 13:26:18 +02:00
|
|
|
from httpie.status import ExitStatus
|
2015-02-08 18:17:35 +02:00
|
|
|
from httpie.core import main
|
2019-09-03 17:14:39 +02:00
|
|
|
from utils import HTTP_OK, http
|
2019-08-29 09:39:19 +02:00
|
|
|
|
2015-02-08 18:17:35 +02:00
|
|
|
|
|
|
|
error_msg = None
|
|
|
|
|
|
|
|
|
2019-09-03 17:14:39 +02:00
|
|
|
@mock.patch('httpie.core.program')
|
2015-02-08 18:17:35 +02:00
|
|
|
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
|
2019-08-29 13:08:02 +02:00
|
|
|
ret = main(['http', '--ignore-stdin', 'www.google.com'], custom_log_error=error)
|
2016-03-01 15:10:54 +02:00
|
|
|
assert ret == ExitStatus.ERROR
|
2015-02-08 18:17:35 +02:00
|
|
|
assert error_msg == (
|
|
|
|
'ConnectionError: '
|
2019-09-03 17:14:39 +02:00
|
|
|
'Connection aborted while doing a GET request to URL: '
|
2015-02-08 18:17:35 +02:00
|
|
|
'http://www.google.com')
|
|
|
|
|
|
|
|
|
2019-09-03 17:14:39 +02:00
|
|
|
@mock.patch('httpie.core.program')
|
2015-02-08 18:17:35 +02:00
|
|
|
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):
|
2019-08-29 13:08:02 +02:00
|
|
|
main(['http', '--ignore-stdin', '--traceback', 'www.google.com'])
|
2015-02-08 18:17:35 +02:00
|
|
|
|
|
|
|
|
2019-08-29 09:39:19 +02:00
|
|
|
def test_max_headers_limit(httpbin_both):
|
|
|
|
with raises(ConnectionError) as e:
|
|
|
|
http('--max-headers=1', httpbin_both + '/get')
|
|
|
|
assert 'got more than 1 headers' in str(e.value)
|
|
|
|
|
|
|
|
|
|
|
|
def test_max_headers_no_limit(httpbin_both):
|
|
|
|
assert HTTP_OK in http('--max-headers=0', httpbin_both + '/get')
|