2014-04-24 16:17:04 +03:00
|
|
|
import pytest
|
|
|
|
|
2014-04-24 15:07:31 +03:00
|
|
|
from httpie.compat import is_windows
|
2014-04-27 01:07:13 +03:00
|
|
|
from httpie.output.streams import BINARY_SUPPRESSED_NOTICE
|
2021-05-05 14:13:39 +02:00
|
|
|
from .utils import StdinBytesIO, http, MockEnvironment
|
|
|
|
from .fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
|
2016-03-03 12:47:12 +02:00
|
|
|
# GET because httpbin 500s with binary POST body.
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(is_windows,
|
|
|
|
reason='Pretty redirect not supported under Windows')
|
|
|
|
def test_pretty_redirected_stream(httpbin):
|
|
|
|
"""Test that --stream works with prettified redirected output."""
|
2020-09-28 12:16:57 +02:00
|
|
|
env = MockEnvironment(
|
|
|
|
colors=256,
|
|
|
|
stdin=StdinBytesIO(BIN_FILE_PATH.read_bytes()),
|
|
|
|
stdin_isatty=False,
|
|
|
|
stdout_isatty=False,
|
|
|
|
)
|
|
|
|
r = http('--verbose', '--pretty=all', '--stream', 'GET',
|
|
|
|
httpbin.url + '/get', env=env)
|
2016-03-03 12:47:12 +02:00
|
|
|
assert BINARY_SUPPRESSED_NOTICE.decode() in r
|
|
|
|
|
|
|
|
|
|
|
|
def test_encoded_stream(httpbin):
|
|
|
|
"""Test that --stream works with non-prettified
|
|
|
|
redirected terminal output."""
|
2020-09-28 12:16:57 +02:00
|
|
|
env = MockEnvironment(
|
|
|
|
stdin=StdinBytesIO(BIN_FILE_PATH.read_bytes()),
|
|
|
|
stdin_isatty=False,
|
|
|
|
)
|
|
|
|
r = http('--pretty=none', '--stream', '--verbose', 'GET',
|
|
|
|
httpbin.url + '/get', env=env)
|
2016-03-03 12:47:12 +02:00
|
|
|
assert BINARY_SUPPRESSED_NOTICE.decode() in r
|
|
|
|
|
|
|
|
|
|
|
|
def test_redirected_stream(httpbin):
|
|
|
|
"""Test that --stream works with non-prettified
|
|
|
|
redirected terminal output."""
|
2020-09-28 12:16:57 +02:00
|
|
|
env = MockEnvironment(
|
|
|
|
stdout_isatty=False,
|
|
|
|
stdin_isatty=False,
|
|
|
|
stdin=StdinBytesIO(BIN_FILE_PATH.read_bytes()),
|
|
|
|
)
|
|
|
|
r = http('--pretty=none', '--stream', '--verbose', 'GET',
|
|
|
|
httpbin.url + '/get', env=env)
|
2016-03-03 12:47:12 +02:00
|
|
|
assert BIN_FILE_CONTENT in r
|