mirror of
https://github.com/httpie/cli.git
synced 2024-11-22 15:53:13 +01:00
Impreved tests.
This commit is contained in:
parent
926d3f5caf
commit
180313d80c
@ -1,7 +1,3 @@
|
|||||||
"""
|
|
||||||
High-level tests.
|
|
||||||
|
|
||||||
"""
|
|
||||||
import unittest
|
import unittest
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
@ -22,6 +18,7 @@ from httpie import __main__, cliparse
|
|||||||
|
|
||||||
|
|
||||||
TEST_FILE_PATH = os.path.join(TESTS_ROOT, 'file.txt')
|
TEST_FILE_PATH = os.path.join(TESTS_ROOT, 'file.txt')
|
||||||
|
TEST_FILE_CONTENT = open(TEST_FILE_PATH).read().strip()
|
||||||
TERMINAL_COLOR_PRESENCE_CHECK = '\x1b['
|
TERMINAL_COLOR_PRESENCE_CHECK = '\x1b['
|
||||||
|
|
||||||
|
|
||||||
@ -93,18 +90,21 @@ class HTTPieTest(BaseTestCase):
|
|||||||
self.assertIn('"Accept": "application/xml"', r)
|
self.assertIn('"Accept": "application/xml"', r)
|
||||||
|
|
||||||
def test_POST_form(self):
|
def test_POST_form(self):
|
||||||
response = http('--form', 'POST', 'http://httpbin.org/post', 'foo=bar')
|
r = http('--form', 'POST', 'http://httpbin.org/post', 'foo=bar')
|
||||||
self.assertIn('"foo": "bar"', response)
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
|
self.assertIn('"foo": "bar"', r)
|
||||||
|
|
||||||
def test_POST_stdin(self):
|
def test_POST_stdin(self):
|
||||||
r = http('--form', 'POST', 'http://httpbin.org/post',
|
r = http('--form', 'POST', 'http://httpbin.org/post',
|
||||||
stdin=open(TEST_FILE_PATH), stdin_isatty=False)
|
stdin=open(TEST_FILE_PATH), stdin_isatty=False)
|
||||||
self.assertIn('HTTP/1.1 200', r)
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
|
self.assertIn(TEST_FILE_CONTENT, r)
|
||||||
|
|
||||||
def test_headers(self):
|
def test_headers(self):
|
||||||
response = http('GET', 'http://httpbin.org/headers', 'Foo:bar')
|
r = http('GET', 'http://httpbin.org/headers', 'Foo:bar')
|
||||||
self.assertIn('"User-Agent": "HTTPie', response)
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
self.assertIn('"Foo": "bar"', response)
|
self.assertIn('"User-Agent": "HTTPie', r)
|
||||||
|
self.assertIn('"Foo": "bar"', r)
|
||||||
|
|
||||||
|
|
||||||
class ImplicitHTTPMethodTest(BaseTestCase):
|
class ImplicitHTTPMethodTest(BaseTestCase):
|
||||||
@ -115,18 +115,18 @@ class ImplicitHTTPMethodTest(BaseTestCase):
|
|||||||
|
|
||||||
def test_implicit_GET_with_headers(self):
|
def test_implicit_GET_with_headers(self):
|
||||||
r = http('http://httpbin.org/headers', 'Foo:bar')
|
r = http('http://httpbin.org/headers', 'Foo:bar')
|
||||||
self.assertIn('"Foo": "bar"', r)
|
|
||||||
self.assertIn('HTTP/1.1 200', r)
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
|
self.assertIn('"Foo": "bar"', r)
|
||||||
|
|
||||||
def test_implicit_POST_json(self):
|
def test_implicit_POST_json(self):
|
||||||
r = http('http://httpbin.org/post', 'hello=world')
|
r = http('http://httpbin.org/post', 'hello=world')
|
||||||
self.assertIn('"hello": "world"', r)
|
|
||||||
self.assertIn('HTTP/1.1 200', r)
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
|
self.assertIn('"hello": "world"', r)
|
||||||
|
|
||||||
def test_implicit_POST_form(self):
|
def test_implicit_POST_form(self):
|
||||||
r = http('--form', 'http://httpbin.org/post', 'foo=bar')
|
r = http('--form', 'http://httpbin.org/post', 'foo=bar')
|
||||||
self.assertIn('"foo": "bar"', r)
|
|
||||||
self.assertIn('HTTP/1.1 200', r)
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
|
self.assertIn('"foo": "bar"', r)
|
||||||
|
|
||||||
def test_implicit_POST_stdin(self):
|
def test_implicit_POST_stdin(self):
|
||||||
r = http('--form', 'http://httpbin.org/post',
|
r = http('--form', 'http://httpbin.org/post',
|
||||||
@ -158,11 +158,13 @@ class VerboseFlagTest(BaseTestCase):
|
|||||||
|
|
||||||
def test_verbose(self):
|
def test_verbose(self):
|
||||||
r = http('--verbose', 'GET', 'http://httpbin.org/get', 'test-header:__test__')
|
r = http('--verbose', 'GET', 'http://httpbin.org/get', 'test-header:__test__')
|
||||||
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
self.assertEqual(r.count('__test__'), 2)
|
self.assertEqual(r.count('__test__'), 2)
|
||||||
|
|
||||||
def test_verbose_form(self):
|
def test_verbose_form(self):
|
||||||
# https://github.com/jkbr/httpie/issues/53
|
# https://github.com/jkbr/httpie/issues/53
|
||||||
r = http('--verbose', '--form', 'POST', 'http://httpbin.org/post', 'foo=bar', 'baz=bar')
|
r = http('--verbose', '--form', 'POST', 'http://httpbin.org/post', 'foo=bar', 'baz=bar')
|
||||||
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
self.assertIn('foo=bar&baz=bar', r)
|
self.assertIn('foo=bar&baz=bar', r)
|
||||||
|
|
||||||
|
|
||||||
@ -177,6 +179,7 @@ class MultipartFormDataFileUploadTest(BaseTestCase):
|
|||||||
def test_upload_ok(self):
|
def test_upload_ok(self):
|
||||||
r = http('--form', 'POST', 'http://httpbin.org/post',
|
r = http('--form', 'POST', 'http://httpbin.org/post',
|
||||||
'test-file@%s' % TEST_FILE_PATH, 'foo=bar')
|
'test-file@%s' % TEST_FILE_PATH, 'foo=bar')
|
||||||
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
self.assertIn('"test-file": "__test_file_content__', r)
|
self.assertIn('"test-file": "__test_file_content__', r)
|
||||||
self.assertIn('"foo": "bar"', r)
|
self.assertIn('"foo": "bar"', r)
|
||||||
|
|
||||||
@ -186,12 +189,14 @@ class AuthTest(BaseTestCase):
|
|||||||
def test_basic_auth(self):
|
def test_basic_auth(self):
|
||||||
r = http('--auth', 'user:password',
|
r = http('--auth', 'user:password',
|
||||||
'GET', 'httpbin.org/basic-auth/user/password')
|
'GET', 'httpbin.org/basic-auth/user/password')
|
||||||
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
self.assertIn('"authenticated": true', r)
|
self.assertIn('"authenticated": true', r)
|
||||||
self.assertIn('"user": "user"', r)
|
self.assertIn('"user": "user"', r)
|
||||||
|
|
||||||
def test_digest_auth(self):
|
def test_digest_auth(self):
|
||||||
r = http('--auth-type=digest', '--auth', 'user:password',
|
r = http('--auth-type=digest', '--auth', 'user:password',
|
||||||
'GET', 'httpbin.org/digest-auth/auth/user/password')
|
'GET', 'httpbin.org/digest-auth/auth/user/password')
|
||||||
|
self.assertIn('HTTP/1.1 200', r)
|
||||||
self.assertIn('"authenticated": true', r)
|
self.assertIn('"authenticated": true', r)
|
||||||
self.assertIn('"user": "user"', r)
|
self.assertIn('"user": "user"', r)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user