1
0
mirror of https://github.com/httpie/cli.git synced 2025-06-17 00:17:45 +02:00

Refactored main() into program() + main()

This commit is contained in:
Jakub Roztocil
2016-03-01 21:10:54 +08:00
parent 01ca7f0eb2
commit 2a25d71aa4
2 changed files with 108 additions and 69 deletions

View File

@ -3,6 +3,7 @@ from pytest import raises
from requests import Request, Timeout
from requests.exceptions import ConnectionError
from httpie import ExitStatus
from httpie.core import main
error_msg = None
@ -17,8 +18,8 @@ def test_error(get_response):
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
ret = main(['--ignore-stdin', 'www.google.com'], custom_log_error=error)
assert ret == ExitStatus.ERROR
assert error_msg == (
'ConnectionError: '
'Connection aborted while doing GET request to URL: '
@ -43,6 +44,6 @@ def test_timeout(get_response):
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
ret = main(['--ignore-stdin', 'www.google.com'], custom_log_error=error)
assert ret == ExitStatus.ERROR_TIMEOUT
assert error_msg == 'Request timed out (30s).'