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