This commit is contained in:
Jakub Roztocil 2024-03-04 18:12:18 +01:00
parent db16bbee96
commit 3de7c82077
19 changed files with 140 additions and 147 deletions

View File

@ -75,15 +75,8 @@ def _remote_httpbin_available():
@pytest.fixture
def remote_httpbin(_remote_httpbin_available):
if _remote_httpbin_available:
class Server(str):
"""Look like `pytest_httpbin.serve.Server` but only provide URL info."""
@property
def url(self):
return self
return Server('http://' + REMOTE_HTTPBIN_DOMAIN)
return 'http://' + REMOTE_HTTPBIN_DOMAIN
pytest.skip(f'{REMOTE_HTTPBIN_DOMAIN} not resolvable')

View File

@ -42,7 +42,7 @@ def test_bearer_auth(httpbin_both, token):
new=lambda self, prompt: 'password')
def test_password_prompt(httpbin):
r = http('--auth', 'user',
'GET', httpbin.url + '/basic-auth/user/password')
'GET', httpbin + '/basic-auth/user/password')
assert HTTP_OK in r
assert r.json == {'authenticated': True, 'user': 'user'}

View File

@ -15,18 +15,18 @@ class TestBinaryRequestData:
stdin_isatty=False,
stdout_isatty=False
)
r = http('--print=B', 'POST', httpbin.url + '/post', env=env)
r = http('--print=B', 'POST', httpbin + '/post', env=env)
assert r == BIN_FILE_CONTENT
def test_binary_file_path(self, httpbin):
env = MockEnvironment(stdin_isatty=True, stdout_isatty=False)
r = http('--print=B', 'POST', httpbin.url + '/post',
r = http('--print=B', 'POST', httpbin + '/post',
'@' + BIN_FILE_PATH_ARG, env=env)
assert r == BIN_FILE_CONTENT
def test_binary_file_form(self, httpbin):
env = MockEnvironment(stdin_isatty=True, stdout_isatty=False)
r = http('--print=B', '--form', 'POST', httpbin.url + '/post',
r = http('--print=B', '--form', 'POST', httpbin + '/post',
'test@' + BIN_FILE_PATH_ARG, env=env)
assert bytes(BIN_FILE_CONTENT) in bytes(r)

View File

@ -151,17 +151,17 @@ class TestItemParsing:
class TestQuerystring:
def test_query_string_params_in_url(self, httpbin):
r = http('--print=Hhb', 'GET', httpbin.url + '/get?a=1&b=2')
r = http('--print=Hhb', 'GET', httpbin + '/get?a=1&b=2')
path = '/get?a=1&b=2'
url = httpbin.url + path
url = httpbin + path
assert HTTP_OK in r
assert f'GET {path} HTTP/1.1' in r
assert f'"url": "{url}"' in r
def test_query_string_params_items(self, httpbin):
r = http('--print=Hhb', 'GET', httpbin.url + '/get', 'a==1')
r = http('--print=Hhb', 'GET', httpbin + '/get', 'a==1')
path = '/get?a=1'
url = httpbin.url + path
url = httpbin + path
assert HTTP_OK in r
assert f'GET {path} HTTP/1.1' in r
assert f'"url": "{url}"' in r
@ -169,9 +169,9 @@ class TestQuerystring:
def test_query_string_params_in_url_and_items_with_duplicates(self,
httpbin):
r = http('--print=Hhb', 'GET',
httpbin.url + '/get?a=1&a=1', 'a==1', 'a==1')
httpbin + '/get?a=1&a=1', 'a==1', 'a==1')
path = '/get?a=1&a=1&a=1&a=1'
url = httpbin.url + path
url = httpbin + path
assert HTTP_OK in r
assert f'GET {path} HTTP/1.1' in r
assert f'"url": "{url}"' in r
@ -320,11 +320,11 @@ class TestArgumentParser:
class TestNoOptions:
def test_valid_no_options(self, httpbin):
r = http('--verbose', '--no-verbose', 'GET', httpbin.url + '/get')
r = http('--verbose', '--no-verbose', 'GET', httpbin + '/get')
assert 'GET /get HTTP/1.1' not in r
def test_invalid_no_options(self, httpbin):
r = http('--no-war', 'GET', httpbin.url + '/get',
r = http('--no-war', 'GET', httpbin + '/get',
tolerate_error_exit_status=True)
assert r.exit_status == ExitStatus.ERROR
assert 'unrecognized arguments: --no-war' in r.stderr
@ -338,13 +338,13 @@ class TestStdin:
stdin=StdinBytesIO(FILE_PATH.read_bytes()),
stdin_isatty=False,
)
r = http('--ignore-stdin', '--verbose', httpbin.url + '/get', env=env)
r = http('--ignore-stdin', '--verbose', httpbin + '/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_ignore_stdin_cannot_prompt_password(self, httpbin):
r = http('--ignore-stdin', '--auth=no-password', httpbin.url + '/get',
r = http('--ignore-stdin', '--auth=no-password', httpbin + '/get',
tolerate_error_exit_status=True)
assert r.exit_status == ExitStatus.ERROR
assert 'because --ignore-stdin' in r.stderr

View File

@ -29,14 +29,14 @@ def assert_decompressed_equal(base64_compressed_data, expected_str):
def test_cannot_combine_compress_with_chunked(httpbin):
r = http('--compress', '--chunked', httpbin.url + '/get',
r = http('--compress', '--chunked', httpbin + '/get',
tolerate_error_exit_status=True)
assert r.exit_status == ExitStatus.ERROR
assert 'cannot combine --compress and --chunked' in r.stderr
def test_cannot_combine_compress_with_multipart(httpbin):
r = http('--compress', '--multipart', httpbin.url + '/get',
r = http('--compress', '--multipart', httpbin + '/get',
tolerate_error_exit_status=True)
assert r.exit_status == ExitStatus.ERROR
assert 'cannot combine --compress and --multipart' in r.stderr

View File

@ -17,7 +17,7 @@ def test_default_options(httpbin):
env = MockEnvironment()
env.config['default_options'] = ['--form']
env.config.save()
r = http(httpbin.url + '/post', 'foo=bar', env=env)
r = http(httpbin + '/post', 'foo=bar', env=env)
assert r.json['form'] == {
"foo": "bar"
}
@ -51,7 +51,7 @@ def test_default_options_overwrite(httpbin):
env = MockEnvironment()
env.config['default_options'] = ['--form']
env.config.save()
r = http('--json', httpbin.url + '/post', 'foo=bar', env=env)
r = http('--json', httpbin + '/post', 'foo=bar', env=env)
assert r.json['json'] == {
"foo": "bar"
}

View File

@ -12,7 +12,7 @@ def test_explicit_user_set_cookie(httpbin, target_httpbin, request):
r = http(
'--follow',
httpbin + '/redirect-to',
f'url=={target_httpbin.url}/cookies',
f'url=={target_httpbin}/cookies',
'Cookie:a=b'
)
assert r.json == {'cookies': {}}

View File

@ -16,7 +16,7 @@ def test_default_headers_case_insensitive(httpbin):
r = http(
'--debug',
'--print=H',
httpbin.url + '/post',
httpbin + '/post',
'CONTENT-TYPE:application/json-patch+json',
'a=b',
)
@ -27,26 +27,26 @@ def test_default_headers_case_insensitive(httpbin):
# noinspection PyPep8Naming
class TestImplicitHTTPMethod:
def test_implicit_GET(self, httpbin):
r = http(httpbin.url + '/get')
r = http(httpbin + '/get')
assert HTTP_OK in r
def test_implicit_GET_with_headers(self, httpbin):
r = http(httpbin.url + '/headers', 'Foo:bar')
r = http(httpbin + '/headers', 'Foo:bar')
assert HTTP_OK in r
assert r.json['headers']['Foo'] == 'bar'
def test_implicit_POST_json(self, httpbin):
r = http(httpbin.url + '/post', 'hello=world')
r = http(httpbin + '/post', 'hello=world')
assert HTTP_OK in r
assert r.json['json'] == {'hello': 'world'}
def test_implicit_POST_form(self, httpbin):
r = http('--form', httpbin.url + '/post', 'foo=bar')
r = http('--form', httpbin + '/post', 'foo=bar')
assert HTTP_OK in r
assert r.json['form'] == {'foo': 'bar'}
def test_implicit_POST_raw(self, httpbin):
r = http('--raw', 'foo bar', httpbin.url + '/post')
r = http('--raw', 'foo bar', httpbin + '/post')
assert HTTP_OK in r
assert r.json['data'] == 'foo bar'
@ -55,7 +55,7 @@ class TestImplicitHTTPMethod:
stdin_isatty=False,
stdin=BytesIO(FILE_PATH.read_bytes())
)
r = http('--form', httpbin.url + '/post', env=env)
r = http('--form', httpbin + '/post', env=env)
assert HTTP_OK in r
@ -69,33 +69,33 @@ class TestAutoContentTypeAndAcceptHeaders:
def test_GET_no_data_no_auto_headers(self, httpbin):
# https://github.com/httpie/cli/issues/62
r = http('GET', httpbin.url + '/headers')
r = http('GET', httpbin + '/headers')
assert HTTP_OK in r
assert r.json['headers']['Accept'] == '*/*'
assert 'Content-Type' not in r.json['headers']
def test_POST_no_data_no_auto_headers(self, httpbin):
# JSON headers shouldn't be automatically set for POST with no data.
r = http('POST', httpbin.url + '/post')
r = http('POST', httpbin + '/post')
assert HTTP_OK in r
assert '"Accept": "*/*"' in r
assert '"Content-Type": "application/json' not in r
def test_POST_with_data_auto_JSON_headers(self, httpbin):
r = http('POST', httpbin.url + '/post', 'a=b')
r = http('POST', httpbin + '/post', 'a=b')
assert HTTP_OK in r
assert r.json['headers']['Accept'] == JSON_ACCEPT
assert r.json['headers']['Content-Type'] == 'application/json'
def test_GET_with_data_auto_JSON_headers(self, httpbin):
# JSON headers should automatically be set also for GET with data.
r = http('POST', httpbin.url + '/post', 'a=b')
r = http('POST', httpbin + '/post', 'a=b')
assert HTTP_OK in r
assert r.json['headers']['Accept'] == JSON_ACCEPT
assert r.json['headers']['Content-Type'] == 'application/json'
def test_POST_explicit_JSON_JSON_ACCEPT(self, httpbin):
r = http('--json', 'POST', httpbin.url + '/post')
r = http('--json', 'POST', httpbin + '/post')
assert HTTP_OK in r
assert r.json['headers']['Accept'] == JSON_ACCEPT
# Make sure Content-Type gets set even with no data.
@ -103,7 +103,7 @@ class TestAutoContentTypeAndAcceptHeaders:
assert 'application/json' in r.json['headers']['Content-Type']
def test_GET_explicit_JSON_explicit_headers(self, httpbin):
r = http('--json', 'GET', httpbin.url + '/headers',
r = http('--json', 'GET', httpbin + '/headers',
'Accept:application/xml',
'Content-Type:application/xml')
assert HTTP_OK in r
@ -111,22 +111,22 @@ class TestAutoContentTypeAndAcceptHeaders:
assert '"Content-Type": "application/xml"' in r
def test_POST_form_auto_Content_Type(self, httpbin):
r = http('--form', 'POST', httpbin.url + '/post')
r = http('--form', 'POST', httpbin + '/post')
assert HTTP_OK in r
assert '"Content-Type": "application/x-www-form-urlencoded' in r
def test_POST_form_Content_Type_override(self, httpbin):
r = http('--form', 'POST', httpbin.url + '/post',
r = http('--form', 'POST', httpbin + '/post',
'Content-Type:application/xml')
assert HTTP_OK in r
assert '"Content-Type": "application/xml"' in r
def test_print_only_body_when_stdout_redirected_by_default(self, httpbin):
env = MockEnvironment(stdin_isatty=True, stdout_isatty=False)
r = http('GET', httpbin.url + '/get', env=env)
r = http('GET', httpbin + '/get', env=env)
assert 'HTTP/' not in r
def test_print_overridable_when_stdout_redirected(self, httpbin):
env = MockEnvironment(stdin_isatty=True, stdout_isatty=False)
r = http('--print=h', 'GET', httpbin.url + '/get', env=env)
r = http('--print=h', 'GET', httpbin + '/get', env=env)
assert HTTP_OK in r

View File

@ -255,7 +255,7 @@ class TestDownloads:
os.chdir(tmp_dirname)
try:
assert os.listdir('.') == []
http('--download', httpbin.url + '/redirect/1')
http('--download', httpbin + '/redirect/1')
assert os.listdir('.') == [expected_filename]
finally:
os.chdir(orig_cwd)

View File

@ -31,90 +31,90 @@ def test_charset_text_pairs():
def test_unicode_headers(httpbin):
# httpbin doesn't interpret UFT-8 headers
r = http(httpbin.url + '/headers', f'Test:{UNICODE}')
r = http(httpbin + '/headers', f'Test:{UNICODE}')
assert HTTP_OK in r
def test_unicode_headers_verbose(httpbin):
# httpbin doesn't interpret UTF-8 headers
r = http('--verbose', httpbin.url + '/headers', f'Test:{UNICODE}')
r = http('--verbose', httpbin + '/headers', f'Test:{UNICODE}')
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_raw(httpbin):
r = http('--raw', f'test {UNICODE}', 'POST', httpbin.url + '/post')
r = http('--raw', f'test {UNICODE}', 'POST', httpbin + '/post')
assert HTTP_OK in r
assert r.json['data'] == f'test {UNICODE}'
def test_unicode_raw_verbose(httpbin):
r = http('--verbose', '--raw', f'test {UNICODE}',
'POST', httpbin.url + '/post')
'POST', httpbin + '/post')
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_form_item(httpbin):
r = http('--form', 'POST', httpbin.url + '/post', f'test={UNICODE}')
r = http('--form', 'POST', httpbin + '/post', f'test={UNICODE}')
assert HTTP_OK in r
assert r.json['form'] == {'test': UNICODE}
def test_unicode_form_item_verbose(httpbin):
r = http('--verbose', '--form',
'POST', httpbin.url + '/post', f'test={UNICODE}')
'POST', httpbin + '/post', f'test={UNICODE}')
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_json_item(httpbin):
r = http('--json', 'POST', httpbin.url + '/post', f'test={UNICODE}')
r = http('--json', 'POST', httpbin + '/post', f'test={UNICODE}')
assert HTTP_OK in r
assert r.json['json'] == {'test': UNICODE}
def test_unicode_json_item_verbose(httpbin):
r = http('--verbose', '--json',
'POST', httpbin.url + '/post', f'test={UNICODE}')
'POST', httpbin + '/post', f'test={UNICODE}')
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_raw_json_item(httpbin):
r = http('--json', 'POST', httpbin.url + '/post',
r = http('--json', 'POST', httpbin + '/post',
f'test:={{ "{UNICODE}" : [ "{UNICODE}" ] }}')
assert HTTP_OK in r
assert r.json['json'] == {'test': {UNICODE: [UNICODE]}}
def test_unicode_raw_json_item_verbose(httpbin):
r = http('--json', 'POST', httpbin.url + '/post',
r = http('--json', 'POST', httpbin + '/post',
f'test:={{ "{UNICODE}" : [ "{UNICODE}" ] }}')
assert HTTP_OK in r
assert r.json['json'] == {'test': {UNICODE: [UNICODE]}}
def test_unicode_url_query_arg_item(httpbin):
r = http(httpbin.url + '/get', f'test=={UNICODE}')
r = http(httpbin + '/get', f'test=={UNICODE}')
assert HTTP_OK in r
assert r.json['args'] == {'test': UNICODE}, r
def test_unicode_url_query_arg_item_verbose(httpbin):
r = http('--verbose', httpbin.url + '/get', f'test=={UNICODE}')
r = http('--verbose', httpbin + '/get', f'test=={UNICODE}')
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_url(httpbin):
r = http(f'{httpbin.url}/get?test={UNICODE}')
r = http(f'{httpbin}/get?test={UNICODE}')
assert HTTP_OK in r
assert r.json['args'] == {'test': UNICODE}
def test_unicode_url_verbose(httpbin):
r = http('--verbose', f'{httpbin.url}/get?test={UNICODE}')
r = http('--verbose', f'{httpbin}/get?test={UNICODE}')
assert HTTP_OK in r
assert r.json['args'] == {'test': UNICODE}
@ -123,7 +123,7 @@ def test_unicode_basic_auth(httpbin):
# it doesn't really authenticate us because httpbin
# doesn't interpret the UTF-8-encoded auth
http('--verbose', '--auth', f'test:{UNICODE}',
f'{httpbin.url}/basic-auth/test/{UNICODE}')
f'{httpbin}/basic-auth/test/{UNICODE}')
def test_unicode_digest_auth(httpbin):
@ -131,7 +131,7 @@ def test_unicode_digest_auth(httpbin):
# doesn't interpret the UTF-8-encoded auth
http('--auth-type=digest',
'--auth', f'test:{UNICODE}',
f'{httpbin.url}/digest-auth/auth/test/{UNICODE}')
f'{httpbin}/digest-auth/auth/test/{UNICODE}')
@pytest.mark.parametrize('charset, text', CHARSET_TEXT_PAIRS)

View File

@ -7,25 +7,25 @@ from .utils import MockEnvironment, http, HTTP_OK
def test_keyboard_interrupt_during_arg_parsing_exit_status(httpbin):
with mock.patch('httpie.cli.definition.parser.parse_args',
side_effect=KeyboardInterrupt()):
r = http('GET', httpbin.url + '/get', tolerate_error_exit_status=True)
r = http('GET', httpbin + '/get', tolerate_error_exit_status=True)
assert r.exit_status == ExitStatus.ERROR_CTRL_C
def test_keyboard_interrupt_in_program_exit_status(httpbin):
with mock.patch('httpie.core.program',
side_effect=KeyboardInterrupt()):
r = http('GET', httpbin.url + '/get', tolerate_error_exit_status=True)
r = http('GET', httpbin + '/get', tolerate_error_exit_status=True)
assert r.exit_status == ExitStatus.ERROR_CTRL_C
def test_ok_response_exits_0(httpbin):
r = http('GET', httpbin.url + '/get')
r = http('GET', httpbin + '/get')
assert HTTP_OK in r
assert r.exit_status == ExitStatus.SUCCESS
def test_error_response_exits_0_without_check_status(httpbin):
r = http('GET', httpbin.url + '/status/500')
r = http('GET', httpbin + '/status/500')
assert '500 INTERNAL SERVER ERROR' in r
assert r.exit_status == ExitStatus.SUCCESS
assert not r.stderr
@ -33,7 +33,7 @@ def test_error_response_exits_0_without_check_status(httpbin):
def test_timeout_exit_status(httpbin):
r = http('--timeout=0.01', 'GET', httpbin.url + '/delay/0.5',
r = http('--timeout=0.01', 'GET', httpbin + '/delay/0.5',
tolerate_error_exit_status=True)
assert r.exit_status == ExitStatus.ERROR_TIMEOUT
@ -42,7 +42,7 @@ def test_3xx_check_status_exits_3_and_stderr_when_stdout_redirected(
httpbin):
env = MockEnvironment(stdout_isatty=False)
r = http('--check-status', '--headers',
'GET', httpbin.url + '/status/301',
'GET', httpbin + '/status/301',
env=env, tolerate_error_exit_status=True)
assert '301 MOVED PERMANENTLY' in r
assert r.exit_status == ExitStatus.ERROR_HTTP_3XX
@ -51,7 +51,7 @@ def test_3xx_check_status_exits_3_and_stderr_when_stdout_redirected(
def test_3xx_check_status_redirects_allowed_exits_0(httpbin):
r = http('--check-status', '--follow',
'GET', httpbin.url + '/status/301',
'GET', httpbin + '/status/301',
tolerate_error_exit_status=True)
# The redirect will be followed so 200 is expected.
assert HTTP_OK in r
@ -59,7 +59,7 @@ def test_3xx_check_status_redirects_allowed_exits_0(httpbin):
def test_4xx_check_status_exits_4(httpbin):
r = http('--check-status', 'GET', httpbin.url + '/status/401',
r = http('--check-status', 'GET', httpbin + '/status/401',
tolerate_error_exit_status=True)
assert '401 UNAUTHORIZED' in r
assert r.exit_status == ExitStatus.ERROR_HTTP_4XX
@ -68,7 +68,7 @@ def test_4xx_check_status_exits_4(httpbin):
def test_5xx_check_status_exits_5(httpbin):
r = http('--check-status', 'GET', httpbin.url + '/status/500',
r = http('--check-status', 'GET', httpbin + '/status/500',
tolerate_error_exit_status=True)
assert '500 INTERNAL SERVER ERROR' in r
assert r.exit_status == ExitStatus.ERROR_HTTP_5XX

View File

@ -54,7 +54,7 @@ class TestQuietFlag:
stdout_isatty=True,
devnull=io.BytesIO()
)
r = http(*quiet_flags, 'GET', httpbin.url + '/get', env=env)
r = http(*quiet_flags, 'GET', httpbin + '/get', env=env)
assert env.stdout is env.devnull
assert env.stderr is env.devnull
assert HTTP_OK in r.devnull
@ -134,7 +134,7 @@ class TestQuietFlag:
)
r = http(
*quiet_flags, '--auth', 'user', 'GET',
httpbin.url + '/basic-auth/user/password',
httpbin + '/basic-auth/user/password',
env=env
)
assert env.stdout is env.devnull
@ -147,7 +147,7 @@ class TestQuietFlag:
@pytest.mark.parametrize('output_options', ['-h', '-b', '-v', '-p=hH'])
def test_quiet_with_explicit_output_options(self, httpbin, quiet_flags, output_options):
env = MockEnvironment(stdin_isatty=True, stdout_isatty=True)
r = http(*quiet_flags, output_options, httpbin.url + '/get', env=env)
r = http(*quiet_flags, output_options, httpbin + '/get', env=env)
assert env.stdout is env.devnull
assert env.stderr is env.devnull
assert r == ''
@ -188,26 +188,26 @@ class TestQuietFlag:
class TestVerboseFlag:
def test_verbose(self, httpbin):
r = http('--verbose',
'GET', httpbin.url + '/get', 'test-header:__test__')
'GET', httpbin + '/get', 'test-header:__test__')
assert HTTP_OK in r
assert r.count('__test__') == 2
def test_verbose_raw(self, httpbin):
r = http('--verbose', '--raw', 'foo bar',
'POST', httpbin.url + '/post')
'POST', httpbin + '/post')
assert HTTP_OK in r
assert 'foo bar' in r
def test_verbose_form(self, httpbin):
# https://github.com/httpie/cli/issues/53
r = http('--verbose', '--form', 'POST', httpbin.url + '/post',
r = http('--verbose', '--form', 'POST', httpbin + '/post',
'A=B', 'C=D')
assert HTTP_OK in r
assert 'A=B&C=D' in r
def test_verbose_json(self, httpbin):
r = http('--verbose',
'POST', httpbin.url + '/post', 'foo=bar', 'baz=bar')
'POST', httpbin + '/post', 'foo=bar', 'baz=bar')
assert HTTP_OK in r
assert '"baz": "bar"' in r
@ -290,20 +290,20 @@ class TestPrettyOptions:
def test_pretty_enabled_by_default(self, httpbin):
env = MockEnvironment(colors=256)
r = http('GET', httpbin.url + '/get', env=env)
r = http('GET', httpbin + '/get', env=env)
assert COLOR in r
def test_pretty_enabled_by_default_unless_stdout_redirected(self, httpbin):
r = http('GET', httpbin.url + '/get')
r = http('GET', httpbin + '/get')
assert COLOR not in r
def test_force_pretty(self, httpbin):
env = MockEnvironment(stdout_isatty=False, colors=256)
r = http('--pretty=all', 'GET', httpbin.url + '/get', env=env)
r = http('--pretty=all', 'GET', httpbin + '/get', env=env)
assert COLOR in r
def test_force_ugly(self, httpbin):
r = http('--pretty=none', 'GET', httpbin.url + '/get')
r = http('--pretty=none', 'GET', httpbin + '/get')
assert COLOR not in r
def test_subtype_based_pygments_lexer_match(self, httpbin):
@ -312,14 +312,14 @@ class TestPrettyOptions:
"""
env = MockEnvironment(colors=256)
r = http('--print=B', '--pretty=all', httpbin.url + '/post',
r = http('--print=B', '--pretty=all', httpbin + '/post',
'Content-Type:text/foo+json', 'a=b', env=env)
assert COLOR in r
def test_colors_option(self, httpbin):
env = MockEnvironment(colors=256)
r = http('--print=B', '--pretty=colors',
'GET', httpbin.url + '/get', 'a=b',
'GET', httpbin + '/get', 'a=b',
env=env)
# Tests that the JSON data isn't formatted.
assert not r.strip().count('\n')
@ -328,7 +328,7 @@ class TestPrettyOptions:
def test_format_option(self, httpbin):
env = MockEnvironment(colors=256)
r = http('--print=B', '--pretty=format',
'GET', httpbin.url + '/get', 'a=b',
'GET', httpbin + '/get', 'a=b',
env=env)
# Tests that the JSON data is formatted.
assert r.strip().count('\n') == 2
@ -355,25 +355,25 @@ class TestLineEndings:
return body
def test_CRLF_headers_only(self, httpbin):
r = http('--headers', 'GET', httpbin.url + '/get')
r = http('--headers', 'GET', httpbin + '/get')
body = self._validate_crlf(r)
assert not body, f'Garbage after headers: {r!r}'
def test_CRLF_ugly_response(self, httpbin):
r = http('--pretty=none', 'GET', httpbin.url + '/get')
r = http('--pretty=none', 'GET', httpbin + '/get')
self._validate_crlf(r)
def test_CRLF_formatted_response(self, httpbin):
r = http('--pretty=format', 'GET', httpbin.url + '/get')
r = http('--pretty=format', 'GET', httpbin + '/get')
assert r.exit_status == ExitStatus.SUCCESS
self._validate_crlf(r)
def test_CRLF_ugly_request(self, httpbin):
r = http('--pretty=none', '--print=HB', 'GET', httpbin.url + '/get')
r = http('--pretty=none', '--print=HB', 'GET', httpbin + '/get')
self._validate_crlf(r)
def test_CRLF_formatted_request(self, httpbin):
r = http('--pretty=format', '--print=HB', 'GET', httpbin.url + '/get')
r = http('--pretty=format', '--print=HB', 'GET', httpbin + '/get')
self._validate_crlf(r)

View File

@ -13,7 +13,7 @@ REDIRECTS_WITH_METHOD_BODY_PRESERVED = [307, 308]
def test_follow_all_redirects_shown(httpbin):
r = http('--follow', '--all', httpbin.url + '/redirect/2')
r = http('--follow', '--all', httpbin + '/redirect/2')
assert r.count('HTTP/1.1') == 3
assert r.count('HTTP/1.1 302 FOUND', 2)
assert HTTP_OK in r
@ -21,14 +21,14 @@ def test_follow_all_redirects_shown(httpbin):
@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')
r = http(follow_flag, httpbin + '/redirect/2')
assert r.count('HTTP/1.1') == 1
assert HTTP_OK in r
@pytest.mark.xfail(True, reason="https://github.com/httpie/cli/issues/1082")
def test_follow_output_options_used_for_redirects(httpbin):
r = http('--follow', '--print=H', httpbin.url + '/redirect/2')
r = http('--follow', '--print=H', httpbin + '/redirect/2')
assert r.count('GET /') == 1
assert HTTP_OK not in r
@ -38,7 +38,7 @@ def test_follow_all_output_options_used_for_redirects(httpbin):
'--follow',
'--all',
'--print=H',
httpbin.url + '/redirect/2')
httpbin + '/redirect/2')
assert r.count('GET /') == 3
assert HTTP_OK not in r
@ -50,7 +50,7 @@ def test_follow_all_output_options_used_for_redirects(httpbin):
# '--all',
# '--print=h',
# '--history-print=H',
# httpbin.url + '/redirect/2')
# httpbin + '/redirect/2')
# assert r.count('GET /') == 2
# assert 'HTTP/1.1 302 FOUND' not in r
# assert HTTP_OK in r
@ -61,7 +61,7 @@ def test_max_redirects(httpbin):
r = http(
'--max-redirects=1',
'--follow',
httpbin.url + '/redirect/3',
httpbin + '/redirect/3',
tolerate_error_exit_status=True,
)
assert r.exit_status == ExitStatus.ERROR_TOO_MANY_REDIRECTS
@ -72,11 +72,11 @@ def test_max_redirects(httpbin):
def test_follow_redirect_with_repost(httpbin, status_code):
r = http(
'--follow',
httpbin.url + '/redirect-to',
httpbin + '/redirect-to',
'A:A',
'A:B',
'B:B',
f'url=={httpbin.url}/post',
f'url=={httpbin}/post',
f'status_code=={status_code}',
'@' + FILE_PATH_ARG,
)
@ -92,11 +92,11 @@ def test_verbose_follow_redirect_with_repost(httpbin, status_code):
r = http(
'--follow',
'--verbose',
httpbin.url + '/redirect-to',
httpbin + '/redirect-to',
'A:A',
'A:B',
'B:B',
f'url=={httpbin.url}/post',
f'url=={httpbin}/post',
f'status_code=={status_code}',
'@' + FILE_PATH_ARG,
)

View File

@ -12,7 +12,7 @@ def test_Host_header_overwrite(httpbin):
"""
host = 'pie.dev'
url = httpbin.url + '/get'
url = httpbin + '/get'
r = http('--print=hH', url, f'host:{host}')
assert HTTP_OK in r
assert r.lower().count('host:') == 1
@ -35,7 +35,7 @@ def test_verbose_redirected_stdout_separator(httpbin):
"""
r = http(
'-v',
httpbin.url + '/post',
httpbin + '/post',
'a=b',
env=MockEnvironment(stdout_isatty=False),
)

View File

@ -82,7 +82,7 @@ class TestSessionFlow(SessionTestBase):
'--session=test',
'--auth=username:password',
'GET',
httpbin.url + '/cookies/set?hello=world',
httpbin + '/cookies/set?hello=world',
'Hello:World',
env=self.env()
)
@ -92,7 +92,7 @@ class TestSessionFlow(SessionTestBase):
self.start_session(httpbin)
# Verify that the session created in setup_method() has been used.
r2 = http('--session=test',
'GET', httpbin.url + '/get', env=self.env())
'GET', httpbin + '/get', env=self.env())
assert HTTP_OK in r2
assert r2.json['headers']['Hello'] == 'World'
assert r2.json['headers']['Cookie'] == 'hello=world'
@ -101,19 +101,19 @@ class TestSessionFlow(SessionTestBase):
def test_session_update(self, httpbin):
self.start_session(httpbin)
# Get a response to a request from the original session.
r2 = http('--session=test', 'GET', httpbin.url + '/get',
r2 = http('--session=test', 'GET', httpbin + '/get',
env=self.env())
assert HTTP_OK in r2
# Make a request modifying the session data.
r3 = http('--follow', '--session=test', '--auth=username:password2',
'GET', httpbin.url + '/cookies/set?hello=world2',
'GET', httpbin + '/cookies/set?hello=world2',
'Hello:World2',
env=self.env())
assert HTTP_OK in r3
# Get a response to a request from the updated session.
r4 = http('--session=test', 'GET', httpbin.url + '/get',
r4 = http('--session=test', 'GET', httpbin + '/get',
env=self.env())
assert HTTP_OK in r4
assert r4.json['headers']['Hello'] == 'World2'
@ -124,7 +124,7 @@ class TestSessionFlow(SessionTestBase):
def test_session_read_only(self, httpbin):
self.start_session(httpbin)
# Get a response from the original session.
r2 = http('--session=test', 'GET', httpbin.url + '/get',
r2 = http('--session=test', 'GET', httpbin + '/get',
env=self.env())
assert HTTP_OK in r2
@ -132,12 +132,12 @@ class TestSessionFlow(SessionTestBase):
# with --session-read-only.
r3 = http('--follow', '--session-read-only=test',
'--auth=username:password2', 'GET',
httpbin.url + '/cookies/set?hello=world2', 'Hello:World2',
httpbin + '/cookies/set?hello=world2', 'Hello:World2',
env=self.env())
assert HTTP_OK in r3
# Get a response from the updated session.
r4 = http('--session=test', 'GET', httpbin.url + '/get',
r4 = http('--session=test', 'GET', httpbin + '/get',
env=self.env())
assert HTTP_OK in r4
@ -151,17 +151,17 @@ class TestSessionFlow(SessionTestBase):
def test_session_overwrite_header(self, httpbin):
self.start_session(httpbin)
r2 = http('--session=test', 'GET', httpbin.url + '/get',
r2 = http('--session=test', 'GET', httpbin + '/get',
'Hello:World2', env=self.env())
assert HTTP_OK in r2
assert r2.json['headers']['Hello'] == 'World2'
r3 = http('--session=test', 'GET', httpbin.url + '/get',
r3 = http('--session=test', 'GET', httpbin + '/get',
'Hello:World2', 'Hello:World3', env=self.env())
assert HTTP_OK in r3
assert r3.json['headers']['Hello'] == 'World2,World3'
r3 = http('--session=test', 'GET', httpbin.url + '/get',
r3 = http('--session=test', 'GET', httpbin + '/get',
'Hello:', 'Hello:World3', env=self.env())
assert HTTP_OK in r3
assert 'Hello' not in r3.json['headers']['Hello']
@ -172,12 +172,12 @@ class TestSession(SessionTestBase):
def test_session_ignored_header_prefixes(self, httpbin):
self.start_session(httpbin)
r1 = http('--session=test', 'GET', httpbin.url + '/get',
r1 = http('--session=test', 'GET', httpbin + '/get',
'Content-Type: text/plain',
'If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT',
env=self.env())
assert HTTP_OK in r1
r2 = http('--session=test', 'GET', httpbin.url + '/get',
r2 = http('--session=test', 'GET', httpbin + '/get',
env=self.env())
assert HTTP_OK in r2
assert 'Content-Type' not in r2.json['headers']
@ -185,18 +185,18 @@ class TestSession(SessionTestBase):
def test_session_with_upload(self, httpbin):
self.start_session(httpbin)
r = http('--session=test', '--form', '--verbose', 'POST', httpbin.url + '/post',
r = http('--session=test', '--form', '--verbose', 'POST', httpbin + '/post',
f'test-file@{FILE_PATH_ARG}', 'foo=bar', env=self.env())
assert HTTP_OK in r
def test_session_by_path(self, httpbin):
self.start_session(httpbin)
session_path = self.config_dir / 'session-by-path.json'
r1 = http('--session', str(session_path), 'GET', httpbin.url + '/get',
r1 = http('--session', str(session_path), 'GET', httpbin + '/get',
'Foo:Bar', env=self.env())
assert HTTP_OK in r1
r2 = http('--session', str(session_path), 'GET', httpbin.url + '/get',
r2 = http('--session', str(session_path), 'GET', httpbin + '/get',
env=self.env())
assert HTTP_OK in r2
assert r2.json['headers']['Foo'] == 'Bar'
@ -214,7 +214,7 @@ class TestSession(SessionTestBase):
}
session_path = self.config_dir / 'session-data.json'
session_path.write_text(json.dumps(session_data))
r = http('--session', str(session_path), 'GET', httpbin.url + '/get',
r = http('--session', str(session_path), 'GET', httpbin + '/get',
env=self.env())
assert HTTP_OK in r
assert 'Zzz' in r
@ -223,12 +223,12 @@ class TestSession(SessionTestBase):
self.start_session(httpbin)
r1 = http('--session=test', f'--auth=test:{UNICODE}',
'GET', httpbin.url + '/get', f'Test:{UNICODE}',
'GET', httpbin + '/get', f'Test:{UNICODE}',
env=self.env())
assert HTTP_OK in r1
r2 = http('--session=test', '--verbose', 'GET',
httpbin.url + '/get', env=self.env())
httpbin + '/get', env=self.env())
assert HTTP_OK in r2
# FIXME: Authorization *sometimes* is not present
@ -241,12 +241,12 @@ class TestSession(SessionTestBase):
self.start_session(httpbin)
# https://github.com/httpie/cli/issues/180
r1 = http('--session=test',
httpbin.url + '/headers', 'User-Agent:custom',
httpbin + '/headers', 'User-Agent:custom',
env=self.env())
assert HTTP_OK in r1
assert r1.json['headers']['User-Agent'] == 'custom'
r2 = http('--session=test', httpbin.url + '/headers', env=self.env())
r2 = http('--session=test', httpbin + '/headers', env=self.env())
assert HTTP_OK in r2
assert r2.json['headers']['User-Agent'] == 'custom'
@ -257,7 +257,7 @@ class TestSession(SessionTestBase):
os.chdir(tmp_path)
try:
http('--session=test', '--download',
httpbin.url + '/get', env=self.env())
httpbin + '/get', env=self.env())
finally:
os.chdir(cwd)
@ -386,7 +386,7 @@ class TestExpiredCookies(CookieTestBase):
r = http(
'--session', str(self.session_path),
'--print=H',
httpbin.url + '/cookies/delete?cookie2',
httpbin + '/cookies/delete?cookie2',
)
assert 'Cookie: cookie1=foo; cookie2=foo' in r
@ -484,7 +484,7 @@ class TestCookieStorage(CookieTestBase):
r = http(
'--session', str(self.session_path),
'--print=H',
httpbin.url,
httpbin + '/get',
'Cookie:' + specified_cookie_header,
)
parsed_request_headers = { # noqa
@ -537,7 +537,7 @@ class TestCookieStorage(CookieTestBase):
"""
http(
'--session', str(self.session_path),
httpbin.url + set_cookie,
httpbin + set_cookie,
'Cookie:' + cli_cookie,
)
updated_session = json.loads(self.session_path.read_text(encoding=UTF8))

View File

@ -46,7 +46,7 @@ def test_pretty_redirected_stream(httpbin):
stdout_isatty=False,
)
r = http('--verbose', '--pretty=all', '--stream', 'GET',
httpbin.url + '/get', env=env)
httpbin + '/get', env=env)
assert BINARY_SUPPRESSED_NOTICE.decode() in r
@ -57,7 +57,7 @@ def test_pretty_stream_ensure_full_stream_is_retrieved(httpbin):
stdout_isatty=False,
)
r = http('--pretty=format', '--stream', 'GET',
httpbin.url + '/stream/3', env=env)
httpbin + '/stream/3', env=env)
assert r.count('/stream/3') == 3
@ -98,7 +98,7 @@ def test_encoded_stream(httpbin):
stdin_isatty=False,
)
r = http('--pretty=none', '--stream', '--verbose', 'GET',
httpbin.url + '/get', env=env)
httpbin + '/get', env=env)
assert BINARY_SUPPRESSED_NOTICE.decode() in r
@ -111,7 +111,7 @@ def test_redirected_stream(httpbin):
stdin=StdinBytesIO(BIN_FILE_PATH.read_bytes()),
)
r = http('--pretty=none', '--stream', '--verbose', 'GET',
httpbin.url + '/get', env=env)
httpbin + '/get', env=env)
assert BIN_FILE_CONTENT in r

View File

@ -192,10 +192,10 @@ class TestMultipartFormDataFileUpload:
def test_non_existent_file_raises_parse_error(self, httpbin):
with pytest.raises(ParseError):
http('--form',
'POST', httpbin.url + '/post', 'foo@/__does_not_exist__')
'POST', httpbin + '/post', 'foo@/__does_not_exist__')
def test_upload_ok(self, httpbin):
r = http('--form', '--verbose', 'POST', httpbin.url + '/post',
r = http('--form', '--verbose', 'POST', httpbin + '/post',
f'test-file@{FILE_PATH_ARG}', 'foo=bar')
assert HTTP_OK in r
assert 'Content-Disposition: form-data; name="foo"' in r
@ -206,7 +206,7 @@ class TestMultipartFormDataFileUpload:
assert 'Content-Type: text/plain' in r
def test_upload_multiple_fields_with_the_same_name(self, httpbin):
r = http('--form', '--verbose', 'POST', httpbin.url + '/post',
r = http('--form', '--verbose', 'POST', httpbin + '/post',
f'test-file@{FILE_PATH_ARG}',
f'test-file@{FILE_PATH_ARG}')
assert HTTP_OK in r
@ -221,7 +221,7 @@ class TestMultipartFormDataFileUpload:
r = http(
'--form',
'--verbose',
httpbin.url + '/post',
httpbin + '/post',
f'test-file@{FILE_PATH_ARG};type=image/vnd.microsoft.icon'
)
assert HTTP_OK in r
@ -235,7 +235,7 @@ class TestMultipartFormDataFileUpload:
r = http(
'--form',
'--verbose',
httpbin.url + '/post',
httpbin + '/post',
'AAAA=AAA',
'BBB=BBB',
)
@ -246,7 +246,7 @@ class TestMultipartFormDataFileUpload:
r = http(
'--verbose',
'--multipart',
httpbin.url + '/post',
httpbin + '/post',
'AAAA=AAA',
'BBB=BBB',
)
@ -261,7 +261,7 @@ class TestMultipartFormDataFileUpload:
'--check-status',
'--multipart',
f'--boundary={boundary}',
httpbin.url + '/post',
httpbin + '/post',
'AAAA=AAA',
'BBB=BBB',
)
@ -275,7 +275,7 @@ class TestMultipartFormDataFileUpload:
'--check-status',
'--multipart',
f'--boundary={boundary}',
httpbin.url + '/post',
httpbin + '/post',
'Content-Type: multipart/magic',
'AAAA=AAA',
'BBB=BBB',
@ -292,7 +292,7 @@ class TestMultipartFormDataFileUpload:
'--check-status',
'--multipart',
f'--boundary={boundary_in_body}',
httpbin.url + '/post',
httpbin + '/post',
f'Content-Type: multipart/magic; boundary={boundary_in_header}',
'AAAA=AAA',
'BBB=BBB',
@ -342,7 +342,7 @@ class TestRequestBodyFromFilePath:
def test_request_body_from_file_by_path(self, httpbin):
r = http(
'--verbose',
'POST', httpbin.url + '/post',
'POST', httpbin + '/post',
'@' + FILE_PATH_ARG,
)
assert HTTP_OK in r
@ -363,7 +363,7 @@ class TestRequestBodyFromFilePath:
def test_request_body_from_file_by_path_with_explicit_content_type(
self, httpbin):
r = http('--verbose',
'POST', httpbin.url + '/post', '@' + FILE_PATH_ARG,
'POST', httpbin + '/post', '@' + FILE_PATH_ARG,
'Content-Type:text/plain; charset=UTF-8')
assert HTTP_OK in r
assert FILE_CONTENT in r
@ -372,7 +372,7 @@ class TestRequestBodyFromFilePath:
def test_request_body_from_file_by_path_no_field_name_allowed(
self, httpbin):
env = MockEnvironment(stdin_isatty=True)
r = http('POST', httpbin.url + '/post', 'field-name@' + FILE_PATH_ARG,
r = http('POST', httpbin + '/post', 'field-name@' + FILE_PATH_ARG,
env=env, tolerate_error_exit_status=True)
assert 'perhaps you meant --form?' in r.stderr
@ -381,7 +381,7 @@ class TestRequestBodyFromFilePath:
env = MockEnvironment(stdin_isatty=False)
r = http(
'POST',
httpbin.url + '/post',
httpbin + '/post',
'@' + FILE_PATH_ARG, 'foo=bar',
env=env,
tolerate_error_exit_status=True,
@ -393,7 +393,7 @@ class TestRequestBodyFromFilePath:
env = MockEnvironment(stdin_isatty=True)
r = http(
'--verbose',
'POST', httpbin.url + '/post',
'POST', httpbin + '/post',
'@' + FILE_PATH_ARG,
'@' + FILE_PATH_ARG,
env=env,

View File

@ -12,7 +12,7 @@ class TestWindowsOnly:
reason='this test for some reason kills the process')
def test_windows_colorized_output(self, httpbin):
# Spits out the colorized output.
http(httpbin.url + '/get', env=Environment())
http(httpbin + '/get', env=Environment())
class TestFakeWindows:
@ -20,6 +20,6 @@ class TestFakeWindows:
env = MockEnvironment(is_windows=True)
output_file = tmp_path / 'test_output_file_pretty_not_allowed_on_windows'
r = http('--output', str(output_file),
'--pretty=all', 'GET', httpbin.url + '/get',
'--pretty=all', 'GET', httpbin + '/get',
env=env, tolerate_error_exit_status=True)
assert 'Only terminal output can be colorized on Windows' in r.stderr

View File

@ -360,7 +360,7 @@ def http(
$ http --auth=user:password GET pie.dev/basic-auth/user/password
>>> httpbin = getfixture('httpbin')
>>> r = http('-a', 'user:pw', httpbin.url + '/basic-auth/user/pw')
>>> r = http('-a', 'user:pw', httpbin + '/basic-auth/user/pw')
>>> type(r) == StrCLIResponse
True
>>> r.exit_status is ExitStatus.SUCCESS