Add test files for CI
This commit is contained in:
@@ -1,59 +1,91 @@
|
||||
"""Integration tests for CLI."""
|
||||
|
||||
import os
|
||||
import pytest
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
from click.testing import CliRunner
|
||||
|
||||
from mockapi.cli.main import cli
|
||||
|
||||
|
||||
class TestCLIIntegration:
|
||||
"""Integration tests for CLI commands."""
|
||||
"""Test cases for CLI integration."""
|
||||
|
||||
@pytest.fixture
|
||||
def runner(self):
|
||||
"""Create CLI runner."""
|
||||
return CliRunner()
|
||||
def test_validate_command(self):
|
||||
"""Test validate command with valid spec."""
|
||||
spec = {
|
||||
"openapi": "3.0.0",
|
||||
"info": {"title": "Test API", "version": "1.0.0"},
|
||||
"paths": {
|
||||
"/users": {
|
||||
"get": {"operationId": "getUsers", "responses": {"200": {"description": "OK"}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@pytest.fixture
|
||||
def sample_spec_path(self):
|
||||
"""Path to sample spec file."""
|
||||
return "examples/petstore.yaml"
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w", suffix=".yaml", delete=False
|
||||
) as f:
|
||||
yaml.dump(spec, f)
|
||||
f.flush()
|
||||
|
||||
def test_validate_command(self, runner, sample_spec_path):
|
||||
"""Test validate command."""
|
||||
result = runner.invoke(cli, ["validate", sample_spec_path])
|
||||
assert result.exit_code == 0
|
||||
assert "valid" in result.output.lower() or "paths" in result.output.lower()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["validate", f.name])
|
||||
|
||||
def test_validate_nonexistent_file(self, runner):
|
||||
assert result.exit_code == 0
|
||||
assert "valid" in result.output.lower()
|
||||
|
||||
Path(f.name).unlink()
|
||||
|
||||
def test_validate_nonexistent_file(self):
|
||||
"""Test validate command with non-existent file."""
|
||||
result = runner.invoke(cli, ["validate", "nonexistent.yaml"])
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["validate", "/nonexistent/file.yaml"])
|
||||
assert result.exit_code != 0
|
||||
|
||||
def test_generate_command(self, runner, sample_spec_path):
|
||||
def test_generate_command(self):
|
||||
"""Test generate command."""
|
||||
result = runner.invoke(cli, ["generate", sample_spec_path])
|
||||
assert result.exit_code == 0
|
||||
assert "users" in result.output.lower() or "endpoints" in result.output.lower()
|
||||
spec = {
|
||||
"openapi": "3.0.0",
|
||||
"info": {"title": "Test API", "version": "1.0.0"},
|
||||
"paths": {
|
||||
"/users": {
|
||||
"get": {"operationId": "getUsers", "summary": "Get all users"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def test_show_config_command(self, runner):
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w", suffix=".yaml", delete=False
|
||||
) as f:
|
||||
yaml.dump(spec, f)
|
||||
f.flush()
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["generate", f.name])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "users" in result.output.lower()
|
||||
|
||||
Path(f.name).unlink()
|
||||
|
||||
def test_show_config_command(self):
|
||||
"""Test show-config command."""
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["show-config"])
|
||||
assert result.exit_code == 0
|
||||
assert "port" in result.output.lower()
|
||||
assert "host" in result.output.lower()
|
||||
assert "Port" in result.output
|
||||
|
||||
def test_cli_version(self, runner):
|
||||
"""Test CLI version flag."""
|
||||
def test_cli_version(self):
|
||||
"""Test CLI version."""
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--version"])
|
||||
assert result.exit_code == 0
|
||||
assert "mockapi" in result.output.lower() or "0.1" in result.output
|
||||
|
||||
def test_cli_help(self, runner):
|
||||
def test_cli_help(self):
|
||||
"""Test CLI help."""
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "validate" in result.output.lower()
|
||||
assert "start" in result.output.lower()
|
||||
assert "generate" in result.output.lower()
|
||||
|
||||
Reference in New Issue
Block a user