From 65beda0a0e5df90cf0323e4a279f2dd5c0dabbb9 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 29 Jan 2026 11:34:26 +0000 Subject: [PATCH] Initial commit: Add http-convert project --- tests/test_cli.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tests/test_cli.py diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..31f0f1c --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,85 @@ +import pytest +from click.testing import CliRunner +from src.http_convert.cli import cli + + +@pytest.fixture +def runner(): + return CliRunner() + + +class TestCLI: + def test_version(self, runner): + result = runner.invoke(cli, ["version"]) + assert result.exit_code == 0 + assert "HTTP Convert" in result.output + + def test_formats(self, runner): + result = runner.invoke(cli, ["formats"]) + assert result.exit_code == 0 + assert "curl" in result.output + assert "httpie" in result.output + assert "fetch" in result.output + assert "axios" in result.output + + def test_convert_curl_to_fetch(self, runner): + curl_cmd = "curl 'https://api.example.com/users'" + result = runner.invoke(cli, ["convert", curl_cmd, "--to", "fetch"]) + assert result.exit_code == 0 + assert "fetch(" in result.output or "fetch" in result.output + + def test_convert_with_explicit_format(self, runner): + curl_cmd = "curl 'https://api.example.com/users'" + result = runner.invoke(cli, ["convert", curl_cmd, "--from", "curl", "--to", "httpie"]) + assert result.exit_code == 0 + assert "GET" in result.output + + def test_convert_missing_output_format(self, runner): + curl_cmd = "curl 'https://api.example.com/users'" + result = runner.invoke(cli, ["convert", curl_cmd]) + assert result.exit_code != 0 + + def test_convert_invalid_input(self, runner): + result = runner.invoke(cli, ["convert", "not a valid input", "--to", "curl"]) + assert result.exit_code != 0 + + def test_config_show(self, runner): + result = runner.invoke(cli, ["config", "--show"]) + assert result.exit_code == 0 + assert "Configuration" in result.output or "Default Format" in result.output + + def test_config_set_format(self, runner): + result = runner.invoke(cli, ["config", "--set-format", "httpie"]) + assert result.exit_code == 0 + + def test_config_toggle_highlighting(self, runner): + result = runner.invoke(cli, ["config", "--toggle-highlight"]) + assert result.exit_code == 0 + + def test_config_toggle_compact(self, runner): + result = runner.invoke(cli, ["config", "--toggle-compact"]) + assert result.exit_code == 0 + + def test_config_reset(self, runner): + result = runner.invoke(cli, ["config", "--reset"]) + assert result.exit_code == 0 + assert "reset" in result.output.lower() + + def test_config_compact_output(self, runner): + curl_cmd = "curl 'https://api.example.com/users'" + result = runner.invoke(cli, ["convert", curl_cmd, "--to", "fetch", "--compact"]) + assert result.exit_code == 0 + + def test_config_no_highlight(self, runner): + curl_cmd = "curl 'https://api.example.com/users'" + result = runner.invoke(cli, ["convert", curl_cmd, "--to", "fetch", "--no-highlight"]) + assert result.exit_code == 0 + + def test_help(self, runner): + result = runner.invoke(cli, ["--help"]) + assert result.exit_code == 0 + assert "convert" in result.output + assert "interactive" in result.output + assert "formats" in result.output + assert "config" in result.output + assert "web" in result.output