Пример #1
0
def test_POST_stdin(httpbin_both):
    env = MockEnvironment(
        stdin=StdinBytesIO(FILE_PATH.read_bytes()),
        stdin_isatty=False,
    )
    r = http('--form', 'POST', httpbin_both + '/post', env=env)
    assert HTTP_OK in r
    assert FILE_CONTENT in r
Пример #2
0
 def test_ignore_stdin(self, httpbin):
     env = MockEnvironment(
         stdin=StdinBytesIO(FILE_PATH.read_bytes()),
         stdin_isatty=False,
     )
     r = http('--ignore-stdin', '--verbose', httpbin.url + '/get', env=env)
     assert HTTP_OK in r
     assert 'GET /get HTTP' in r, "Don't default to POST."
     assert FILE_CONTENT not in r, "Don't send stdin data."
Пример #3
0
def test_chunked_stdin():
    r = http('--verbose',
             '--chunked',
             HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
             env=MockEnvironment(
                 stdin=StdinBytesIO(FILE_PATH.read_bytes()),
                 stdin_isatty=False,
             ))
    assert HTTP_OK in r
    assert 'Transfer-Encoding: chunked' in r
    assert r.count(FILE_CONTENT) == 2
Пример #4
0
def test_chunked_stdin_multiple_chunks():
    stdin_bytes = FILE_PATH.read_bytes() + b'\n' + FILE_PATH.read_bytes()
    r = http('--verbose',
             '--chunked',
             HTTPBIN_WITH_CHUNKED_SUPPORT + '/post',
             env=MockEnvironment(
                 stdin=StdinBytesIO(stdin_bytes),
                 stdin_isatty=False,
                 stdout_isatty=True,
             ))
    assert HTTP_OK in r
    assert 'Transfer-Encoding: chunked' in r
    assert r.count(FILE_CONTENT) == 4
Пример #5
0
def test_encoded_stream(httpbin):
    """Test that --stream works with non-prettified
    redirected terminal output."""
    env = MockEnvironment(
        stdin=StdinBytesIO(BIN_FILE_PATH.read_bytes()),
        stdin_isatty=False,
    )
    r = http('--pretty=none',
             '--stream',
             '--verbose',
             'GET',
             httpbin.url + '/get',
             env=env)
    assert BINARY_SUPPRESSED_NOTICE.decode() in r
Пример #6
0
def test_redirected_stream(httpbin):
    """Test that --stream works with non-prettified
    redirected terminal output."""
    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)
    assert BIN_FILE_CONTENT in r
Пример #7
0
def test_compress_stdin(httpbin_both):
    env = MockEnvironment(
        stdin=StdinBytesIO(FILE_PATH.read_bytes()),
        stdin_isatty=False,
    )
    r = http(
        '--compress',
        '--compress',
        'PATCH',
        httpbin_both + '/patch',
        env=env,
    )
    assert HTTP_OK in r
    assert r.json['headers']['Content-Encoding'] == 'deflate'
    assert_decompressed_equal(r.json['data'], FILE_CONTENT.strip())
    assert not r.json['json']
Пример #8
0
def test_form_POST_file_redirected_stdin(httpbin):
    """
    <https://github.com/httpie/httpie/issues/840>

    """
    with open(FILE_PATH) as f:
        r = http(
            '--form',
            'POST',
            httpbin + '/post',
            f'file@{FILE_PATH}',
            tolerate_error_exit_status=True,
            env=MockEnvironment(
                stdin=StdinBytesIO(FILE_PATH.read_bytes()),
                stdin_isatty=False,
            ),
        )
    assert r.exit_status == ExitStatus.ERROR
    assert 'cannot be mixed' in r.stderr