mirror of
https://github.com/httpie/cli.git
synced 2025-01-08 14:49:41 +01:00
Cleanup tests
This commit is contained in:
parent
529981af7a
commit
4e574e6b8e
@ -1,5 +1,5 @@
|
|||||||
"""HTTP authentication-related tests."""
|
"""HTTP authentication-related tests."""
|
||||||
import requests
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from utils import http, add_auth, HTTP_OK, TestEnvironment
|
from utils import http, add_auth, HTTP_OK, TestEnvironment
|
||||||
@ -7,56 +7,58 @@ import httpie.input
|
|||||||
import httpie.cli
|
import httpie.cli
|
||||||
|
|
||||||
|
|
||||||
class TestAuth:
|
def test_basic_auth(httpbin):
|
||||||
def test_basic_auth(self, httpbin):
|
r = http('--auth=user:password',
|
||||||
r = http('--auth=user:password',
|
'GET', httpbin.url + '/basic-auth/user/password')
|
||||||
'GET', httpbin.url + '/basic-auth/user/password')
|
assert HTTP_OK in r
|
||||||
assert HTTP_OK in r
|
assert r.json == {'authenticated': True, 'user': 'user'}
|
||||||
assert r.json == {'authenticated': True, 'user': 'user'}
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('argument_name', ['--auth-type', '-A'])
|
|
||||||
@pytest.mark.skipif(
|
|
||||||
requests.__version__ == '0.13.6',
|
|
||||||
reason='Redirects with prefetch=False are broken in Requests 0.13.6')
|
|
||||||
def test_digest_auth(self, httpbin, argument_name):
|
|
||||||
r = http(argument_name + '=digest', '--auth=user:password',
|
|
||||||
'GET', httpbin.url + '/digest-auth/auth/user/password')
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.json == {'authenticated': True, 'user': 'user'}
|
|
||||||
|
|
||||||
def test_password_prompt(self, httpbin):
|
@pytest.mark.parametrize('argument_name', ['--auth-type', '-A'])
|
||||||
httpie.input.AuthCredentials._getpass = lambda self, prompt: 'password'
|
def test_digest_auth(httpbin, argument_name):
|
||||||
r = http('--auth', 'user',
|
r = http(argument_name + '=digest', '--auth=user:password',
|
||||||
'GET', httpbin.url + '/basic-auth/user/password')
|
'GET', httpbin.url + '/digest-auth/auth/user/password')
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert r.json == {'authenticated': True, 'user': 'user'}
|
assert r.json == {'authenticated': True, 'user': 'user'}
|
||||||
|
|
||||||
def test_credentials_in_url(self, httpbin):
|
|
||||||
url = add_auth(httpbin.url + '/basic-auth/user/password',
|
|
||||||
auth='user:password')
|
|
||||||
r = http('GET', url)
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.json == {'authenticated': True, 'user': 'user'}
|
|
||||||
|
|
||||||
def test_credentials_in_url_auth_flag_has_priority(self, httpbin):
|
@mock.patch('httpie.input.AuthCredentials._getpass',
|
||||||
"""When credentials are passed in URL and via -a at the same time,
|
new=lambda self, prompt: 'password')
|
||||||
then the ones from -a are used."""
|
def test_password_prompt(httpbin):
|
||||||
url = add_auth(httpbin.url + '/basic-auth/user/password',
|
r = http('--auth', 'user',
|
||||||
auth='user:wrong')
|
'GET', httpbin.url + '/basic-auth/user/password')
|
||||||
r = http('--auth=user:password', 'GET', url)
|
assert HTTP_OK in r
|
||||||
assert HTTP_OK in r
|
assert r.json == {'authenticated': True, 'user': 'user'}
|
||||||
assert r.json == {'authenticated': True, 'user': 'user'}
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('url', [
|
|
||||||
'username@example.org',
|
|
||||||
'username:@example.org',
|
|
||||||
])
|
|
||||||
def test_only_username_in_url(self, url):
|
|
||||||
"""
|
|
||||||
https://github.com/jkbrzt/httpie/issues/242
|
|
||||||
|
|
||||||
"""
|
def test_credentials_in_url(httpbin):
|
||||||
args = httpie.cli.parser.parse_args(args=[url], env=TestEnvironment())
|
url = add_auth(httpbin.url + '/basic-auth/user/password',
|
||||||
assert args.auth
|
auth='user:password')
|
||||||
assert args.auth.key == 'username'
|
r = http('GET', url)
|
||||||
assert args.auth.value == ''
|
assert HTTP_OK in r
|
||||||
|
assert r.json == {'authenticated': True, 'user': 'user'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_credentials_in_url_auth_flag_has_priority(httpbin):
|
||||||
|
"""When credentials are passed in URL and via -a at the same time,
|
||||||
|
then the ones from -a are used."""
|
||||||
|
url = add_auth(httpbin.url + '/basic-auth/user/password',
|
||||||
|
auth='user:wrong')
|
||||||
|
r = http('--auth=user:password', 'GET', url)
|
||||||
|
assert HTTP_OK in r
|
||||||
|
assert r.json == {'authenticated': True, 'user': 'user'}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('url', [
|
||||||
|
'username@example.org',
|
||||||
|
'username:@example.org',
|
||||||
|
])
|
||||||
|
def test_only_username_in_url(url):
|
||||||
|
"""
|
||||||
|
https://github.com/jkbrzt/httpie/issues/242
|
||||||
|
|
||||||
|
"""
|
||||||
|
args = httpie.cli.parser.parse_args(args=[url], env=TestEnvironment())
|
||||||
|
assert args.auth
|
||||||
|
assert args.auth.key == 'username'
|
||||||
|
assert args.auth.value == ''
|
||||||
|
@ -154,7 +154,7 @@ class TestQuerystring:
|
|||||||
assert '"url": "%s"' % url in r
|
assert '"url": "%s"' % url in r
|
||||||
|
|
||||||
|
|
||||||
class TestURLshorthand:
|
class TestLocalhostShorthand:
|
||||||
def test_expand_localhost_shorthand(self):
|
def test_expand_localhost_shorthand(self):
|
||||||
args = parser.parse_args(args=[':'], env=TestEnvironment())
|
args = parser.parse_args(args=[':'], env=TestEnvironment())
|
||||||
assert args.url == 'http://localhost'
|
assert args.url == 'http://localhost'
|
||||||
|
@ -1,63 +1,58 @@
|
|||||||
import requests
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from httpie import ExitStatus
|
from httpie import ExitStatus
|
||||||
from utils import TestEnvironment, http, HTTP_OK
|
from utils import TestEnvironment, http, HTTP_OK
|
||||||
|
|
||||||
|
|
||||||
class TestExitStatus:
|
def test_ok_response_exits_0(httpbin):
|
||||||
def test_ok_response_exits_0(self, httpbin):
|
r = http('GET', httpbin.url + '/status/200')
|
||||||
r = http('GET', httpbin.url + '/status/200')
|
assert HTTP_OK in r
|
||||||
assert HTTP_OK in r
|
assert r.exit_status == ExitStatus.OK
|
||||||
assert r.exit_status == ExitStatus.OK
|
|
||||||
|
|
||||||
def test_error_response_exits_0_without_check_status(self, httpbin):
|
|
||||||
r = http('GET', httpbin.url + '/status/500')
|
|
||||||
assert '500 INTERNAL SERVER ERRO' in r
|
|
||||||
assert r.exit_status == ExitStatus.OK
|
|
||||||
assert not r.stderr
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
def test_error_response_exits_0_without_check_status(httpbin):
|
||||||
tuple(map(int, requests.__version__.split('.'))) < (2, 3, 0),
|
r = http('GET', httpbin.url + '/status/500')
|
||||||
reason='timeout broken in requests prior v2.3.0 (#185)'
|
assert '500 INTERNAL SERVER ERRO' in r
|
||||||
)
|
assert r.exit_status == ExitStatus.OK
|
||||||
def test_timeout_exit_status(self, httpbin):
|
assert not r.stderr
|
||||||
|
|
||||||
r = http('--timeout=0.01', 'GET', httpbin.url + '/delay/0.02',
|
|
||||||
error_exit_ok=True)
|
|
||||||
assert r.exit_status == ExitStatus.ERROR_TIMEOUT
|
|
||||||
|
|
||||||
def test_3xx_check_status_exits_3_and_stderr_when_stdout_redirected(
|
def test_timeout_exit_status(httpbin):
|
||||||
self, httpbin):
|
|
||||||
env = TestEnvironment(stdout_isatty=False)
|
|
||||||
r = http('--check-status', '--headers',
|
|
||||||
'GET', httpbin.url + '/status/301',
|
|
||||||
env=env, error_exit_ok=True)
|
|
||||||
assert '301 MOVED PERMANENTLY' in r
|
|
||||||
assert r.exit_status == ExitStatus.ERROR_HTTP_3XX
|
|
||||||
assert '301 moved permanently' in r.stderr.lower()
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
r = http('--timeout=0.01', 'GET', httpbin.url + '/delay/0.02',
|
||||||
requests.__version__ == '0.13.6',
|
error_exit_ok=True)
|
||||||
reason='Redirects with prefetch=False are broken in Requests 0.13.6')
|
assert r.exit_status == ExitStatus.ERROR_TIMEOUT
|
||||||
def test_3xx_check_status_redirects_allowed_exits_0(self, httpbin):
|
|
||||||
r = http('--check-status', '--follow',
|
|
||||||
'GET', httpbin.url + '/status/301',
|
|
||||||
error_exit_ok=True)
|
|
||||||
# The redirect will be followed so 200 is expected.
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.exit_status == ExitStatus.OK
|
|
||||||
|
|
||||||
def test_4xx_check_status_exits_4(self, httpbin):
|
|
||||||
r = http('--check-status', 'GET', httpbin.url + '/status/401',
|
|
||||||
error_exit_ok=True)
|
|
||||||
assert '401 UNAUTHORIZED' in r
|
|
||||||
assert r.exit_status == ExitStatus.ERROR_HTTP_4XX
|
|
||||||
# Also stderr should be empty since stdout isn't redirected.
|
|
||||||
assert not r.stderr
|
|
||||||
|
|
||||||
def test_5xx_check_status_exits_5(self, httpbin):
|
def test_3xx_check_status_exits_3_and_stderr_when_stdout_redirected(
|
||||||
r = http('--check-status', 'GET', httpbin.url + '/status/500',
|
httpbin):
|
||||||
error_exit_ok=True)
|
env = TestEnvironment(stdout_isatty=False)
|
||||||
assert '500 INTERNAL SERVER ERROR' in r
|
r = http('--check-status', '--headers',
|
||||||
assert r.exit_status == ExitStatus.ERROR_HTTP_5XX
|
'GET', httpbin.url + '/status/301',
|
||||||
|
env=env, error_exit_ok=True)
|
||||||
|
assert '301 MOVED PERMANENTLY' in r
|
||||||
|
assert r.exit_status == ExitStatus.ERROR_HTTP_3XX
|
||||||
|
assert '301 moved permanently' in r.stderr.lower()
|
||||||
|
|
||||||
|
|
||||||
|
def test_3xx_check_status_redirects_allowed_exits_0(httpbin):
|
||||||
|
r = http('--check-status', '--follow',
|
||||||
|
'GET', httpbin.url + '/status/301',
|
||||||
|
error_exit_ok=True)
|
||||||
|
# The redirect will be followed so 200 is expected.
|
||||||
|
assert HTTP_OK in r
|
||||||
|
assert r.exit_status == ExitStatus.OK
|
||||||
|
|
||||||
|
|
||||||
|
def test_4xx_check_status_exits_4(httpbin):
|
||||||
|
r = http('--check-status', 'GET', httpbin.url + '/status/401',
|
||||||
|
error_exit_ok=True)
|
||||||
|
assert '401 UNAUTHORIZED' in r
|
||||||
|
assert r.exit_status == ExitStatus.ERROR_HTTP_4XX
|
||||||
|
# Also stderr should be empty since stdout isn't redirected.
|
||||||
|
assert not r.stderr
|
||||||
|
|
||||||
|
|
||||||
|
def test_5xx_check_status_exits_5(httpbin):
|
||||||
|
r = http('--check-status', 'GET', httpbin.url + '/status/500',
|
||||||
|
error_exit_ok=True)
|
||||||
|
assert '500 INTERNAL SERVER ERROR' in r
|
||||||
|
assert r.exit_status == ExitStatus.ERROR_HTTP_5XX
|
||||||
|
@ -7,73 +7,82 @@ import httpie
|
|||||||
from httpie.compat import is_py26
|
from httpie.compat import is_py26
|
||||||
|
|
||||||
|
|
||||||
class TestHTTPie:
|
def test_debug():
|
||||||
|
r = http('--debug')
|
||||||
|
assert r.exit_status == httpie.ExitStatus.OK
|
||||||
|
assert 'HTTPie %s' % httpie.__version__ in r.stderr
|
||||||
|
assert 'HTTPie data:' in r.stderr
|
||||||
|
|
||||||
def test_debug(self):
|
|
||||||
r = http('--debug')
|
|
||||||
assert r.exit_status == httpie.ExitStatus.OK
|
|
||||||
assert 'HTTPie %s' % httpie.__version__ in r.stderr
|
|
||||||
assert 'HTTPie data:' in r.stderr
|
|
||||||
|
|
||||||
def test_help(self):
|
def test_help():
|
||||||
r = http('--help', error_exit_ok=True)
|
r = http('--help', error_exit_ok=True)
|
||||||
assert r.exit_status == httpie.ExitStatus.OK
|
assert r.exit_status == httpie.ExitStatus.OK
|
||||||
assert 'https://github.com/jkbrzt/httpie/issues' in r
|
assert 'https://github.com/jkbrzt/httpie/issues' in r
|
||||||
|
|
||||||
def test_version(self):
|
|
||||||
r = http('--version', error_exit_ok=True)
|
|
||||||
assert r.exit_status == httpie.ExitStatus.OK
|
|
||||||
# FIXME: py3 has version in stdout, py2 in stderr
|
|
||||||
assert httpie.__version__ == r.stderr.strip() + r.strip()
|
|
||||||
|
|
||||||
def test_GET(self, httpbin):
|
def test_version():
|
||||||
r = http('GET', httpbin.url + '/get')
|
r = http('--version', error_exit_ok=True)
|
||||||
assert HTTP_OK in r
|
assert r.exit_status == httpie.ExitStatus.OK
|
||||||
|
# FIXME: py3 has version in stdout, py2 in stderr
|
||||||
|
assert httpie.__version__ == r.stderr.strip() + r.strip()
|
||||||
|
|
||||||
def test_DELETE(self, httpbin):
|
|
||||||
r = http('DELETE', httpbin.url + '/delete')
|
|
||||||
assert HTTP_OK in r
|
|
||||||
|
|
||||||
def test_PUT(self, httpbin):
|
def test_GET(httpbin):
|
||||||
r = http('PUT', httpbin.url + '/put', 'foo=bar')
|
r = http('GET', httpbin.url + '/get')
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert r.json['json']['foo'] == 'bar'
|
|
||||||
|
|
||||||
def test_POST_JSON_data(self, httpbin):
|
|
||||||
r = http('POST', httpbin.url + '/post', 'foo=bar')
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.json['json']['foo'] == 'bar'
|
|
||||||
|
|
||||||
def test_POST_form(self, httpbin):
|
def test_DELETE(httpbin):
|
||||||
r = http('--form', 'POST', httpbin.url + '/post', 'foo=bar')
|
r = http('DELETE', httpbin.url + '/delete')
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert '"foo": "bar"' in r
|
|
||||||
|
|
||||||
def test_POST_form_multiple_values(self, httpbin):
|
|
||||||
r = http('--form', 'POST', httpbin.url + '/post', 'foo=bar', 'foo=baz')
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.json['form'] == {'foo': ['bar', 'baz']}
|
|
||||||
|
|
||||||
def test_POST_stdin(self, httpbin):
|
def test_PUT(httpbin):
|
||||||
with open(FILE_PATH) as f:
|
r = http('PUT', httpbin.url + '/put', 'foo=bar')
|
||||||
env = TestEnvironment(stdin=f, stdin_isatty=False)
|
assert HTTP_OK in r
|
||||||
r = http('--form', 'POST', httpbin.url + '/post', env=env)
|
assert r.json['json']['foo'] == 'bar'
|
||||||
assert HTTP_OK in r
|
|
||||||
assert FILE_CONTENT in r
|
|
||||||
|
|
||||||
def test_headers(self, httpbin):
|
|
||||||
r = http('GET', httpbin.url + '/headers', 'Foo:bar')
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert '"User-Agent": "HTTPie' in r, r
|
|
||||||
assert '"Foo": "bar"' in r
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
def test_POST_JSON_data(httpbin):
|
||||||
is_py26,
|
r = http('POST', httpbin.url + '/post', 'foo=bar')
|
||||||
reason='the `object_pairs_hook` arg for `json.loads()` is Py>2.6 only'
|
assert HTTP_OK in r
|
||||||
)
|
assert r.json['json']['foo'] == 'bar'
|
||||||
def test_json_input_preserve_order(self, httpbin):
|
|
||||||
r = http('PATCH', httpbin.url + '/patch',
|
|
||||||
'order:={"map":{"1":"first","2":"second"}}')
|
def test_POST_form(httpbin):
|
||||||
assert HTTP_OK in r
|
r = http('--form', 'POST', httpbin.url + '/post', 'foo=bar')
|
||||||
assert r.json['data'] == \
|
assert HTTP_OK in r
|
||||||
'{"order": {"map": {"1": "first", "2": "second"}}}'
|
assert '"foo": "bar"' in r
|
||||||
|
|
||||||
|
|
||||||
|
def test_POST_form_multiple_values(httpbin):
|
||||||
|
r = http('--form', 'POST', httpbin.url + '/post', 'foo=bar', 'foo=baz')
|
||||||
|
assert HTTP_OK in r
|
||||||
|
assert r.json['form'] == {'foo': ['bar', 'baz']}
|
||||||
|
|
||||||
|
|
||||||
|
def test_POST_stdin(httpbin):
|
||||||
|
with open(FILE_PATH) as f:
|
||||||
|
env = TestEnvironment(stdin=f, stdin_isatty=False)
|
||||||
|
r = http('--form', 'POST', httpbin.url + '/post', env=env)
|
||||||
|
assert HTTP_OK in r
|
||||||
|
assert FILE_CONTENT in r
|
||||||
|
|
||||||
|
|
||||||
|
def test_headers(httpbin):
|
||||||
|
r = http('GET', httpbin.url + '/headers', 'Foo:bar')
|
||||||
|
assert HTTP_OK in r
|
||||||
|
assert '"User-Agent": "HTTPie' in r, r
|
||||||
|
assert '"Foo": "bar"' in r
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
is_py26,
|
||||||
|
reason='the `object_pairs_hook` arg for `json.loads()` is Py>2.6 only'
|
||||||
|
)
|
||||||
|
def test_json_input_preserve_order(httpbin):
|
||||||
|
r = http('PATCH', httpbin.url + '/patch',
|
||||||
|
'order:={"map":{"1":"first","2":"second"}}')
|
||||||
|
assert HTTP_OK in r
|
||||||
|
assert r.json['data'] == \
|
||||||
|
'{"order": {"map": {"1": "first", "2": "second"}}}'
|
||||||
|
@ -9,7 +9,7 @@ from httpie.compat import urlopen
|
|||||||
from httpie.output.formatters.colors import get_lexer
|
from httpie.output.formatters.colors import get_lexer
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('stdout_isatty', [(True,), (False,)])
|
@pytest.mark.parametrize('stdout_isatty', [True, False])
|
||||||
def test_output_option(httpbin, stdout_isatty):
|
def test_output_option(httpbin, stdout_isatty):
|
||||||
output_filename = os.path.join(gettempdir(), test_output_option.__name__)
|
output_filename = os.path.join(gettempdir(), test_output_option.__name__)
|
||||||
url = httpbin + '/robots.txt'
|
url = httpbin + '/robots.txt'
|
||||||
|
@ -6,37 +6,39 @@ from utils import http, TestEnvironment
|
|||||||
from fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH
|
from fixtures import BIN_FILE_CONTENT, BIN_FILE_PATH
|
||||||
|
|
||||||
|
|
||||||
class TestStream:
|
# GET because httpbin 500s with binary POST body.
|
||||||
# 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(self, httpbin):
|
|
||||||
"""Test that --stream works with prettified redirected output."""
|
|
||||||
with open(BIN_FILE_PATH, 'rb') as f:
|
|
||||||
env = TestEnvironment(colors=256, stdin=f,
|
|
||||||
stdin_isatty=False,
|
|
||||||
stdout_isatty=False)
|
|
||||||
r = http('--verbose', '--pretty=all', '--stream', 'GET',
|
|
||||||
httpbin.url + '/get', env=env)
|
|
||||||
assert BINARY_SUPPRESSED_NOTICE.decode() in r
|
|
||||||
|
|
||||||
def test_encoded_stream(self, httpbin):
|
@pytest.mark.skipif(is_windows,
|
||||||
"""Test that --stream works with non-prettified
|
reason='Pretty redirect not supported under Windows')
|
||||||
redirected terminal output."""
|
def test_pretty_redirected_stream(httpbin):
|
||||||
with open(BIN_FILE_PATH, 'rb') as f:
|
"""Test that --stream works with prettified redirected output."""
|
||||||
env = TestEnvironment(stdin=f, stdin_isatty=False)
|
with open(BIN_FILE_PATH, 'rb') as f:
|
||||||
r = http('--pretty=none', '--stream', '--verbose', 'GET',
|
env = TestEnvironment(colors=256, stdin=f,
|
||||||
httpbin.url + '/get', env=env)
|
stdin_isatty=False,
|
||||||
assert BINARY_SUPPRESSED_NOTICE.decode() in r
|
stdout_isatty=False)
|
||||||
|
r = http('--verbose', '--pretty=all', '--stream', 'GET',
|
||||||
|
httpbin.url + '/get', env=env)
|
||||||
|
assert BINARY_SUPPRESSED_NOTICE.decode() in r
|
||||||
|
|
||||||
def test_redirected_stream(self, httpbin):
|
|
||||||
"""Test that --stream works with non-prettified
|
def test_encoded_stream(httpbin):
|
||||||
redirected terminal output."""
|
"""Test that --stream works with non-prettified
|
||||||
with open(BIN_FILE_PATH, 'rb') as f:
|
redirected terminal output."""
|
||||||
env = TestEnvironment(stdout_isatty=False,
|
with open(BIN_FILE_PATH, 'rb') as f:
|
||||||
stdin_isatty=False,
|
env = TestEnvironment(stdin=f, stdin_isatty=False)
|
||||||
stdin=f)
|
r = http('--pretty=none', '--stream', '--verbose', 'GET',
|
||||||
r = http('--pretty=none', '--stream', '--verbose', 'GET',
|
httpbin.url + '/get', env=env)
|
||||||
httpbin.url + '/get', env=env)
|
assert BINARY_SUPPRESSED_NOTICE.decode() in r
|
||||||
assert BIN_FILE_CONTENT in r
|
|
||||||
|
|
||||||
|
def test_redirected_stream(httpbin):
|
||||||
|
"""Test that --stream works with non-prettified
|
||||||
|
redirected terminal output."""
|
||||||
|
with open(BIN_FILE_PATH, 'rb') as f:
|
||||||
|
env = TestEnvironment(stdout_isatty=False,
|
||||||
|
stdin_isatty=False,
|
||||||
|
stdin=f)
|
||||||
|
r = http('--pretty=none', '--stream', '--verbose', 'GET',
|
||||||
|
httpbin.url + '/get', env=env)
|
||||||
|
assert BIN_FILE_CONTENT in r
|
||||||
|
@ -7,81 +7,91 @@ from utils import http, HTTP_OK
|
|||||||
from fixtures import UNICODE
|
from fixtures import UNICODE
|
||||||
|
|
||||||
|
|
||||||
class TestUnicode:
|
def test_unicode_headers(httpbin):
|
||||||
|
# httpbin doesn't interpret utf8 headers
|
||||||
|
r = http(httpbin.url + '/headers', u'Test:%s' % UNICODE)
|
||||||
|
assert HTTP_OK in r
|
||||||
|
|
||||||
def test_unicode_headers(self, httpbin):
|
|
||||||
# httpbin doesn't interpret utf8 headers
|
|
||||||
r = http(httpbin.url + '/headers', u'Test:%s' % UNICODE)
|
|
||||||
assert HTTP_OK in r
|
|
||||||
|
|
||||||
def test_unicode_headers_verbose(self, httpbin):
|
def test_unicode_headers_verbose(httpbin):
|
||||||
# httpbin doesn't interpret utf8 headers
|
# httpbin doesn't interpret utf8 headers
|
||||||
r = http('--verbose', httpbin.url + '/headers', u'Test:%s' % UNICODE)
|
r = http('--verbose', httpbin.url + '/headers', u'Test:%s' % UNICODE)
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert UNICODE in r
|
assert UNICODE in r
|
||||||
|
|
||||||
def test_unicode_form_item(self, httpbin):
|
|
||||||
r = http('--form', 'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.json['form'] == {'test': UNICODE}
|
|
||||||
|
|
||||||
def test_unicode_form_item_verbose(self, httpbin):
|
def test_unicode_form_item(httpbin):
|
||||||
r = http('--verbose', '--form',
|
r = http('--form', 'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
||||||
'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
assert HTTP_OK in r
|
||||||
assert HTTP_OK in r
|
assert r.json['form'] == {'test': UNICODE}
|
||||||
assert UNICODE in r
|
|
||||||
|
|
||||||
def test_unicode_json_item(self, httpbin):
|
|
||||||
r = http('--json', 'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.json['json'] == {'test': UNICODE}
|
|
||||||
|
|
||||||
def test_unicode_json_item_verbose(self, httpbin):
|
def test_unicode_form_item_verbose(httpbin):
|
||||||
r = http('--verbose', '--json',
|
r = http('--verbose', '--form',
|
||||||
'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert UNICODE in r
|
assert UNICODE in r
|
||||||
|
|
||||||
def test_unicode_raw_json_item(self, httpbin):
|
|
||||||
r = http('--json', 'POST', httpbin.url + '/post',
|
|
||||||
u'test:={ "%s" : [ "%s" ] }' % (UNICODE, UNICODE))
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.json['json'] == {'test': {UNICODE: [UNICODE]}}
|
|
||||||
|
|
||||||
def test_unicode_raw_json_item_verbose(self, httpbin):
|
def test_unicode_json_item(httpbin):
|
||||||
r = http('--json', 'POST', httpbin.url + '/post',
|
r = http('--json', 'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
||||||
u'test:={ "%s" : [ "%s" ] }' % (UNICODE, UNICODE))
|
assert HTTP_OK in r
|
||||||
assert HTTP_OK in r
|
assert r.json['json'] == {'test': UNICODE}
|
||||||
assert r.json['json'] == {'test': {UNICODE: [UNICODE]}}
|
|
||||||
|
|
||||||
def test_unicode_url_query_arg_item(self, httpbin):
|
|
||||||
r = http(httpbin.url + '/get', u'test==%s' % UNICODE)
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.json['args'] == {'test': UNICODE}, r
|
|
||||||
|
|
||||||
def test_unicode_url_query_arg_item_verbose(self, httpbin):
|
def test_unicode_json_item_verbose(httpbin):
|
||||||
r = http('--verbose', httpbin.url + '/get', u'test==%s' % UNICODE)
|
r = http('--verbose', '--json',
|
||||||
assert HTTP_OK in r
|
'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
|
||||||
assert UNICODE in r
|
assert HTTP_OK in r
|
||||||
|
assert UNICODE in r
|
||||||
|
|
||||||
def test_unicode_url(self, httpbin):
|
|
||||||
r = http(httpbin.url + u'/get?test=' + UNICODE)
|
|
||||||
assert HTTP_OK in r
|
|
||||||
assert r.json['args'] == {'test': UNICODE}
|
|
||||||
|
|
||||||
# def test_unicode_url_verbose(self):
|
def test_unicode_raw_json_item(httpbin):
|
||||||
# r = http(httpbin.url + '--verbose', u'/get?test=' + UNICODE)
|
r = http('--json', 'POST', httpbin.url + '/post',
|
||||||
# assert HTTP_OK in r
|
u'test:={ "%s" : [ "%s" ] }' % (UNICODE, UNICODE))
|
||||||
|
assert HTTP_OK in r
|
||||||
|
assert r.json['json'] == {'test': {UNICODE: [UNICODE]}}
|
||||||
|
|
||||||
def test_unicode_basic_auth(self, httpbin):
|
|
||||||
# it doesn't really authenticate us because httpbin
|
|
||||||
# doesn't interpret the utf8-encoded auth
|
|
||||||
http('--verbose', '--auth', u'test:%s' % UNICODE,
|
|
||||||
httpbin.url + u'/basic-auth/test/' + UNICODE)
|
|
||||||
|
|
||||||
def test_unicode_digest_auth(self, httpbin):
|
def test_unicode_raw_json_item_verbose(httpbin):
|
||||||
# it doesn't really authenticate us because httpbin
|
r = http('--json', 'POST', httpbin.url + '/post',
|
||||||
# doesn't interpret the utf8-encoded auth
|
u'test:={ "%s" : [ "%s" ] }' % (UNICODE, UNICODE))
|
||||||
http('--auth-type=digest',
|
assert HTTP_OK in r
|
||||||
'--auth', u'test:%s' % UNICODE,
|
assert r.json['json'] == {'test': {UNICODE: [UNICODE]}}
|
||||||
httpbin.url + u'/digest-auth/auth/test/' + UNICODE)
|
|
||||||
|
|
||||||
|
def test_unicode_url_query_arg_item(httpbin):
|
||||||
|
r = http(httpbin.url + '/get', u'test==%s' % 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', u'test==%s' % UNICODE)
|
||||||
|
assert HTTP_OK in r
|
||||||
|
assert UNICODE in r
|
||||||
|
|
||||||
|
|
||||||
|
def test_unicode_url(httpbin):
|
||||||
|
r = http(httpbin.url + u'/get?test=' + UNICODE)
|
||||||
|
assert HTTP_OK in r
|
||||||
|
assert r.json['args'] == {'test': UNICODE}
|
||||||
|
|
||||||
|
# def test_unicode_url_verbose(self):
|
||||||
|
# r = http(httpbin.url + '--verbose', u'/get?test=' + UNICODE)
|
||||||
|
# assert HTTP_OK in r
|
||||||
|
|
||||||
|
|
||||||
|
def test_unicode_basic_auth(httpbin):
|
||||||
|
# it doesn't really authenticate us because httpbin
|
||||||
|
# doesn't interpret the utf8-encoded auth
|
||||||
|
http('--verbose', '--auth', u'test:%s' % UNICODE,
|
||||||
|
httpbin.url + u'/basic-auth/test/' + UNICODE)
|
||||||
|
|
||||||
|
|
||||||
|
def test_unicode_digest_auth(httpbin):
|
||||||
|
# it doesn't really authenticate us because httpbin
|
||||||
|
# doesn't interpret the utf8-encoded auth
|
||||||
|
http('--auth-type=digest',
|
||||||
|
'--auth', u'test:%s' % UNICODE,
|
||||||
|
httpbin.url + u'/digest-auth/auth/test/' + UNICODE)
|
||||||
|
Loading…
Reference in New Issue
Block a user