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
def test_implicit_POST_stdin(self, httpbin): env = MockEnvironment( stdin_isatty=False, stdin=BytesIO(FILE_PATH.read_bytes()) ) r = http('--form', httpbin.url + '/post', env=env) assert HTTP_OK in r
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
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."
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
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']
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