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
|
||||
|
||||
|
||||
SAMPLE_SPEC_PATH = "examples/petstore.yaml"
|
||||
|
||||
|
||||
class TestMockServerIntegration:
|
||||
"""Test cases for mock server integration."""
|
||||
"""Integration tests for mock server."""
|
||||
|
||||
def test_load_spec(self):
|
||||
"""Test loading a spec."""
|
||||
spec_dict = {
|
||||
"openapi": "3.0.0",
|
||||
"info": {"title": "Test API", "version": "1.0.0"},
|
||||
"paths": {
|
||||
"/users": {
|
||||
"get": {"operationId": "getUsers", "responses": {"200": {"description": "OK"}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
generator = MockServerGenerator(spec_dict)
|
||||
assert generator.spec is not None
|
||||
@pytest.fixture
|
||||
def sample_spec(self):
|
||||
"""Load sample OpenAPI spec."""
|
||||
loader = SpecLoader(SAMPLE_SPEC_PATH)
|
||||
return loader.load()
|
||||
|
||||
def test_validate_spec(self):
|
||||
"""Test validating a spec."""
|
||||
spec = {
|
||||
"openapi": "3.0.0",
|
||||
"info": {"title": "Test", "version": "1.0.0"},
|
||||
"paths": {},
|
||||
}
|
||||
validator = OpenAPIValidator(spec)
|
||||
assert validator.is_valid() is True
|
||||
@pytest.fixture
|
||||
def config(self):
|
||||
"""Create test configuration."""
|
||||
return Config(seed=42, port=8080)
|
||||
|
||||
def test_get_paths(self):
|
||||
"""Test getting paths from spec."""
|
||||
spec = {
|
||||
"openapi": "3.0.0",
|
||||
"info": {"title": "Test", "version": "1.0.0"},
|
||||
"paths": {
|
||||
"/users": {},
|
||||
"/items": {},
|
||||
},
|
||||
}
|
||||
validator = OpenAPIValidator(spec)
|
||||
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 len(paths) == 2
|
||||
assert "/users" in paths
|
||||
assert "/products" in paths
|
||||
assert "/orders" in paths
|
||||
|
||||
def test_generate_mock_server(self):
|
||||
"""Test generating a mock server."""
|
||||
spec = {
|
||||
"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)
|
||||
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):
|
||||
def test_paths_have_operations(self, sample_spec):
|
||||
"""Test that paths have operations defined."""
|
||||
spec = {
|
||||
"openapi": "3.0.0",
|
||||
"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
|
||||
validator = OpenAPIValidator(sample_spec)
|
||||
paths = validator.get_paths()
|
||||
|
||||
def test_schemas_defined(self):
|
||||
"""Test that schemas are properly defined."""
|
||||
spec = {
|
||||
"openapi": "3.0.0",
|
||||
"info": {"title": "Test API", "version": "1.0.0"},
|
||||
"paths": {},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"User": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"type": "integer"},
|
||||
"name": {"type": "string"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
validator = OpenAPIValidator(spec)
|
||||
schema = validator.get_schema("User")
|
||||
assert schema is not None
|
||||
assert schema["type"] == "object"
|
||||
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
|
||||
Reference in New Issue
Block a user