2014-04-24 16:17:04 +03:00
|
|
|
import pytest
|
|
|
|
|
2014-04-24 15:07:31 +03:00
|
|
|
from httpie.compat import is_windows
|
|
|
|
from httpie.output import BINARY_SUPPRESSED_NOTICE
|
2014-04-24 16:17:04 +03:00
|
|
|
from tests import http, httpbin, TestEnvironment
|
|
|
|
from tests.fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
|
2014-04-25 12:39:59 +03:00
|
|
|
class TestStream:
|
2014-04-24 15:07:31 +03:00
|
|
|
# GET because httpbin 500s with binary POST body.
|
|
|
|
|
2014-04-24 16:17:04 +03:00
|
|
|
@pytest.mark.skipif(is_windows,
|
|
|
|
reason='Pretty redirect not supported under Windows')
|
2014-04-24 15:07:31 +03:00
|
|
|
def test_pretty_redirected_stream(self):
|
|
|
|
"""Test that --stream works with prettified redirected output."""
|
|
|
|
with open(BIN_FILE_PATH, 'rb') as f:
|
2014-04-24 16:48:01 +03:00
|
|
|
env = TestEnvironment(colors=256, stdin=f,
|
|
|
|
stdin_isatty=False,
|
|
|
|
stdout_isatty=False)
|
|
|
|
r = http('--verbose', '--pretty=all', '--stream', 'GET',
|
|
|
|
httpbin('/get'), env=env)
|
2014-04-24 15:58:15 +03:00
|
|
|
assert BINARY_SUPPRESSED_NOTICE.decode() in r
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
def test_encoded_stream(self):
|
|
|
|
"""Test that --stream works with non-prettified
|
|
|
|
redirected terminal output."""
|
|
|
|
with open(BIN_FILE_PATH, 'rb') as f:
|
2014-04-24 16:48:01 +03:00
|
|
|
env = TestEnvironment(stdin=f, stdin_isatty=False)
|
|
|
|
r = http('--pretty=none', '--stream', '--verbose', 'GET',
|
|
|
|
httpbin('/get'), env=env)
|
2014-04-24 15:58:15 +03:00
|
|
|
assert BINARY_SUPPRESSED_NOTICE.decode() in r
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
def test_redirected_stream(self):
|
|
|
|
"""Test that --stream works with non-prettified
|
|
|
|
redirected terminal output."""
|
|
|
|
with open(BIN_FILE_PATH, 'rb') as f:
|
2014-04-24 19:20:23 +03:00
|
|
|
env = TestEnvironment(stdout_isatty=False,
|
|
|
|
stdin_isatty=False,
|
|
|
|
stdin=f)
|
2014-04-24 16:48:01 +03:00
|
|
|
r = http('--pretty=none', '--stream', '--verbose', 'GET',
|
|
|
|
httpbin('/get'), env=env)
|
2014-04-24 15:58:15 +03:00
|
|
|
assert BIN_FILE_CONTENT in r
|