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
This commit is contained in:
@@ -8,99 +8,63 @@ from mockapi.core.server_generator import MockServerGenerator
|
|||||||
from mockapi.core.config import Config
|
from mockapi.core.config import Config
|
||||||
|
|
||||||
|
|
||||||
|
SAMPLE_SPEC_PATH = "examples/petstore.yaml"
|
||||||
|
|
||||||
|
|
||||||
class TestMockServerIntegration:
|
class TestMockServerIntegration:
|
||||||
"""Test cases for mock server integration."""
|
"""Integration tests for mock server."""
|
||||||
|
|
||||||
def test_load_spec(self):
|
@pytest.fixture
|
||||||
"""Test loading a spec."""
|
def sample_spec(self):
|
||||||
spec_dict = {
|
"""Load sample OpenAPI spec."""
|
||||||
"openapi": "3.0.0",
|
loader = SpecLoader(SAMPLE_SPEC_PATH)
|
||||||
"info": {"title": "Test API", "version": "1.0.0"},
|
return loader.load()
|
||||||
"paths": {
|
|
||||||
"/users": {
|
|
||||||
"get": {"operationId": "getUsers", "responses": {"200": {"description": "OK"}}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
generator = MockServerGenerator(spec_dict)
|
|
||||||
assert generator.spec is not None
|
|
||||||
|
|
||||||
def test_validate_spec(self):
|
@pytest.fixture
|
||||||
"""Test validating a spec."""
|
def config(self):
|
||||||
spec = {
|
"""Create test configuration."""
|
||||||
"openapi": "3.0.0",
|
return Config(seed=42, port=8080)
|
||||||
"info": {"title": "Test", "version": "1.0.0"},
|
|
||||||
"paths": {},
|
|
||||||
}
|
|
||||||
validator = OpenAPIValidator(spec)
|
|
||||||
assert validator.is_valid() is True
|
|
||||||
|
|
||||||
def test_get_paths(self):
|
def test_load_spec(self, sample_spec):
|
||||||
"""Test getting paths from spec."""
|
"""Test loading OpenAPI spec."""
|
||||||
spec = {
|
assert sample_spec is not None
|
||||||
"openapi": "3.0.0",
|
assert "openapi" in sample_spec
|
||||||
"info": {"title": "Test", "version": "1.0.0"},
|
assert sample_spec["openapi"].startswith("3.0")
|
||||||
"paths": {
|
|
||||||
"/users": {},
|
def test_validate_spec(self, sample_spec):
|
||||||
"/items": {},
|
"""Test validating OpenAPI spec."""
|
||||||
},
|
validator = OpenAPIValidator(sample_spec)
|
||||||
}
|
errors = validator.validate()
|
||||||
validator = OpenAPIValidator(spec)
|
assert len(errors) == 0
|
||||||
|
|
||||||
|
def test_get_paths(self, sample_spec):
|
||||||
|
"""Test extracting paths from spec."""
|
||||||
|
validator = OpenAPIValidator(sample_spec)
|
||||||
paths = validator.get_paths()
|
paths = validator.get_paths()
|
||||||
assert len(paths) == 2
|
assert "/users" in paths
|
||||||
|
assert "/products" in paths
|
||||||
|
assert "/orders" in paths
|
||||||
|
|
||||||
def test_generate_mock_server(self):
|
def test_generate_mock_server(self, sample_spec, config):
|
||||||
"""Test generating a mock server."""
|
"""Test generating mock server."""
|
||||||
spec = {
|
generator = MockServerGenerator(sample_spec, config)
|
||||||
"openapi": "3.0.0",
|
|
||||||
"info": {"title": "Test API", "version": "1.0.0"},
|
|
||||||
"paths": {
|
|
||||||
"/users": {
|
|
||||||
"get": {"operationId": "getUsers", "responses": {"200": {"description": "OK"}}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
config = Config()
|
|
||||||
generator = MockServerGenerator(spec, config)
|
|
||||||
app = generator.generate()
|
app = generator.generate()
|
||||||
assert app is not None
|
assert app is not None
|
||||||
|
|
||||||
def test_paths_have_operations(self):
|
def test_paths_have_operations(self, sample_spec):
|
||||||
"""Test that paths have operations defined."""
|
"""Test that paths have operations defined."""
|
||||||
spec = {
|
validator = OpenAPIValidator(sample_spec)
|
||||||
"openapi": "3.0.0",
|
paths = validator.get_paths()
|
||||||
"info": {"title": "Test API", "version": "1.0.0"},
|
|
||||||
"paths": {
|
|
||||||
"/users": {
|
|
||||||
"get": {"operationId": "getUsers", "responses": {"200": {}}},
|
|
||||||
"post": {"operationId": "createUser", "responses": {"201": {}}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
validator = OpenAPIValidator(spec)
|
|
||||||
ops = validator.get_operations("/users")
|
|
||||||
assert "get" in ops
|
|
||||||
assert "post" in ops
|
|
||||||
|
|
||||||
def test_schemas_defined(self):
|
for path in paths:
|
||||||
"""Test that schemas are properly defined."""
|
operations = validator.get_operations(path)
|
||||||
spec = {
|
assert len(operations) > 0, f"Path {path} has no operations"
|
||||||
"openapi": "3.0.0",
|
|
||||||
"info": {"title": "Test API", "version": "1.0.0"},
|
def test_schemas_defined(self, sample_spec):
|
||||||
"paths": {},
|
"""Test that schemas are defined in spec."""
|
||||||
"components": {
|
validator = OpenAPIValidator(sample_spec)
|
||||||
"schemas": {
|
schemas = validator.get_all_schemas()
|
||||||
"User": {
|
assert len(schemas) > 0
|
||||||
"type": "object",
|
assert "User" in schemas
|
||||||
"properties": {
|
assert "Product" in schemas
|
||||||
"id": {"type": "integer"},
|
assert "Order" in schemas
|
||||||
"name": {"type": "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
validator = OpenAPIValidator(spec)
|
|
||||||
schema = validator.get_schema("User")
|
|
||||||
assert schema is not None
|
|
||||||
assert schema["type"] == "object"
|
|
||||||
Reference in New Issue
Block a user