@@ -32,12 +32,7 @@ def mock_static_files(mocker: MockerFixture) -> None:
3232 return mock_static
3333
3434
35- @pytest .fixture (autouse = True )
36- def mock_templates (mocker : MockerFixture ) -> None :
37- """Mock Jinja2 template rendering to bypass actual file loading."""
38- mock_template = mocker .patch ("starlette.templating.Jinja2Templates.TemplateResponse" , autospec = True )
39- mock_template .return_value = "Mocked Template Response"
40- return mock_template
35+
4136
4237
4338@pytest .fixture (scope = "module" , autouse = True )
@@ -64,9 +59,17 @@ async def test_remote_repository_analysis(request: pytest.FixtureRequest) -> Non
6459 "token" : "" ,
6560 }
6661
67- response = client .post ("/" , data = form_data )
62+ response = client .post ("/api/ingest " , data = form_data )
6863 assert response .status_code == status .HTTP_200_OK , f"Form submission failed: { response .text } "
69- assert "Mocked Template Response" in response .text
64+
65+ # Check that response is JSON
66+ response_data = response .json ()
67+ assert "result" in response_data
68+ assert response_data ["result" ] is True
69+ assert "repo_url" in response_data
70+ assert "summary" in response_data
71+ assert "tree" in response_data
72+ assert "content" in response_data
7073
7174
7275@pytest .mark .asyncio
@@ -81,9 +84,14 @@ async def test_invalid_repository_url(request: pytest.FixtureRequest) -> None:
8184 "token" : "" ,
8285 }
8386
84- response = client .post ("/" , data = form_data )
85- assert response .status_code == status .HTTP_200_OK , f"Request failed: { response .text } "
86- assert "Mocked Template Response" in response .text
87+ response = client .post ("/api/ingest" , data = form_data )
88+ # Should return 400 for invalid repository
89+ assert response .status_code == status .HTTP_400_BAD_REQUEST , f"Request failed: { response .text } "
90+
91+ # Check that response is JSON error
92+ response_data = response .json ()
93+ assert "error" in response_data
94+ assert "repo_url" in response_data
8795
8896
8997@pytest .mark .asyncio
@@ -98,9 +106,16 @@ async def test_large_repository(request: pytest.FixtureRequest) -> None:
98106 "token" : "" ,
99107 }
100108
101- response = client .post ("/" , data = form_data )
102- assert response .status_code == status .HTTP_200_OK , f"Request failed: { response .text } "
103- assert "Mocked Template Response" in response .text
109+ response = client .post ("/api/ingest" , data = form_data )
110+ # This might fail with 400 if repo doesn't exist, or succeed with 200
111+ assert response .status_code in [status .HTTP_200_OK , status .HTTP_400_BAD_REQUEST ], f"Request failed: { response .text } "
112+
113+ response_data = response .json ()
114+ if response .status_code == status .HTTP_200_OK :
115+ assert "result" in response_data
116+ assert response_data ["result" ] is True
117+ else :
118+ assert "error" in response_data
104119
105120
106121@pytest .mark .asyncio
@@ -116,9 +131,15 @@ def make_request() -> None:
116131 "pattern" : "" ,
117132 "token" : "" ,
118133 }
119- response = client .post ("/" , data = form_data )
120- assert response .status_code == status .HTTP_200_OK , f"Request failed: { response .text } "
121- assert "Mocked Template Response" in response .text
134+ response = client .post ("/api/ingest" , data = form_data )
135+ assert response .status_code in [status .HTTP_200_OK , status .HTTP_400_BAD_REQUEST ], f"Request failed: { response .text } "
136+
137+ response_data = response .json ()
138+ if response .status_code == status .HTTP_200_OK :
139+ assert "result" in response_data
140+ assert response_data ["result" ] is True
141+ else :
142+ assert "error" in response_data
122143
123144 with ThreadPoolExecutor (max_workers = 5 ) as executor :
124145 futures = [executor .submit (make_request ) for _ in range (5 )]
@@ -138,9 +159,15 @@ async def test_large_file_handling(request: pytest.FixtureRequest) -> None:
138159 "token" : "" ,
139160 }
140161
141- response = client .post ("/" , data = form_data )
142- assert response .status_code == status .HTTP_200_OK , f"Request failed: { response .text } "
143- assert "Mocked Template Response" in response .text
162+ response = client .post ("/api/ingest" , data = form_data )
163+ assert response .status_code in [status .HTTP_200_OK , status .HTTP_400_BAD_REQUEST ], f"Request failed: { response .text } "
164+
165+ response_data = response .json ()
166+ if response .status_code == status .HTTP_200_OK :
167+ assert "result" in response_data
168+ assert response_data ["result" ] is True
169+ else :
170+ assert "error" in response_data
144171
145172
146173@pytest .mark .asyncio
@@ -155,6 +182,16 @@ async def test_repository_with_patterns(request: pytest.FixtureRequest) -> None:
155182 "token" : "" ,
156183 }
157184
158- response = client .post ("/" , data = form_data )
159- assert response .status_code == status .HTTP_200_OK , f"Request failed: { response .text } "
160- assert "Mocked Template Response" in response .text
185+ response = client .post ("/api/ingest" , data = form_data )
186+ assert response .status_code in [status .HTTP_200_OK , status .HTTP_400_BAD_REQUEST ], f"Request failed: { response .text } "
187+
188+ response_data = response .json ()
189+ if response .status_code == status .HTTP_200_OK :
190+ assert "result" in response_data
191+ assert response_data ["result" ] is True
192+ assert "pattern_type" in response_data
193+ assert response_data ["pattern_type" ] == "include"
194+ assert "pattern" in response_data
195+ assert response_data ["pattern" ] == "*.md"
196+ else :
197+ assert "error" in response_data
0 commit comments