8
8
from httpx import AsyncClient
9
9
10
10
from codegate import __version__
11
+ from codegate .pipeline .factory import PipelineFactory
11
12
from codegate .pipeline .secrets .manager import SecretsManager
12
13
from codegate .providers .registry import ProviderRegistry
13
14
from codegate .server import init_app
@@ -26,23 +27,35 @@ def mock_provider_registry():
26
27
27
28
28
29
@pytest .fixture
29
- def test_client () -> TestClient :
30
+ def mock_pipeline_factory ():
31
+ """Create a mock pipeline factory."""
32
+ mock_factory = MagicMock (spec = PipelineFactory )
33
+ # Mock the methods that are called on the pipeline factory
34
+ mock_factory .create_input_pipeline .return_value = MagicMock ()
35
+ mock_factory .create_fim_pipeline .return_value = MagicMock ()
36
+ mock_factory .create_output_pipeline .return_value = MagicMock ()
37
+ mock_factory .create_fim_output_pipeline .return_value = MagicMock ()
38
+ return mock_factory
39
+
40
+
41
+ @pytest .fixture
42
+ def test_client (mock_pipeline_factory ) -> TestClient :
30
43
"""Create a test client for the FastAPI application."""
31
- app = init_app ()
44
+ app = init_app (mock_pipeline_factory )
32
45
return TestClient (app )
33
46
34
47
35
- def test_app_initialization () -> None :
48
+ def test_app_initialization (mock_pipeline_factory ) -> None :
36
49
"""Test that the FastAPI application initializes correctly."""
37
- app = init_app ()
50
+ app = init_app (mock_pipeline_factory )
38
51
assert app is not None
39
52
assert app .title == "CodeGate"
40
53
assert app .version == __version__
41
54
42
55
43
- def test_cors_middleware () -> None :
56
+ def test_cors_middleware (mock_pipeline_factory ) -> None :
44
57
"""Test that CORS middleware is properly configured."""
45
- app = init_app ()
58
+ app = init_app (mock_pipeline_factory )
46
59
cors_middleware = None
47
60
for middleware in app .user_middleware :
48
61
if isinstance (middleware .cls , type ) and issubclass (middleware .cls , CORSMiddleware ):
@@ -62,14 +75,11 @@ def test_health_check(test_client: TestClient) -> None:
62
75
assert response .json () == {"status" : "healthy" }
63
76
64
77
78
+ @patch ("codegate.pipeline.secrets.manager.SecretsManager" )
65
79
@patch ("codegate.server.ProviderRegistry" )
66
- @patch ("codegate.server.SecretsManager" )
67
- def test_provider_registration (mock_secrets_mgr , mock_registry ) -> None :
80
+ def test_provider_registration (mock_registry , mock_secrets_mgr , mock_pipeline_factory ) -> None :
68
81
"""Test that all providers are registered correctly."""
69
- init_app ()
70
-
71
- # Verify SecretsManager was initialized
72
- mock_secrets_mgr .assert_called_once ()
82
+ init_app (mock_pipeline_factory )
73
83
74
84
# Verify ProviderRegistry was initialized with the app
75
85
mock_registry .assert_called_once ()
@@ -90,15 +100,15 @@ def test_provider_registration(mock_secrets_mgr, mock_registry) -> None:
90
100
91
101
92
102
@patch ("codegate.server.CodegateSignatures" )
93
- def test_signatures_initialization (mock_signatures ) -> None :
103
+ def test_signatures_initialization (mock_signatures , mock_pipeline_factory ) -> None :
94
104
"""Test that signatures are initialized correctly."""
95
- init_app ()
105
+ init_app (mock_pipeline_factory )
96
106
mock_signatures .initialize .assert_called_once_with ("signatures.yaml" )
97
107
98
108
99
- def test_pipeline_initialization () -> None :
109
+ def test_pipeline_initialization (mock_pipeline_factory ) -> None :
100
110
"""Test that pipelines are initialized correctly."""
101
- app = init_app ()
111
+ app = init_app (mock_pipeline_factory )
102
112
103
113
# Access the provider registry to check pipeline configuration
104
114
registry = next ((route for route in app .routes if hasattr (route , "registry" )), None )
@@ -111,29 +121,29 @@ def test_pipeline_initialization() -> None:
111
121
assert hasattr (provider , "output_pipeline_processor" )
112
122
113
123
114
- def test_dashboard_routes () -> None :
124
+ def test_dashboard_routes (mock_pipeline_factory ) -> None :
115
125
"""Test that dashboard routes are included."""
116
- app = init_app ()
126
+ app = init_app (mock_pipeline_factory )
117
127
routes = [route .path for route in app .routes ]
118
128
119
129
# Verify dashboard endpoints are included
120
130
dashboard_routes = [route for route in routes if route .startswith ("/dashboard" )]
121
131
assert len (dashboard_routes ) > 0
122
132
123
133
124
- def test_system_routes () -> None :
134
+ def test_system_routes (mock_pipeline_factory ) -> None :
125
135
"""Test that system routes are included."""
126
- app = init_app ()
136
+ app = init_app (mock_pipeline_factory )
127
137
routes = [route .path for route in app .routes ]
128
138
129
139
# Verify system endpoints are included
130
140
assert "/health" in routes
131
141
132
142
133
143
@pytest .mark .asyncio
134
- async def test_async_health_check () -> None :
144
+ async def test_async_health_check (mock_pipeline_factory ) -> None :
135
145
"""Test the health check endpoint with async client."""
136
- app = init_app ()
146
+ app = init_app (mock_pipeline_factory )
137
147
async with AsyncClient (app = app , base_url = "http://test" ) as ac :
138
148
response = await ac .get ("/health" )
139
149
assert response .status_code == 200
0 commit comments