2014-04-24 14:07:31 +02:00
|
|
|
"""High-level tests."""
|
2014-04-24 14:58:15 +02:00
|
|
|
from unittest import TestCase
|
|
|
|
|
2014-04-24 15:17:04 +02:00
|
|
|
from tests import TestEnvironment, http, httpbin, HTTP_OK
|
|
|
|
from tests.fixtures import FILE_PATH, FILE_CONTENT
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
|
|
|
2014-04-24 14:58:15 +02:00
|
|
|
class HTTPieTest(TestCase):
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
|
|
def test_GET(self):
|
2014-04-24 15:48:01 +02:00
|
|
|
r = http('GET', httpbin('/get'))
|
2014-04-24 14:58:15 +02:00
|
|
|
assert HTTP_OK in r
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
|
|
def test_DELETE(self):
|
2014-04-24 15:48:01 +02:00
|
|
|
r = http('DELETE', httpbin('/delete'))
|
2014-04-24 14:58:15 +02:00
|
|
|
assert HTTP_OK in r
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
|
|
def test_PUT(self):
|
2014-04-24 15:48:01 +02:00
|
|
|
r = http('PUT', httpbin('/put'), 'foo=bar')
|
2014-04-24 14:58:15 +02:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert r'\"foo\": \"bar\"' in r
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
|
|
def test_POST_JSON_data(self):
|
2014-04-24 15:48:01 +02:00
|
|
|
r = http('POST', httpbin('/post'), 'foo=bar')
|
2014-04-24 14:58:15 +02:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert r'\"foo\": \"bar\"' in r
|
2014-04-24 14:07:31 +02:00
|
|
|
|
|
|
|
def test_POST_form(self):
|
2014-04-24 15:48:01 +02:00
|
|
|
r = http('--form', 'POST', httpbin('/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
|
|
|
|
|
|
|
def test_POST_form_multiple_values(self):
|
2014-04-24 15:48:01 +02:00
|
|
|
r = http('--form', 'POST', httpbin('/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
|
|
|
|
|
|
|
def test_POST_stdin(self):
|
|
|
|
|
|
|
|
with open(FILE_PATH) as f:
|
2014-04-24 15:48:01 +02:00
|
|
|
env = TestEnvironment(stdin=f, stdin_isatty=False)
|
|
|
|
r = http('--form', 'POST', httpbin('/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
|
|
|
|
|
|
|
def test_headers(self):
|
2014-04-24 15:48:01 +02:00
|
|
|
r = http('GET', httpbin('/headers'), 'Foo:bar')
|
2014-04-24 14:58:15 +02:00
|
|
|
assert HTTP_OK in r
|
|
|
|
assert '"User-Agent": "HTTPie' in r
|
|
|
|
assert '"Foo": "bar"' in r
|