kgraph-mcp-agent-platform / tests /test_simple_app.py
BasalGanglia's picture
πŸ† Multi-Track Hackathon Submission
1f2d50a verified
"""Tests for simple_app.py functionality."""
import pytest
from fastapi.testclient import TestClient
from simple_app import app
@pytest.fixture
def client():
"""Create test client for simple FastAPI app."""
return TestClient(app)
class TestSimpleAppEndpoints:
"""Test simple app endpoints."""
def test_health_check_success(self, client):
"""Test health check endpoint."""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert data["version"] == "0.1.0"
def test_health_check_response_model(self, client):
"""Test health check response follows model."""
response = client.get("/health")
data = response.json()
# Verify required fields
assert "status" in data
assert "version" in data
assert isinstance(data["status"], str)
assert isinstance(data["version"], str)
def test_root_endpoint(self, client):
"""Test root endpoint."""
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert "message" in data
assert "docs" in data
assert "KGraph-MCP is running!" in data["message"]
assert data["docs"] == "/docs"
def test_cors_configuration(self, client):
"""Test CORS configuration is working."""
response = client.options("/health")
# Should not fail due to CORS
assert response.status_code in [200, 405] # 405 is acceptable for OPTIONS
def test_api_documentation_accessible(self, client):
"""Test API documentation is accessible."""
# Test OpenAPI schema
response = client.get("/openapi.json")
assert response.status_code == 200
schema = response.json()
assert "openapi" in schema
assert "info" in schema
assert schema["info"]["title"] == "KGraph-MCP"
def test_docs_endpoint(self, client):
"""Test documentation endpoint is accessible."""
response = client.get("/docs")
assert response.status_code == 200
def test_redoc_endpoint(self, client):
"""Test ReDoc endpoint is accessible."""
response = client.get("/redoc")
assert response.status_code == 200
class TestSimpleAppConfiguration:
"""Test app configuration."""
def test_app_metadata(self):
"""Test app has correct metadata."""
assert app.title == "KGraph-MCP"
assert app.description == "Knowledge Graph Multi-Agent Collaboration Platform"
assert app.version == "0.1.0"
assert app.docs_url == "/docs"
assert app.redoc_url == "/redoc"
def test_middleware_configuration(self):
"""Test CORS middleware is properly configured."""
# Check if CORS middleware is in the middleware stack
middleware_classes = [
middleware.cls.__name__ for middleware in app.user_middleware
]
assert "CORSMiddleware" in middleware_classes