This commit is contained in:
85
tests/test_cli.py
Normal file
85
tests/test_cli.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user