1
0
mirror of https://github.com/httpie/cli.git synced 2025-08-10 22:42:05 +02:00

Implemented more robust unicode handling.

* Immediatelly convert all args from `bytes` to `str`.
* Added `Environment.stdin_encoding` and `Environment.stdout_encoding`
* Allow unicode characters in HTTP headers and basic auth credentials
  by encoding them using UTF8 instead of latin1 (#212).
This commit is contained in:
Jakub Roztocil
2014-04-26 15:06:51 +02:00
parent 5c29a4e551
commit 15e62ad26d
14 changed files with 177 additions and 39 deletions

View File

@@ -22,14 +22,15 @@ class TestExitStatus:
reason='timeout broken in requests'
' (https://github.com/jkbr/httpie/issues/185)')
def test_timeout_exit_status(self):
r = http('--timeout=0.5', 'GET', httpbin('/delay/1'))
r = http('--timeout=0.5', 'GET', httpbin('/delay/1'),
error_exit_ok=True)
assert HTTP_OK in r
assert r.exit_status == ExitStatus.ERROR_TIMEOUT
def test_3xx_check_status_exits_3_and_stderr_when_stdout_redirected(self):
env = TestEnvironment(stdout_isatty=False)
r = http('--check-status', '--headers', 'GET', httpbin('/status/301'),
env=env)
env=env, error_exit_ok=True)
assert 'HTTP/1.1 301' in r
assert r.exit_status == ExitStatus.ERROR_HTTP_3XX
assert '301 moved permanently' in r.stderr.lower()
@@ -38,19 +39,22 @@ class TestExitStatus:
requests.__version__ == '0.13.6',
reason='Redirects with prefetch=False are broken in Requests 0.13.6')
def test_3xx_check_status_redirects_allowed_exits_0(self):
r = http('--check-status', '--follow', 'GET', httpbin('/status/301'))
r = http('--check-status', '--follow', 'GET', httpbin('/status/301'),
error_exit_ok=True)
# The redirect will be followed so 200 is expected.
assert 'HTTP/1.1 200 OK' in r
assert r.exit_status == ExitStatus.OK
def test_4xx_check_status_exits_4(self):
r = http('--check-status', 'GET', httpbin('/status/401'))
r = http('--check-status', 'GET', httpbin('/status/401'),
error_exit_ok=True)
assert 'HTTP/1.1 401' 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):
r = http('--check-status', 'GET', httpbin('/status/500'))
r = http('--check-status', 'GET', httpbin('/status/500'),
error_exit_ok=True)
assert 'HTTP/1.1 500' in r
assert r.exit_status == ExitStatus.ERROR_HTTP_5XX