File size: 3,073 Bytes
1f2d50a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""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