Ejemplo n.º 1
0
def test_plugins_cli_error_message_without_args():
    # No arguments
    result = httpie(no_debug=True)
    assert result.exit_status == ExitStatus.ERROR
    assert 'usage: ' in result.stderr
    assert 'specify one of these' in result.stderr
    assert 'please use the http/https commands:' in result.stderr
Ejemplo n.º 2
0
 def runner(*args):
     # Prevent installed plugins from showing up.
     original_plugins = plugin_manager.copy()
     clean_sys_path = set(sys.path).difference(site.getsitepackages())
     with patch('sys.path', list(clean_sys_path)):
         response = httpie('plugins', *args, env=interface.environment)
     plugin_manager.clear()
     plugin_manager.extend(original_plugins)
     return response
Ejemplo n.º 3
0
def test_httpie_sessions_upgrade(tmp_path, old_session_file, new_session_file, extra_args, extra_variables):
    session_path = tmp_path / 'session.json'
    shutil.copyfile(old_session_file, session_path)

    result = httpie(
        'cli', 'sessions', 'upgrade', *extra_args, DUMMY_HOST, str(session_path)
    )
    assert result.exit_status == ExitStatus.SUCCESS
    assert read_session_file(session_path) == read_session_file(
        new_session_file, extra_variables=extra_variables
    )
Ejemplo n.º 4
0
    def runner(*args, cli_mode: bool = True):
        args = list(args)
        if cli_mode:
            args.insert(0, 'cli')
        args.insert(cli_mode, 'plugins')

        # Prevent installed plugins from showing up.
        original_plugins = plugin_manager.copy()
        clean_sys_path = set(sys.path).difference(site.getsitepackages())
        with patch('sys.path', list(clean_sys_path)):
            response = httpie(*args, env=interface.environment)
        plugin_manager.clear()
        plugin_manager.extend(original_plugins)
        return response
Ejemplo n.º 5
0
def test_httpie_sessions_upgrade_all(tmp_path, mock_env, extra_args, extra_variables):
    mock_env._create_temp_config_dir = False
    mock_env.config_dir = tmp_path / "config"

    session_dir = mock_env.config_dir / SESSIONS_DIR_NAME / DUMMY_HOST
    session_dir.mkdir(parents=True)
    for original_session_file in SESSION_FILES_OLD:
        shutil.copy(original_session_file, session_dir)

    result = httpie(
        'cli', 'sessions', 'upgrade-all', *extra_args, env=mock_env
    )
    assert result.exit_status == ExitStatus.SUCCESS

    for refactored_session_file, expected_session_file in zip(
        sorted(session_dir.glob("*.json")),
        SESSION_FILES_NEW
    ):
        assert read_session_file(refactored_session_file) == read_session_file(
            expected_session_file, extra_variables=extra_variables
        )
Ejemplo n.º 6
0
def test_httpie_sessions_upgrade_on_non_existent_file(tmp_path):
    session_path = tmp_path / 'session.json'
    result = httpie('cli', 'sessions', 'upgrade', DUMMY_HOST, str(session_path))
    assert result.exit_status == ExitStatus.ERROR
    assert 'does not exist' in result.stderr
Ejemplo n.º 7
0
def test_plugins_cli_error_messages_invalid_example(example):
    result = httpie(*example.split(), no_debug=True)
    assert result.exit_status == ExitStatus.ERROR
    assert 'usage: ' in result.stderr
    assert f'http {example}' not in result.stderr
    assert f'https {example}' not in result.stderr
Ejemplo n.º 8
0
def test_cli_export(load_func, extra_options):
    response = httpie('cli', 'export-args', *extra_options)
    assert response.exit_status == ExitStatus.SUCCESS
    assert load_func(response)['version'] == PARSER_SPEC_VERSION