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
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:
59
tests/test_cli.py
Normal file
59
tests/test_cli.py
Normal 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
|
||||
Reference in New Issue
Block a user