67 lines
2.2 KiB
Python
67 lines
2.2 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
|
|
|
|
|
|
class TestMockServerIntegration:
|
|
"""Integration tests for mock server."""
|
|
|
|
@pytest.fixture
|
|
def sample_spec(self, sample_spec_path):
|
|
"""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 |