Initial upload: API Mock CLI v0.1.0
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / type-check (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-01-29 13:53:58 +00:00
parent 8446652682
commit af28a38c49

59
tests/test_cli.py Normal file
View File

@@ -0,0 +1,59 @@
import pytest
from click.testing import CliRunner
from src.cli.main import main
class TestCLI:
@pytest.fixture
def runner(self):
return CliRunner()
def test_main_help(self, runner):
result = runner.invoke(main, ["--help"])
assert result.exit_code == 0
assert "API Mock CLI" in result.output
def test_main_version(self, runner):
result = runner.invoke(main, ["--version"])
assert result.exit_code == 0
assert "0.1.0" in result.output
def test_init_command(self, runner, tmp_path):
result = runner.invoke(main, ["init", "--name", "test-api", "--path", str(tmp_path)])
assert result.exit_code == 0
assert "Created mock API project" in result.output
config_path = tmp_path / "test-api" / "config.yaml"
assert config_path.exists()
def test_init_command_with_template(self, runner, tmp_path):
result = runner.invoke(main, [
"init",
"--name", "full-api",
"--template", "full",
"--path", str(tmp_path)
])
assert result.exit_code == 0
def test_stop_no_server(self, runner):
result = runner.invoke(main, ["stop"])
assert result.exit_code == 0
assert "No running server found" in result.output
def test_generate_command(self, runner, tmp_path):
result = runner.invoke(main, [
"generate", "GetUser",
"--method", "GET",
"--path", "/api/users/{id}",
"--output", str(tmp_path / "endpoints.yaml")
])
assert result.exit_code == 0
assert "Generated endpoint" in result.output
def test_generate_with_status_code(self, runner, tmp_path):
result = runner.invoke(main, [
"generate", "CreateItem",
"--method", "POST",
"--status-code", "201",
"--output", str(tmp_path / "endpoints.yaml")
])
assert result.exit_code == 0