2016-02-29 07:56:21 +02:00
|
|
|
"""High-level tests."""
|
2016-03-09 15:58:34 +02:00
|
|
|
import pytest
|
|
|
|
|
2019-09-16 13:26:18 +02:00
|
|
|
from httpie.status import ExitStatus
|
2016-02-29 07:56:21 +02:00
|
|
|
from utils import http, HTTP_OK
|
|
|
|
|
|
|
|
|
2016-03-05 20:09:52 +02:00
|
|
|
def test_follow_all_redirects_shown(httpbin):
|
|
|
|
r = http('--follow', '--all', httpbin.url + '/redirect/2')
|
|
|
|
assert r.count('HTTP/1.1') == 3
|
|
|
|
assert r.count('HTTP/1.1 302 FOUND', 2)
|
|
|
|
assert HTTP_OK in r
|
|
|
|
|
|
|
|
|
2016-03-09 15:58:34 +02:00
|
|
|
@pytest.mark.parametrize('follow_flag', ['--follow', '-F'])
|
|
|
|
def test_follow_without_all_redirects_hidden(httpbin, follow_flag):
|
|
|
|
r = http(follow_flag, httpbin.url + '/redirect/2')
|
2016-02-29 08:31:27 +02:00
|
|
|
assert r.count('HTTP/1.1') == 1
|
|
|
|
assert HTTP_OK in r
|
2016-02-29 07:56:21 +02:00
|
|
|
|
|
|
|
|
2016-03-05 20:09:52 +02:00
|
|
|
def test_follow_all_output_options_used_for_redirects(httpbin):
|
|
|
|
r = http('--check-status',
|
|
|
|
'--follow',
|
|
|
|
'--all',
|
|
|
|
'--print=H',
|
|
|
|
httpbin.url + '/redirect/2')
|
|
|
|
assert r.count('GET /') == 3
|
|
|
|
assert HTTP_OK not in r
|
|
|
|
|
2019-09-03 17:14:39 +02:00
|
|
|
#
|
|
|
|
# def test_follow_redirect_output_options(httpbin):
|
|
|
|
# r = http('--check-status',
|
|
|
|
# '--follow',
|
|
|
|
# '--all',
|
|
|
|
# '--print=h',
|
|
|
|
# '--history-print=H',
|
|
|
|
# httpbin.url + '/redirect/2')
|
|
|
|
# assert r.count('GET /') == 2
|
|
|
|
# assert 'HTTP/1.1 302 FOUND' not in r
|
|
|
|
# assert HTTP_OK in r
|
|
|
|
#
|
2016-02-29 07:56:21 +02:00
|
|
|
|
2016-02-29 08:31:27 +02:00
|
|
|
|
|
|
|
def test_max_redirects(httpbin):
|
2019-09-03 17:14:39 +02:00
|
|
|
r = http(
|
|
|
|
'--max-redirects=1',
|
|
|
|
'--follow',
|
|
|
|
httpbin.url + '/redirect/3',
|
|
|
|
tolerate_error_exit_status=True,
|
|
|
|
)
|
2016-02-29 08:31:27 +02:00
|
|
|
assert r.exit_status == ExitStatus.ERROR_TOO_MANY_REDIRECTS
|