Dont apply default options on the httpie command (#1280)

* Mark tests with requires_installation

* Dont apply default options on the httpie command

* lint
This commit is contained in:
Batuhan Taskaya 2022-01-24 21:13:47 +03:00 committed by GitHub
parent 45fcd746d7
commit 813e8864a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 3 deletions

View File

@ -30,14 +30,15 @@ def raw_main(
parser: argparse.ArgumentParser, parser: argparse.ArgumentParser,
main_program: Callable[[argparse.Namespace, Environment], ExitStatus], main_program: Callable[[argparse.Namespace, Environment], ExitStatus],
args: List[Union[str, bytes]] = sys.argv, args: List[Union[str, bytes]] = sys.argv,
env: Environment = Environment() env: Environment = Environment(),
use_default_options: bool = True,
) -> ExitStatus: ) -> ExitStatus:
program_name, *args = args program_name, *args = args
env.program_name = os.path.basename(program_name) env.program_name = os.path.basename(program_name)
args = decode_raw_args(args, env.stdin_encoding) args = decode_raw_args(args, env.stdin_encoding)
plugin_manager.load_installed_plugins(env.config.plugins_dir) plugin_manager.load_installed_plugins(env.config.plugins_dir)
if env.config.default_options: if use_default_options and env.config.default_options:
args = env.config.default_options + args args = env.config.default_options + args
include_debug_info = '--debug' in args include_debug_info = '--debug' in args

View File

@ -37,7 +37,8 @@ def main(args: List[Union[str, bytes]] = sys.argv, env: Environment = Environmen
parser=parser, parser=parser,
main_program=main_program, main_program=main_program,
args=args, args=args,
env=env env=env,
use_default_options=False,
) )
except argparse.ArgumentError: except argparse.ArgumentError:
program_args = args[1:] program_args = args[1:]

3
pytest.ini Normal file
View File

@ -0,0 +1,3 @@
[pytest]
markers =
requires_installation

View File

@ -5,6 +5,7 @@ from tests.utils import httpie
from tests.utils.plugins_cli import parse_listing from tests.utils.plugins_cli import parse_listing
@pytest.mark.requires_installation
def test_plugins_installation(httpie_plugins_success, interface, dummy_plugin): def test_plugins_installation(httpie_plugins_success, interface, dummy_plugin):
lines = httpie_plugins_success('install', dummy_plugin.path) lines = httpie_plugins_success('install', dummy_plugin.path)
assert lines[0].startswith( assert lines[0].startswith(
@ -14,6 +15,20 @@ def test_plugins_installation(httpie_plugins_success, interface, dummy_plugin):
assert interface.is_installed(dummy_plugin.name) assert interface.is_installed(dummy_plugin.name)
@pytest.mark.requires_installation
def test_plugin_installation_with_custom_config(httpie_plugins_success, interface, dummy_plugin):
interface.environment.config['default_options'] = ['--session-read-only', 'some-path.json', 'other', 'args']
interface.environment.config.save()
lines = httpie_plugins_success('install', dummy_plugin.path)
assert lines[0].startswith(
f'Installing {dummy_plugin.path}'
)
assert f'Successfully installed {dummy_plugin.name}-{dummy_plugin.version}' in lines
assert interface.is_installed(dummy_plugin.name)
@pytest.mark.requires_installation
def test_plugins_listing(httpie_plugins_success, interface, dummy_plugin): def test_plugins_listing(httpie_plugins_success, interface, dummy_plugin):
httpie_plugins_success('install', dummy_plugin.path) httpie_plugins_success('install', dummy_plugin.path)
data = parse_listing(httpie_plugins_success('list')) data = parse_listing(httpie_plugins_success('list'))
@ -23,6 +38,7 @@ def test_plugins_listing(httpie_plugins_success, interface, dummy_plugin):
} }
@pytest.mark.requires_installation
def test_plugins_listing_multiple(interface, httpie_plugins_success, dummy_plugins): def test_plugins_listing_multiple(interface, httpie_plugins_success, dummy_plugins):
paths = [plugin.path for plugin in dummy_plugins] paths = [plugin.path for plugin in dummy_plugins]
httpie_plugins_success('install', *paths) httpie_plugins_success('install', *paths)
@ -34,12 +50,14 @@ def test_plugins_listing_multiple(interface, httpie_plugins_success, dummy_plugi
} }
@pytest.mark.requires_installation
def test_plugins_uninstall(interface, httpie_plugins_success, dummy_plugin): def test_plugins_uninstall(interface, httpie_plugins_success, dummy_plugin):
httpie_plugins_success('install', dummy_plugin.path) httpie_plugins_success('install', dummy_plugin.path)
httpie_plugins_success('uninstall', dummy_plugin.name) httpie_plugins_success('uninstall', dummy_plugin.name)
assert not interface.is_installed(dummy_plugin.name) assert not interface.is_installed(dummy_plugin.name)
@pytest.mark.requires_installation
def test_plugins_listing_after_uninstall(interface, httpie_plugins_success, dummy_plugin): def test_plugins_listing_after_uninstall(interface, httpie_plugins_success, dummy_plugin):
httpie_plugins_success('install', dummy_plugin.path) httpie_plugins_success('install', dummy_plugin.path)
httpie_plugins_success('uninstall', dummy_plugin.name) httpie_plugins_success('uninstall', dummy_plugin.name)
@ -48,6 +66,7 @@ def test_plugins_listing_after_uninstall(interface, httpie_plugins_success, dumm
assert len(data) == 0 assert len(data) == 0
@pytest.mark.requires_installation
def test_plugins_uninstall_specific(interface, httpie_plugins_success): def test_plugins_uninstall_specific(interface, httpie_plugins_success):
new_plugin_1 = interface.make_dummy_plugin() new_plugin_1 = interface.make_dummy_plugin()
new_plugin_2 = interface.make_dummy_plugin() new_plugin_2 = interface.make_dummy_plugin()
@ -61,6 +80,7 @@ def test_plugins_uninstall_specific(interface, httpie_plugins_success):
assert not interface.is_installed(target_plugin.name) assert not interface.is_installed(target_plugin.name)
@pytest.mark.requires_installation
def test_plugins_installation_failed(httpie_plugins, interface): def test_plugins_installation_failed(httpie_plugins, interface):
plugin = interface.make_dummy_plugin(build=False) plugin = interface.make_dummy_plugin(build=False)
result = httpie_plugins('install', plugin.path) result = httpie_plugins('install', plugin.path)
@ -69,6 +89,7 @@ def test_plugins_installation_failed(httpie_plugins, interface):
assert result.stderr.splitlines()[-1].strip().startswith("Can't install") assert result.stderr.splitlines()[-1].strip().startswith("Can't install")
@pytest.mark.requires_installation
def test_plugins_uninstall_non_existent(httpie_plugins, interface): def test_plugins_uninstall_non_existent(httpie_plugins, interface):
plugin = interface.make_dummy_plugin(build=False) plugin = interface.make_dummy_plugin(build=False)
result = httpie_plugins('uninstall', plugin.name) result = httpie_plugins('uninstall', plugin.name)
@ -80,6 +101,7 @@ def test_plugins_uninstall_non_existent(httpie_plugins, interface):
) )
@pytest.mark.requires_installation
def test_plugins_double_uninstall(httpie_plugins, httpie_plugins_success, dummy_plugin): def test_plugins_double_uninstall(httpie_plugins, httpie_plugins_success, dummy_plugin):
httpie_plugins_success("install", dummy_plugin.path) httpie_plugins_success("install", dummy_plugin.path)
httpie_plugins_success("uninstall", dummy_plugin.name) httpie_plugins_success("uninstall", dummy_plugin.name)
@ -93,6 +115,7 @@ def test_plugins_double_uninstall(httpie_plugins, httpie_plugins_success, dummy_
) )
@pytest.mark.requires_installation
def test_plugins_upgrade(httpie_plugins, httpie_plugins_success, dummy_plugin): def test_plugins_upgrade(httpie_plugins, httpie_plugins_success, dummy_plugin):
httpie_plugins_success("install", dummy_plugin.path) httpie_plugins_success("install", dummy_plugin.path)
@ -105,6 +128,7 @@ def test_plugins_upgrade(httpie_plugins, httpie_plugins_success, dummy_plugin):
assert data[dummy_plugin.name]['version'] == '2.0.0' assert data[dummy_plugin.name]['version'] == '2.0.0'
@pytest.mark.requires_installation
def test_broken_plugins(httpie_plugins, httpie_plugins_success, dummy_plugin, broken_plugin): def test_broken_plugins(httpie_plugins, httpie_plugins_success, dummy_plugin, broken_plugin):
httpie_plugins_success("install", dummy_plugin.path, broken_plugin.path) httpie_plugins_success("install", dummy_plugin.path, broken_plugin.path)
@ -127,6 +151,7 @@ def test_broken_plugins(httpie_plugins, httpie_plugins_success, dummy_plugin, br
assert len(data) == 1 assert len(data) == 1
@pytest.mark.requires_installation
def test_plugins_cli_error_message_without_args(): def test_plugins_cli_error_message_without_args():
# No arguments # No arguments
result = httpie(no_debug=True) result = httpie(no_debug=True)
@ -143,6 +168,7 @@ def test_plugins_cli_error_message_without_args():
'POST pie.dev/post header:value a=b header_2:value x:=1' 'POST pie.dev/post header:value a=b header_2:value x:=1'
] ]
) )
@pytest.mark.requires_installation
def test_plugins_cli_error_messages_with_example(example): def test_plugins_cli_error_messages_with_example(example):
result = httpie(*example.split(), no_debug=True) result = httpie(*example.split(), no_debug=True)
assert result.exit_status == ExitStatus.ERROR assert result.exit_status == ExitStatus.ERROR
@ -158,6 +184,7 @@ def test_plugins_cli_error_messages_with_example(example):
'unknown.com UNPARSABLE????SYNTAX', 'unknown.com UNPARSABLE????SYNTAX',
] ]
) )
@pytest.mark.requires_installation
def test_plugins_cli_error_messages_invalid_example(example): def test_plugins_cli_error_messages_invalid_example(example):
result = httpie(*example.split(), no_debug=True) result = httpie(*example.split(), no_debug=True)
assert result.exit_status == ExitStatus.ERROR assert result.exit_status == ExitStatus.ERROR