Files
mockapi/tests/integration/test_server.py
7000pctAUTO 4bea8c8bc5
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
fix: resolve CI test failures
- Added ruff and mypy installation to CI workflow
- Removed deprecated license classifier from pyproject.toml
- Added pytest conftest.py for proper test discovery
- Fixed test paths in CI to match actual test file locations
- All 46 tests pass locally
2026-03-22 21:50:07 +00:00

70 lines
2.3 KiB
Python

"""Integration tests for mock server."""
import pytest
from mockapi.core.spec_loader import SpecLoader
from mockapi.core.validator import OpenAPIValidator
from mockapi.core.server_generator import MockServerGenerator
from mockapi.core.config import Config
SAMPLE_SPEC_PATH = "examples/petstore.yaml"
class TestMockServerIntegration:
"""Integration tests for mock server."""
@pytest.fixture
def sample_spec(self):
"""Load sample OpenAPI spec."""
loader = SpecLoader(SAMPLE_SPEC_PATH)
return loader.load()
@pytest.fixture
def config(self):
"""Create test configuration."""
return Config(seed=42, port=8080)
def test_load_spec(self, sample_spec):
"""Test loading OpenAPI spec."""
assert sample_spec is not None
assert "openapi" in sample_spec
assert sample_spec["openapi"].startswith("3.0")
def test_validate_spec(self, sample_spec):
"""Test validating OpenAPI spec."""
validator = OpenAPIValidator(sample_spec)
errors = validator.validate()
assert len(errors) == 0
def test_get_paths(self, sample_spec):
"""Test extracting paths from spec."""
validator = OpenAPIValidator(sample_spec)
paths = validator.get_paths()
assert "/users" in paths
assert "/products" in paths
assert "/orders" in paths
def test_generate_mock_server(self, sample_spec, config):
"""Test generating mock server."""
generator = MockServerGenerator(sample_spec, config)
app = generator.generate()
assert app is not None
def test_paths_have_operations(self, sample_spec):
"""Test that paths have operations defined."""
validator = OpenAPIValidator(sample_spec)
paths = validator.get_paths()
for path in paths:
operations = validator.get_operations(path)
assert len(operations) > 0, f"Path {path} has no operations"
def test_schemas_defined(self, sample_spec):
"""Test that schemas are defined in spec."""
validator = OpenAPIValidator(sample_spec)
schemas = validator.get_all_schemas()
assert len(schemas) > 0
assert "User" in schemas
assert "Product" in schemas
assert "Order" in schemas