2014-04-24 15:07:31 +03:00
|
|
|
"""High-level tests."""
|
2014-04-24 16:17:04 +03:00
|
|
|
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
|
|
|
from tests.fixtures import FILE_PATH, FILE_CONTENT
|
2014-04-24 19:32:15 +03:00
|
|
|
import httpie
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
|
2014-04-25 12:39:59 +03:00
|
|
|
class TestHTTPie:
|
2014-04-24 15:07:31 +03:00
|
|
|
|
2014-04-24 19:32:15 +03:00
|
|
|
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):
|
2014-04-26 16:06:51 +03:00
|
|
|
r = http('--help', error_exit_ok=True)
|
2014-04-24 19:32:15 +03:00
|
|
|
assert r.exit_status == httpie.ExitStatus.ERROR
|
|
|
|
assert 'https://github.com/jkbr/httpie/issues' in r
|
|
|
|
|
2014-04-24 20:32:39 +03:00
|
|
|
def test_version(self):
|
2014-04-26 16:06:51 +03:00
|
|
|
r = http('--version', error_exit_ok=True)
|
2014-04-24 20:32:39 +03:00
|
|
|
assert r.exit_status == httpie.ExitStatus.ERROR
|
2014-04-24 20:56:11 +03:00
|
|
|
# FIXME: py3 has version in stdout, py2 in stderr
|
|
|
|
assert httpie.__version__ == r.stderr.strip() + r.strip()
|
2014-04-24 20:32:39 +03:00
|
|
|
|
2014-04-24 15:07:31 +03:00
|
|
|
def test_GET(self):
|
2014-04-24 16:48:01 +03:00
|
|
|
r = http('GET', httpbin('/get'))
|
2014-04-24 15:58:15 +03:00
|
|
|
assert HTTP_OK in r
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
def test_DELETE(self):
|
2014-04-24 16:48:01 +03:00
|
|
|
r = http('DELETE', httpbin('/delete'))
|
2014-04-24 15:58:15 +03:00
|
|
|
assert HTTP_OK in r
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
def test_PUT(self):
|
2014-04-24 16:48:01 +03:00
|
|
|
r = http('PUT', httpbin('/put'), 'foo=bar')
|
2014-04-24 15:58:15 +03:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert r'\"foo\": \"bar\"' in r
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
def test_POST_JSON_data(self):
|
2014-04-24 16:48:01 +03:00
|
|
|
r = http('POST', httpbin('/post'), 'foo=bar')
|
2014-04-24 15:58:15 +03:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert r'\"foo\": \"bar\"' in r
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
def test_POST_form(self):
|
2014-04-24 16:48:01 +03:00
|
|
|
r = http('--form', 'POST', httpbin('/post'), 'foo=bar')
|
2014-04-24 15:58:15 +03:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert '"foo": "bar"' in r
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
def test_POST_form_multiple_values(self):
|
2014-04-24 16:48:01 +03:00
|
|
|
r = http('--form', 'POST', httpbin('/post'), 'foo=bar', 'foo=baz')
|
2014-04-24 15:58:15 +03:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert r.json['form'] == {'foo': ['bar', 'baz']}
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
def test_POST_stdin(self):
|
|
|
|
with open(FILE_PATH) as f:
|
2014-04-24 16:48:01 +03:00
|
|
|
env = TestEnvironment(stdin=f, stdin_isatty=False)
|
|
|
|
r = http('--form', 'POST', httpbin('/post'), env=env)
|
2014-04-24 15:58:15 +03:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert FILE_CONTENT in r
|
2014-04-24 15:07:31 +03:00
|
|
|
|
|
|
|
def test_headers(self):
|
2014-04-24 16:48:01 +03:00
|
|
|
r = http('GET', httpbin('/headers'), 'Foo:bar')
|
2014-04-24 15:58:15 +03:00
|
|
|
assert HTTP_OK in r
|
2014-04-26 18:16:11 +03:00
|
|
|
assert '"User-Agent": "HTTPie' in r, r
|
2014-04-24 15:58:15 +03:00
|
|
|
assert '"Foo": "bar"' in r
|