mirror of
https://github.com/httpie/cli.git
synced 2025-08-14 09:59:11 +02:00
Run tests against local httpbin instance via pytest-httpbin.
This commit is contained in:
@ -9,7 +9,7 @@ from httpie import input
|
||||
from httpie.input import KeyValue, KeyValueArgType
|
||||
from httpie import ExitStatus
|
||||
from httpie.cli import parser
|
||||
from utils import TestEnvironment, http, httpbin, HTTP_OK
|
||||
from utils import TestEnvironment, http, HTTP_OK
|
||||
from fixtures import (
|
||||
FILE_PATH_ARG, JSON_FILE_PATH_ARG,
|
||||
JSON_FILE_CONTENT, FILE_CONTENT, FILE_PATH
|
||||
@ -93,27 +93,28 @@ class TestItemParsing:
|
||||
|
||||
|
||||
class TestQuerystring:
|
||||
def test_query_string_params_in_url(self):
|
||||
r = http('--print=Hhb', 'GET', httpbin('/get?a=1&b=2'))
|
||||
def test_query_string_params_in_url(self, httpbin):
|
||||
r = http('--print=Hhb', 'GET', httpbin.url + '/get?a=1&b=2')
|
||||
path = '/get?a=1&b=2'
|
||||
url = httpbin(path)
|
||||
url = httpbin.url + path
|
||||
assert HTTP_OK in r
|
||||
assert 'GET %s HTTP/1.1' % path in r
|
||||
assert '"url": "%s"' % url in r
|
||||
|
||||
def test_query_string_params_items(self):
|
||||
r = http('--print=Hhb', 'GET', httpbin('/get'), 'a==1', 'b==2')
|
||||
path = '/get?a=1&b=2'
|
||||
url = httpbin(path)
|
||||
def test_query_string_params_items(self, httpbin):
|
||||
r = http('--print=Hhb', 'GET', httpbin.url + '/get', 'a==1')
|
||||
path = '/get?a=1'
|
||||
url = httpbin.url + path
|
||||
assert HTTP_OK in r
|
||||
assert 'GET %s HTTP/1.1' % path in r
|
||||
assert '"url": "%s"' % url in r
|
||||
|
||||
def test_query_string_params_in_url_and_items_with_duplicates(self):
|
||||
r = http('--print=Hhb', 'GET', httpbin('/get?a=1&a=1'),
|
||||
'a==1', 'a==1', 'b==2')
|
||||
path = '/get?a=1&a=1&a=1&a=1&b=2'
|
||||
url = httpbin(path)
|
||||
def test_query_string_params_in_url_and_items_with_duplicates(self,
|
||||
httpbin):
|
||||
r = http('--print=Hhb', 'GET',
|
||||
httpbin.url + '/get?a=1&a=1', 'a==1', 'a==1')
|
||||
path = '/get?a=1&a=1&a=1&a=1'
|
||||
url = httpbin.url + path
|
||||
assert HTTP_OK in r
|
||||
assert 'GET %s HTTP/1.1' % path in r
|
||||
assert '"url": "%s"' % url in r
|
||||
@ -257,12 +258,13 @@ class TestArgumentParser:
|
||||
|
||||
|
||||
class TestNoOptions:
|
||||
def test_valid_no_options(self):
|
||||
r = http('--verbose', '--no-verbose', 'GET', httpbin('/get'))
|
||||
|
||||
def test_valid_no_options(self, httpbin):
|
||||
r = http('--verbose', '--no-verbose', 'GET', httpbin.url + '/get')
|
||||
assert 'GET /get HTTP/1.1' not in r
|
||||
|
||||
def test_invalid_no_options(self):
|
||||
r = http('--no-war', 'GET', httpbin('/get'),
|
||||
def test_invalid_no_options(self, httpbin):
|
||||
r = http('--no-war', 'GET', httpbin.url + '/get',
|
||||
error_exit_ok=True)
|
||||
assert r.exit_status == 1
|
||||
assert 'unrecognized arguments: --no-war' in r.stderr
|
||||
@ -270,16 +272,18 @@ class TestNoOptions:
|
||||
|
||||
|
||||
class TestIgnoreStdin:
|
||||
def test_ignore_stdin(self):
|
||||
|
||||
def test_ignore_stdin(self, httpbin):
|
||||
with open(FILE_PATH) as f:
|
||||
env = TestEnvironment(stdin=f, stdin_isatty=False)
|
||||
r = http('--ignore-stdin', '--verbose', httpbin('/get'), env=env)
|
||||
r = http('--ignore-stdin', '--verbose', httpbin.url + '/get',
|
||||
env=env)
|
||||
assert HTTP_OK in r
|
||||
assert 'GET /get HTTP' in r, "Don't default to POST."
|
||||
assert FILE_CONTENT not in r, "Don't send stdin data."
|
||||
|
||||
def test_ignore_stdin_cannot_prompt_password(self):
|
||||
r = http('--ignore-stdin', '--auth=no-password', httpbin('/get'),
|
||||
def test_ignore_stdin_cannot_prompt_password(self, httpbin):
|
||||
r = http('--ignore-stdin', '--auth=no-password', httpbin.url + '/get',
|
||||
error_exit_ok=True)
|
||||
assert r.exit_status == ExitStatus.ERROR
|
||||
assert 'because --ignore-stdin' in r.stderr
|
||||
|
Reference in New Issue
Block a user